$(document).ready(function(){

	$('div.bZodiac div.footer a').click(function(){
		$('div.bZodiac div.content').load("/xml/zodiac_switch.php?z="+$(this).attr('rel')+" div.bZodiac>div.content");
		return false;
	});

	$('a.trailer_rating').live("click", function(){

		$('#trailer_rating').load("/xml/trailer_rating.php?"+$(this).attr('rel'));
		return false;
	});

	$('a.video_rating').live("click", function(){

		$('#video_rating').load("/xml/video_rating.php?"+$(this).attr('rel'));
		return false;
	});

	if($('div.article_slideshow').length){

		shortcut.add("left", function(){
			$prev = $('div.article_slideshow_photos div.on').prev().attr('id');
			if($prev){
				$id = $prev.replace(/_c/, '');
				updateTab($id);
			}
		});

		shortcut.add("right", function(){
			$next = $('div.article_slideshow_photos div.on').next().attr('id');
			if($next){
				$id = $next.replace(/_c/, '');
				updateTab($id);
			}
		});

		$('div.article_slideshow_photos div img').click(function(){
			$next = $(this).parent().next().attr('id');
			if($next){
				$id = $next.replace(/_c/, '');
				updateTab($id);
			}
			else document.location = '/slideshow.php';
		});

		$('td.table_article_slideshow div.tabswrap div.c3 a').click(function(event){
			event.stopImmediatePropagation();
			$next = $(this).parent().parent().find('div.c2 div.tabs div.active').next().attr('id');
			if($next){
				updateTab($next);
			}
			else document.location = '/slideshow.php';
			return false;
		});
	}

	if($('#slideshow_photo').length){

		shortcut.add("left", function(){
			document.location = $('div.view_photo div.nav a.prev').attr('href');
		});

		shortcut.add("right", function(){
			document.location = $('div.view_photo div.nav a.next').attr('href');
		});
	}

	$('div.tabs div').click(function(){
		updateTab($(this).attr('id'));
	});

	$('div.tabs2 div.c1 a').click(function(){
		updateTab($(this).parent().parent().find('div.c2 div.tabs div.active').prev().attr('id'));
		return false;
	});

	$('div.tabs2 div.c3 a').click(function(){
		updateTab($(this).parent().parent().find('div.c2 div.tabs div.active').next().attr('id'));
		return false;
	});

	if($('div.exclusive div.c2 a.c1').length > 0){
		setTimeout('autoupdateExclusive()', 10000);
	}

	$('div.exclusive div.c2 a.c1').click(function(){
		$current = $(this).parent().parent().find('div.c3 a.active');
		$target = $(this).parent().parent().find('div.c3 a.active').prev();
		updateExclusive($current, $target);
		return false;
	});

	$('div.exclusive div.c2 a.c2').click(function(){
		$current = $(this).parent().parent().find('div.c3 a.active');
		$target = $(this).parent().parent().find('div.c3 a.active').next();
		updateExclusive($current, $target);
		return false;
	});

	$("#show_comments_terms").live('click', function(){
		$("#comments_terms").slideToggle("slow");
		return false;
	});

	$("#show_radio_instructions a").live('click', function(){

		if($("#radio_instructions").length > 0) $("#radio_instructions").slideToggle("slow");
		else{
			$('#show_radio_instructions').before('<div id="radio_instructions" style="display: none" class="pad"></div>');
			$('#radio_instructions').load("/xml/tabs_content.php?id=radio_instructions #tabContent", function(){ $('#radio_instructions').slideDown("slow") });
		}
		return false;
	});

	$("div.text_change a.c1").live('click', function(){
		fontSize($(this).attr('rel'), 'plus');
		return false;
	});
	$("div.text_change a.c2").live('click', function(){
		fontSize($(this).attr('rel'), '');
		return false;
	});

	$("#radio button").live('click', function(){

		//if($("#radio select").val() != 0) window.open($("#radio select").val());
		if($("#radio select").val() != 0) document.location = $("#radio select").val();
		return false;
	});

	/*$("div.view_photo a.prev, div.view_photo a.next").live('click', function(){

		$('#slideshow_photo').load("/xml/tabs_content.php?id=slideshow_photo&"+$(this).attr('rel')+" #tabContent");

		return false;
	});
	*/
	$("#slideshow_search").hover(function(){ $(this).val(''); this.focus(); });

	if($("#mega_branding").length > 0){
		$(window).scroll(function () {
			$('#mega_branding').stop();
			var scroll = $(window).scrollTop();
			$('#mega_branding').animate({top: scroll});
		});
	}
	$("#reporterForm").click(function(){
		if($("#reporterForm table.more").css("display") == 'none'){
			$("#reporterForm table.more").css({"display" : 'block'});
			$("#reporterForm span.code_img").html('<img src="/lib/ibgws/ibgws_comments/validate/code.php" alt="" />');
		}
	});

	$("#reality_go").click(function(){
		if($("#realityForm table.more").css("display") == 'none'){
			$("#realityForm table.more").css({"display" : 'block'});
			$("#realityForm span.code_img").html('<img src="/lib/ibgws/ibgws_comments/validate/code.php" alt="" />');
		}
	});

	$('#new_browse').click(function(){
		var $num = ($('.ufile').length);
		if($num <= 2){
			$("#link_new").before("<tr><td align='left'>Ôàéë:</td><td><input name='file[]' class='ufile' type='file' style='width: 90%' /></td></tr>");
			if($num == 2){
				$("#link_new").remove();
			}
		}
	});

	$("#video_comments_show a").click(function(){
		$("#video_comments_show").hide();
		$("#video_comments").show();
		return false;
	});

	$("#video_comments a.comment-hide").click(function(){
		$("#video_comments").hide();
		$("#video_comments_show").show();
		return false;
	});

	//jQuery('iframe.pay').iframeAutoHeight();
	

	$("#zodiac_oxana_show").click(function(){
		$.fancybox(
			$("#zodiac_oxana").html(), 
			{
	        	'autoDimensions'	: false,
				'width'         	: 600,
				'height'        	: 400,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'padding'			: 0,
				'margin'			: 0,
				'scrolling'			: 'no',
				'centerOnScroll'	: true,
				'showCloseButton'	: false
			}
		);
		return false;
	});

	$(".sms_president_info").click(function(){
		$.fancybox(
				$(".sms_president_info_box").html(), 
				{
		        	'autoDimensions'	: false,
					'width'         	: 583,
					'height'        	: 564,
					'transitionIn'		: 'none',
					'transitionOut'		: 'none',
					'padding'			: 0,
					'margin'			: 0,
					'scrolling'			: 'no',
					'centerOnScroll'	: true,
					'showCloseButton'	: false
				}
			);
			return false;
		});
	
	$(".prezident_light_box a.close").live('click', function(){
		$.fancybox.close();
		return false;
	});

});


