/* AddThis Variables at the bottom of this file */


var s1play = {};

s1play.loaders = [];

s1play.addLoader = function(func)
{
	this.loaders[this.loaders.length] = func;
};
s1play.fireLoaders = function()
{
	for(var i = 0; i < this.loaders.length; i++)
	{
		if(this.loaders[i] && typeof this.loaders[i] == 'function')
		{
		    try 
			{
				this.loaders[i](); 
		    }
			catch(err)
			{
			    alert(err);
			}
		}
	}
};

s1play.moveAds = function(name)
{
    if(document.getElementById(name) && document.getElementById(name + '-loader'))
    {   
        document.getElementById(name).appendChild(document.getElementById(name + '-loader'));
    }
};

//************************************
	//BROWSER WIDTH DETECTION - ewwww
//************************************
//when the window loads and/or is resized, check the width and show or hide the skyscraper depending how wide the browser is.
$(document).ready(function () {
	//when the window is resized run the this function
	
	if(document.body.clientWidth < 1185)
		{
			//if so then hide the skycraper
			$('.skyscraper').hide();
		}
		else
		{
			//if its not, then show the skyscraper
			$('.skyscraper').show();
		}
	
	window.onresize = showHideExplorer;
	function showHideExplorer(){
		//set a var, to make it look nicer lol
		var physicalBrowserWidth = document.body.clientWidth;
		//check to see if the browser width is less than 1185.
		if(physicalBrowserWidth < 1185)
		{
			//if so then hide the skycraper
			$('.skyscraper').hide();
		}
		else
		{
			//if its not, then show the skyscraper
			$('.skyscraper').show();
		}
	}
});


//ALL ANCHORS WITH A CLASS OF "new_window" WILL OPEN IN A NEW WINDOW. THIS IS SO THE MARKUP VALIDATES IN STRICT
s1play.addLoader(function(){
    $('a.new_window').click(function(){
        window.open(this.href);
        return false;
    });
	
	//help bubbles
	$('.bubble-box').hide();
	$('.trigger').click(function()
	{
		$(this).parent().children('.bubble-box').toggle();	
		return false;
	});
	$('.bubble-box .close').click(function()
	{
		$(this).parent().parent().children('.bubble-box').hide();	
	});
});
//GENERIC ACCORDION SCRIPT
s1play.addLoader(function()
{
	$('.accordion-content:not(:first)').hide();
	$('.accordion-content-first').show();
	$('.accordion-toggle:first').addClass('active');
	$('.accordion-toggle-first').addClass('active');
	$('.accordion-toggle').click(function()
	{
		$(this).toggleClass('active').next('.accordion-content').slideToggle("normal");
	});
});

//GENERIC TABBING SCRIPT.
s1play.addLoader(function()
{
	var tabsContainers = $('div.tabs > div');
	tabsContainers.hide().filter(':first').show();
	$('div.tabs ul.tabs-list a').click(function()
	{
		tabsContainers.hide();
		$(this.hash).show();
		
		$('div.tabs ul.tabs-list a').removeClass('active');
		$('div.tabs ul.tabs-list a').removeClass('current');
		$(this).addClass('active');
		$(this).addClass('current');
		
		return false;
	}).filter(':first').click();
});

/*--SLIDING VIEWPORT TO ANCHOR--*/
s1play.addLoader(function()
{
$("a.anchorLink").click(function () 
{	
		elementClick = $(this).attr("href")
		destination = $(elementClick).offset().top;
		$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, 1100 );
		return false;
	});
});

/*SEARCH FORM, clears the values of the location and the postcode depending on what was clicked last*/
s1play.addLoader(function()
{
	$('input#completion').click(function()
	{
		var location_value = $("input#completion");
		var postcode_value = $("input#postcode");
		location_value.attr("value","");
		if(postcode_value.attr("value") !== "postcode")
		{
			postcode_value.attr("value","");
		}
	});
	
	$('input#postcode').click(function()
	{
		var location_value = $("input#completion");
		var postcode_value = $("input#postcode");
		postcode_value.attr("value","");
		if(location_value.attr("value") !== "eg Glasgow")
		{
			location_value.attr("value","");
		}
	});
});

