///////////////////////
//	STRADA LOCATIONS.JS - REQUIRES JQUERY
//	Written by Will
//	www.engageinteractive.co.uk
//	Please do not steal.
//	Every time you steal, an angry Scotsman punches a puppy in the face! A really cute puppy!

//WAIT FOR THE PAGE TO BE READY
function strpos( haystack, needle, offset){ 
    var i = (haystack+'').indexOf( needle, offset ); 
    return i===-1 ? false : i;
}
$(document).ready(function(){

//DROP DOWN MENU
//WOOOOOO!

	$('#locations_noscript').hide();
	$('a.top').show();

	if (location.hash)
	{
		loadContent = location.hash;
		location=loadContent;
		hideContent();
	}
	
	//Toggles the drop down menu, first click and second click on the main button
	
	var dropStatus = false;
	
	$('#drop_down_holder a.top').toggle(
		function(){
			var dropStatus = true;
		},
		function closeDropDown(){
			var dropStatus = false;
		}
	);
	$('#drop_down_holder a.top').click(function(){
		if (dropStatus == false){
			$('div#drop_down').animate({height: 'show'}, 200);
			$(this).addClass('active');
			dropStatus = true;
		}else{
			$('div#drop_down').animate({height: 'hide'}, 200);
			$(this).removeClass('active');
			dropStatus = false;
		}
		return false;
	});
	
	//Clicking an item, takes the text from the item and replaces the main button with that text. Then it closes the drop down menu.	
	
	

	
	
	//Clicking anywhere outside of the drop down menu that isn't the main button resets the drop down menu.	
	$('*[class!="top"]').click(function(){
		$('div#drop_down').animate({height: 'hide'}, 200);
		$('#drop_down_holder a.top').removeClass('active');
		dropStatus = false;
	});
	
	//AJAX FUNCTION
	//Create the function
		//Load the content from the locations list page (renamed to show because of list being a funtion in php or something).
		//Then call the sifr function when the ajax completes.
		
	function hideContent(){
		$('span.locations_loading').show();
		$('div.location_holder').animate({height: 'hide'}, 600, loadLocation);
	}
	
	function loadLocation(){$('span#locations_image').animate({height:'hide'},400, function(){
			var aPosition = loadContent.indexOf("#");
			var contentUrl = loadContent.substr(aPosition + 1);
			$('div#content_wrapper div.location_holder').load('/locations/show/' + contentUrl, showContent);
		});
	}
	
	function showContent(){
		$('span.locations_loading').hide();
		$('div.location_holder').animate({height: 'show'}, 600, sifrReplace);
		var newImage = $('span.hidden_image').html();
		$('span#locations_image').html(newImage);
		if(newImage){showLocationImage();}else{
			//No image available, do nothing.
		}
	}

	function showLocationImage(){
		$('span#locations_image').oneTime(800,function(){$('span#locations_image').animate({height:'show'},400);
		});
	}
	
	function sifrReplace(){
		sIFR.replace(interstate_reg, {
			selector: 'h2',
			ratios: [8, 1.3, 9, 1.22, 10, 1.25, 11, 1.22, 17, 1.2, 28, 1.16, 30, 1.15, 40, 1.14, 60, 1.13, 61, 1.12, 65, 1.13, 66, 1.12, 67, 1.13, 103, 1.12, 104, 1.11, 112, 1.12, 114, 1.11, 119, 1.12, 123, 1.11, 1.12],
			css: '.sIFR-root { background-color: #000000; color: #FFFFFF; }',
			wmode: 'transparent'
		});
	}
});