
/**********************************

//Simple rollovers  thanks to :http://www.shopdev.co.uk/blog/jquery-rollovers-using-this/
//added filter to accomodate downstate of images

***********************************/

jQuery.extend({
	add_image_type: function(img,type){
		var $new_src = img.attr("src").split(".gif").join("_"+type+".gif");
		img.attr("src", $new_src);
	},
	clear_image_type: function(img,type){
		//var $imgtype = $('img[src*="gif"]');
		//alert($imgtype);
		var $new_src = img.attr("src").split("_"+type+".gif").join(".gif");
		img.attr("src", $new_src);
	},
	add_all_rollovers: function() { 
		$(".navbar img[class!='downstate'], .playbutton[class!='downstate'], .searchbutton").hover(function() {
			jQuery.add_image_type($(this),"hover");
		}, function() {
			jQuery.clear_image_type($(this),"hover");
		});
	},
	
	add_tab_rollovers: function() { 
		$(".tabnav img[class!='downstate']").hover(function() {
			jQuery.add_image_type($(this),"hover");
		}, function() {
			jQuery.clear_image_type($(this),"hover");
		});
	},
	remove_tab_rollovers: function() {
		$(" .tabnav img").unbind();
	},
	
	reset_tabnav_images: function(exclude_id) { 
		$(".tabnav li a img[id!="+exclude_id+"]").each(function(){
			jQuery.clear_image_type($(this),"down");
			$(this).attr({height:"20"});
			$(this).removeClass("downstate");
		});
	},
	set_downstate_on_tabnav_image: function(img) {
		jQuery.add_image_type(img,"down");
		img.addClass("downstate");
		img.attr({height:"27"});
	},
	highlight_bg: function() {
		$("ul.gallery li").hover(function(){						
			$(this).addClass("hovercolor");
		}, function(){
			$(this).removeClass("hovercolor");
		});
		
	},
	addframeswitchlinks: function(){
		
		var theFrame = $("#theiframe", parent.document.body);
		
		$("a#switchframenarrowstep").click(function(event){
			event.preventDefault();
			theFrame.attr("src","http://player27.narrowstep.tv/nsp.aspx?player=PlayerPhase2&nsess=1&DO-NOT-USE-THIS-TESTING-URL");
		});
		$("a#switchframelocal").click(function(event){
			event.preventDefault();											   
			theFrame.attr("src","iframe.html");
		});
		
	},
	do_tab_layers: function(){
		//return;

		// Hide all tab layers
		$(".div_tablayer_wrapper").hide();
	
		$(".tabnav li a").hover(
				function() {
					var li = $($(this).parent().get(0));
					if(!li.hasClass('active')){
						li.addClass('hover');
					}
				},
				function() {
					$($(this).parent().get(0)).removeClass('hover');
				}
		);
		
		
		$(".tabnav li a").click(function(event) {
	
			$(".tabnav li").removeClass('active');
			$($(this).parent().get(0)).removeClass('hover');
			$($(this).parent().get(0)).addClass('active');
			
			event.preventDefault();
			$img = $(this).find("img:first");
			$tablayer = $(this).attr("href");
			if($img.length > 0){
				jQuery.clear_image_type($img,"hover");
				jQuery.reset_tabnav_images($img.attr("id"));
		
				if ( $img.attr("class") != "downstate" )
					jQuery.set_downstate_on_tabnav_image($img);
					jQuery.remove_tab_rollovers();
					jQuery.add_tab_rollovers();
			}
			
			//first hide all layers
			$(".div_tablayer_wrapper").hide();
	
			//loop and compare to find which one to show
			$(".div_tablayer_wrapper").each(function(){
	
				$currentlayer = $(this).attr('id');
				$compare="#"+$currentlayer;
				if($tablayer==$compare){
					$(this).show();
				}
	
			});
	
		});
		$($(".tabnav li").get(0)).addClass('active');
	}
});