$(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;
	});
	
	$('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;
	});
	
	$('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="" />');
		}
	});
	
	$("#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;
	});
});

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 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.png';
img_2=tpl+'star_grey.png';
	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;
}