// JavaScript Document
$j.elementReady('frame-border', function(){
	/* game info box nav selection */

	
	if (typeof SPY == 'undefined') {
		var SPY = {}
	}
	SPY.LOCALE = getLocale().toLowerCase();

	
	
	/* Navigation */
	$j('.nav-btn').hover(function(e){
		if(!$j(this).hasClass('selected')){ $j(this).addClass('hover');}
	},function(e){
		$j(this).removeClass('hover')
	});

	/*Click events */	
	$j('#stf_spy').click(function(){
		stf_spy()
	})

	

	


	
	
	/* Video Gallery */
	$j('.watchButton img').hover(function(){
		$j(this).attr('src',$j(this).attr('src').slice(0,-5) + '1.gif')
	},function(){
		$j(this).attr('src',$j(this).attr('src').slice(0,-5) + '0.gif')
	});
	
	/* Locale based changes */
	switch(SPY.LOCALE){
		case 'uk':
		  //game module details
			$j('.us_details').hide();
			$j('.au_details').hide();
			$j('.uk_details').show();
			break;
		case 'au':
		  //game module details
			$j('.us_details').hide();
			$j('.uk_details').hide();
			$j('.au_details').show();
			break;
		default:
		 //put non-uk/au stuff here if necessary, however the default styles should be set to show via the CSS	
		   //game module details
			$j('.us_details').show();
			$j('.uk_details').hide();
			$j('.au_details').hide();	
	}

	/* nav for object article pages */
	$j('.allArticles').find('div').hide();
	$j('.all-header').find('div').show();
	$j('.all-header').show();
	
})


$j(document).ready(function(e){

/* Top Stories  */
	var ts_clicked = false;
	$j.getScript('jquery.cycle.pack.js', function(){	
		$j('#topstories-image-container').cycle({
			timeout: 5000,
			speed:800,
			fastOnEvent:true,
			pager:'#ts-nav',
			pagerClick: function(idx, slide){
			  if(!ts_clicked){
				this.timeout = 0;
				ts_clicked = true;
			  }
			},
			pagerAnchorBuilder: function(idx,slide){
				var i = parseInt(idx + 1);
				return '<a>'+ i +'</a>';
			}
		});		  
	    fixMyPNG()  // fix PNG's after the pager has been drawn
	})
	$j('.allArticles').find('div').hide();
	$j('.all-header').find('div').show();
	$j('.all-header').show();
	
		/* -- Generic Tab Function --
	   when an item with the class tab is clicked
	   it gets the id from the clicked tab and the tab container
	   adds the tab-hide class to all tab layers
	   removes the selected class from all tabs within the container
	   removes the tab-hide class and adds the tab-show class to the tab layer that was clicked
	   and adds the selected class to the clicked tab
	*/
	$j('div.tab').click(function(e){
		tab_id = $j(this).attr('id');
		tab_layer = tab_id + '-layer';
		tab_parent = $j(this).parent().attr("id");
		$j("#" + tab_parent).find("div").each(function(i) {
			$j("#" + this.id + "-layer").removeClass("tab-show");
			$j("#" + this.id).removeClass("selected");
    	});
		$j("#" + tab_layer).addClass("tab-show");
		$j(this).addClass('selected');
	});
	
	$j('.article-nav-btn').click(function(e) {
	if(!$j(this).hasClass('disabled')){ 
		tab_id = $j(this).attr('id');
		tab_parent = $j(this).parent().attr("id");
		$j(".article-nav-bar").find("div").removeClass('selected');
			var divider=$j(this).next();
			$j(".article-nav-divider").removeClass('div-selected');
			$j('.allArticles').find('span').hide();
			$j('.all-header').hide();
		$j("." + tab_id).show();
		$j(".row-date").show();
		$j("." + tab_id).find('div').show();
		$j("#" + tab_id).addClass("selected");
		var divider=$j(this).next();
		divider.addClass('div-selected');
		if(tab_id == 'allArticles'){$j(".allArticles").find("span").show();
		$j('.allArticles').find('div').hide();
		$j('.all-header').find('div').show();
		$j('.all-header').show();
		}
	}
	})
	;
	
	
})

