/* --------------------------------------------
 * 
 * code for alerts warning of site exit. Currently used on the following sites:
 * retailers page
 * --------------------------------------------*/

$(window).ready(function(){
	/* - now redundant.
	 $("#aus_retailers a,#nz_retailers a").click(function(){
	 	var x=confirm("You are now leaving nintendo.com.au to an external website. Nintendo Australia is not responsible for the content or accuracy of any external site. \n\nIf this link does not work, please disable popup blocking on your web browser.");
		return x;
	 });
	 
	 $("#news_content .promos_container a").click(function(){
	 	if (this.href.indexOf("nintendo.com.au")==-1) {
			var x=confirm("You are now leaving nintendo.com.au to an external website. Nintendo Australia is not responsible for the content or accuracy of any external site. \n\nIf this link does not work, please disable popup blocking on your web browser.");
			return x;
		}
		return true;
	 });
	 */
});

/* --------------------------------------------
 * 
 * code for global alerts warning of site exit. 
 * In the end I have resorted to flagging the external link with a class rather than
 * querying the url - just too complicated I think.
 * --------------------------------------------*/

$(window).ready(function(){
	 $("a").live("click",function(){
	 	var link=this.href;
		if (link == "" || link.indexOf("javascript:")>-1 || link.indexOf("mailto:")==0) {
			return true;
		}
		//var match=link.match(/((^[^\.]*\.\w*nintendo\w*\.com\.au)|(http:\/\/nintendocomau\.staging\.corewebdna\.com))/);
		var match=link.match(/((^([^\.]*\.)*\w*nintendo\w*\.com\.au)|(http:\/\/nintendocomau\.staging\.corewebdna\.com))/);
		if (!match) {
			var x=confirm("You are now leaving nintendo.com.au to an external website. Nintendo Australia is not responsible for the content or accuracy of any external site. \n\nIf this link does not work, please disable popup blocking on your web browser.");
			if (x) {
				window.open(this.href,"leavingNintendo");
				return false;
			} else {
				return false;
			}
		}
	 });
});




/* --------------------------------------------
 * 
 * code for filtering games sites in recent updates news page
 * 
 * --------------------------------------------*/

$(window).ready(function(){
	 $("#recent-updates-games-nav a").click(function(){
	 	//set active state of UI buttons
		$(this).parent().parent().find("a").removeClass("active").end().end().end().addClass("active");
		var filter="."+this.rel;
		//hide all games + then display matching games
		$("#recent-updates-games").find(".news_container").hide().end().find(filter).show();

		return false;
	 }).eq(0).click();
	 
	 
});

/* --------------------------------------------
 * 
 * code for managing pagination in games search index
 * 
 * --------------------------------------------*/
$(document).ready(function(){
   $(".results_page_numbers a").click(function(e){
       //e.preventDefault();
	   var form=$(this).parent();
	   var start=this.href.match(/start=(\d+)/);
	   if (start.length>0 && form.length>0 && form[0].nodeName=="FORM") {
	   	form[0].start.value=start[1];
		form[0].submit();
	   }
	   
	   return false;
   });
});

/* --------------------------------------------
 * 
 * code for managing two column panels - 
 * 
 * --------------------------------------------*/
$(document).ready(function(){
   $("#topic_box_middle ul ul a").click(function(e){
       //e.preventDefault();
	   $("#content_box").find(".topic").hide();
	   $(this.hash).show();
	   $(this).parent().parent().find("li.active").removeClass("active");
	   $(this).parent().addClass("active");
	   return false;
   });
   $("#topic_list>li>a").click(function(e){
       //e.preventDefault();
	   $("#topic_box_middle li.active").removeClass("active");
	   $(this).parent().addClass("active").find("li:first").addClass("active").children("a").each(function(){
	   		$("#content_box").find(".topic").hide();
	   		$(this.hash).show();
	   });
	   
	   return false;
   }).each(function(i){
   		if (i==0) {
			$(this).click();
		}
   });
   
   $("#content_box_middle a").click(function(){
   	var key=this.hash;
   	if (key!="" && this.href.indexOf(window.location.search)>-1) {
		$("#topic_list a").each(function(){
			if (this.hash==key) {
				$(this).parent().parent().parent().children("a").click();
				$(this).click();
			}
		});
		return false;
	}
   });
});

$(document).ready(function(){
	$(".flowplayer_video").each(function(){
		var video = $(this).attr('href');
		var id = $(this).attr('id');
		$(this).click(function(){
			callplayer(id,video);
			return false;
		});		
	});	
});

function callplayer(vid_id, playurl){
	$f(
	  vid_id, 
	  "/templates/flash/flowplayer/flowplayer.commercial-3.1.5.swf",	  
	  //{key: '#@a23bf100aec4ed9c23f'} //staging
	  {key: '#@211f36234b909959f41'}   //live
	 );
}

