/* 
Highlight the current navigation item based on the page. 
*/

function setCurrent(currentID){
	if( $('#'+currentID) ){
		 $('#'+currentID).addClass('current');
	}
}


$(document).ready(function(){
	var popup = function(w,h,url){
		window.open(url, '_blank', 'resizable=yes,toolbar=no,scrollbars=yes,width='+w+'height='+h);
	}
	
   // open external links in a new window
	$('.external').bind('click',function(){
		window.open(this.href, 'external', 'resizable=yes,toolbar=yes,scrollbars=yes,width=900,height=650');
		return false;
	});

	// launch 'popup' links in a new window
	$('.popup').bind('click',function(){
		popup(750,800,this);
		return false;
	});


});

// how fast to do these transitions
var speed = 500;

/* To reveal the prizes */
function showPrizes(){
	$('#prizes').slideDown(speed);
}

/* To hide the prizes */
function hidePrizes(){
	$('#prizes').slideUp(speed);
}

/* Toggles between showing and hiding based on initial state of prizes */
function togglePrizes(){
	$('#prizes').slideToggle(speed);
}

/* This will hide the dealer locator and then reveal the prizes */
function hideLocatorShowPrizes(){ 
	$('#dealerlocator').slideUp(speed, function(){
		$('#prizes').slideDown(speed);
	});
}

/* This hides the prizes section, then shows the dealer locator */
function hidePrizesShowLocator(zip){ 
	$('#prizes').slideUp(speed,function(){
		showDealerLocator(zip);
	});
}

/* Shows the dealer locator */
function showDealerLocator(zip){
	$('#dealerlocator').slideDown(speed,function(){ 
		var iframe = document.getElementById('dliframe');
		iframe.src = 'http://www.greatsouthernwood.com/yfdl/Search.aspx?mode=auto&zip='+zip; 
	});
}

/* Hides the dealer locator */
function hideDealerLocator(){ 
	$('#dealerlocator').slideUp(speed);
}
 
/* 
Toggles between showing and hiding based on initial state of the dealer locator. 
This will actually conduct a search whether the dealer locator is open or closed. 
Probably unnecessary. But here anyway.
*/
function toggleDealerLocator(zip){
	$('#dealerlocator').slideToggle(speed,function(){ 
		var iframe = document.getElementById('dliframe');
		iframe.src = 'http://www.greatsouthernwood.com/yfdl/Search.aspx?mode=auto&zip='+zip; 
	});
}

/* Similar to toggleDealerLocator. Takes an optional, boolean showIsTrue parameter. 
If showIsTrue === true, it will reveal the locator and conduct a search. If it is false,
it will hide the locator. It is false or null by default. */

function switchDealerLocator(zip,showIsTrue){
	if(showIsTrue){
		$('#dealerlocator').slideDown(speed,function(){ 
			var iframe = document.getElementById('dliframe');
			iframe.src = 'http://www.greatsouthernwood.com/yfdl/Search.aspx?mode=auto&zip='+zip; 
		});
	} else {
		$('#dealerlocator').slideUp(speed);	
	}
}