$(function()
		{
	var if_height;
	var src = 'http://investorbg.adocean.pl/files/rjjedxfsdt/oapefqhrty/dnes_tlinks_ao.html#' + encodeURIComponent(document.location.href);

	var iframe = $('<iframe id="ttlf" " src="' + src + '" scrolling="no" frameborder="0" marginwidth="0" marginheight="0" style="float:none; clear:both; display: block; width:100%; height:0px; margin-bottom:10px;"><\/iframe>')
		.appendTo( '#tiframe' );

	$.receiveMessage(function(e)
	{
		var h = Number(e.data.replace(/.*if_height=(\d+)(?:&|$)/, '$1')) + 20;

		if ( !isNaN(h) && h > 0 && h !== if_height)
		{
			iframe.height(if_height = h);
			$('#tiframe').css('height', (h) + "px");
			$('#ttlf').css('height', (h) + "px");
		}
	}, 'http://investorbg.adocean.pl');
});




function updateTab($target){

	if($target == undefined)
		return;

	$tab_id = $('div#'+$target).parent().attr('id');
	$('div#'+$tab_id+' div').removeClass('active');

	$tab_params = $('div#'+$target).attr('title');

	if($('div#'+$target).is('.static')){

		if($('div#'+$target).parent().parent().parent().parent().is('.table_article_slideshow'))
			updateArticleSlideshow($target);
	}
	else
		$('div#'+$tab_id+'_c').load("/xml/tabs_content.php?id="+$target+$tab_params+" #tabContent");

	$('div#'+$target).addClass('active');
}