//FLASH VIDEO PLAYER
s1play.addLoader(function()
{
    $(".flash-video-player").addClass("hide");
	$(".flash-video-player").addClass("fvp-position");
	$(".show-flash-video-player").click(function()
	{
		$(this).parent().children(".flash-video-player").removeClass("hide");
		$('#mpu').addClass('mpu-height');
		$('#mpu-loader').hide();
		
		return false;
	});
	$(".hide-flash-video-player").click(function()
	{
		$(".flash-video-player").addClass("hide");
		$('#mpu').removeClass('mpu-height');
		$('#mpu-loader').show();
	});
	
	//Flash video stopping the video
	function getFlashMovie(movieName) {
	 var isIE = navigator.appName.indexOf("Microsoft") != -1;
	 return (isIE) ? window[movieName] : document[movieName];
	}
	function pauseMovie() {
	 getFlashMovie("s1player").jsPause();
	}
	function playMovie() {
	 getFlashMovie("s1player").jsPlay();
	}
	$('.hide-flash-video-player').click(function(){
		pauseMovie();
		return false;
	});
});

//EVENT PAGE GMAP CODE
s1play.addLoader(function()
{
	$(".venue-address-block a.show-map").click(function()
	{
		$(".gmap-container").addClass("hide");
		$(this).parent().children(".gmap-container").removeClass("hide");
		return false;
	});
	$(".gmap-container > .close").click(function()
	{
		$(this).parent().addClass("hide");
		return false;
	});
})

s1play.addLoader(function()
{
	if ($("#general-home").length > 0 || $("#outandabout-home").length > 0)
	{
		$(".allchk").attr("checked", "checked");
		$(".allchk").click(function()
		{
			if($(".singlechk").attr("checked", "checked"))
			{
				$(".singlechk").removeAttr("checked");
			}
		});
		
		$(".singlechk").click(function()
		{
			if($("#cinema").attr("checked") || $("#onstage").attr("checked") || $("#music").attr("checked") || $("#out").attr("checked") || $("#daysouteventsch").attr("checked") || $("#exhivach").attr("checked") || $("#ptvch").attr("checked") || $("#bootch").attr("checked"))
			{
				$(".allchk").removeAttr("checked");
			}
			else
			{
				$(".allchk").attr("checked", "checked");
			}
		});
		
		$("#apply a").click(function()
		{
			$('#events_checkboxes').hide();
			return false;
		});
	}
});

/*--Extra for the OUT and ABOUT search results page--*/
s1play.addLoader(function()
{
	if ( $("#outandabout").length > 0)
	{

		/*Use and regular expression to check the url. We need to know which tab was selected last*/
		var loc = document.location.href;
		var anch = loc.replace(/^.+\#(.+)$/, "$1");
		/*If the whats_on tab has been clicked then display the whats on details only*/
		if(anch == "recommendations_result")
		{
			/*Display the recommendations stuff. Also recommendations should be selected by default*/
			$('#recommend_tab').addClass('active');
			$('#refine_whatson').hide();
			$('#whatson_results').hide();
		}
		else
		{
			$('#whatson_tab').addClass('active');
			$('#refine_recommendations').hide();
			$('#recommendations_results').hide();
		}
		
		/*The whats on tab has been clicked. Show all whats on content and add a class of active to the tab*/
		$('#whatson_tab').click(function()
		{			
			/*hide whats not needed*/
			$('#refine_recommendations').hide();
			$('#recommendations_results').hide();
			$('#recommend_tab').removeClass('active');
			
			/*show whats needed*/
			$('#refine_whatson').show();
			$('#whatson_results').show();
			$('#whatson_tab').addClass('active');
			return false; //make sure the anchor in the tabs doesn't go anywhere
		});
		/*The recommendations tab has been clicked. Show all recommendations content and add a class of active to the tab*/
		$('#recommend_tab').click(function()
		{	
			/*hide whats not needed*/
			$('#refine_whatson').hide();
			$('#whatson_results').hide();
			$('#whatson_tab').removeClass('active');
			
			/*show whats needed*/
			$('#recommendations_results').show();
			$('#refine_recommendations').show();
			$('#recommend_tab').addClass('active');
			return false; //make sure the anchor in the tabs doesn't go anywhere
		});
	}
});



/* AddThis Variables for custom presentation */
var addthis_options = 'facebook, twitter, bebo, myspace, digg, delicious, google, live, linkedin, more';
var addthis_exclude = 'print, email';
var addthis_brand = "s1play.com";
var addthis_header_color = "#ffffff";
var addthis_header_background = "#0066cc";
/* END: AddThis Variables for custom presentation */