function updateArticleSlideshow($target){

	$('div#'+$target+'_c').parent().find("div").removeClass("on");
	$('div#'+$target+'_c').addClass("on");
	$('div#'+$target+'_c2').parent().find("div").removeClass("on");
	$('div#'+$target+'_c2').addClass("on");
}

function autoupdateExclusive()
{
	$current = $('div.exclusive div.c3 a.active');
	$target = $('div.exclusive').find('div.c3 a.active').next();

	if($target.length == 0)
		$target = $('div.exclusive div.c3 a').eq(0);

	updateExclusive($current, $target);

	setTimeout('autoupdateExclusive()', 10000);
}

function updateExclusive($current, $target){

	if($target.attr('href') == undefined || $current.attr('href') == undefined) return;

	$current.removeClass('active');
	$target.addClass('active');
}


function fontSize(target, action) {
	obj = document.getElementById(target);
	current = obj.className;
	size = parseInt(current.charAt(1));

	if (action == 'plus'){
 		size = size + 1;
		if (size > 7) return;
	}
 	else{
  		size = size - 1;
 		if (size <= 0) return;
 	}

  	obj.className = "s" + size;
}

var win= null;
function PopUpWindow(mypage,myname,w,h,scroll,resizeable){
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  var settings  ='height='+h+',';
      settings +='width='+w+',';
      settings +='top='+wint+',';
      settings +='left='+winl+',';
      settings +='scrollbars='+scroll+',';
      settings +='resizable='+resizeable+',';
  win=window.open(mypage,myname,settings);
  if (win.opener == null) {  // for Nav 2.0x
      win.opener = self  // this creates and sets a new property
   }
  if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}

function switch_images(img_number, tpl) {
img_1=tpl+'star_yellow.gif';
img_2=tpl+'star_grey.gif';
	for (i=1; i<=img_number; i++) document.getElementById('image'+i).src=img_1;
	for (i=img_number+1; i<=5; i++) document.getElementById('image'+i).src=img_2;
}

function branding_links(elems)
{
	var de = document.documentElement;
	var w = window.innerWidth || self.innerWidth || (de && de.clientWidth) || document.body.clientWidth;

	if(w < 996)
	{
		try
		{
			for (var i=0; i<elems.length; i++)
			{
				document.getElementById(elems[i]).style.width = '0px';
			}
		}
		catch(err){}
	}
	else if(w >= 996)
	{
		try
		{
			var offset = 0;

			if (navigator.appName != 'Microsoft Internet Explorer')
			{
				offset = 10;
			}

			for (var i=0; i<elems.length; i++)
			{
				document.getElementById(elems[i]).style.width = ((w-996)/2-offset) + 'px';
			}
		}
		catch(err){}
	}
}

/* BEGIN CUSTOM ADSENSE */
function google_ad_request_done(google_ads)
{
	var s = '';
	var i;

	if (google_ads.length == 0)
	{
		return;
	}

	s += '<div class="gas_wrap'+palette+'"><div class="content"><div class="google_ads"><a href="'+google_info.feedback_url+'" target="_blank">Ðåêëàìè îò Google</a></div>';

	for(i = 0; i < google_ads.length; ++i)
	{
		s+= '<div class="item">';
		s+= '<p><a href="'+google_ads[i].url+'" class="title" onmouseout="window.status=\'\'" onmouseover="window.status=\'go to ' +google_ads[i].visible_url + '\';return true">'+google_ads[i].line1+'</a></p>';
		s+= '<p>'+google_ads[i].line2+'';
		s+= ''+google_ads[i].line3+'</p>';
		s+= '<a href="'+google_ads[i].url+'" class="short_link" onmouseout="window.status=\'\'" onmouseover="window.status=\'go to ' +google_ads[i].visible_url + '\';return true">'+google_ads[i].visible_url+'</a>';
		s+= '</div>';
	}

	s += '</div>';
	s += '</div>';

	document.write(s);
	return;
}
/* END CUSTOM ADSENSE */


