/*
*	modalFunctions.js
*
*	A set of functions used to control the html modal window commonly used 
*	by flash panels for resizing etc.
*	
*
*/


var modalHeight = "700px";
var modalWidth = "900px";
var modalAlpha = 0;

function resizeFlash(id, width, height) {
	
	document.getElementById(id).width = width;
	document.getElementById(id).height = height;
	
}
function heroResize (height) {	
	height = height;
	$(".overviewBanner").css('height', height);
}
function vehicleGalleryFunction(width, height, alpha) {
	
	setModalParams(width, height, alpha);
	
	if (width == 790) {
		hideModal();
	}
	
	if (width > 790) {
		hideShoppingTools(0);
	}
	
}

function setModalParams(width, height, alpha)
{
	setModalWidth(width);
	setModalHeight(height);
	setModalAlpha(alpha);
	
	$("#flash").css('height',height+"px");
	$("#flash").css('width',width+"px");
	
	$("#primary").css('top',(height-320)+"px");
}

function setModalAlpha(alpha)
{
	modalAlpha = alpha;
	$(".modal").css('opacity',alpha);
}

function setModalWidth(width)
{
	modalWidth = width;
}	

function setModalHeight(height)
{
	modalHeight = height;
}	

function hideShoppingTools(time)
{
	
	$(".tools").animate({ opacity: 'hide' }, time);
	$(".shoppingToolsContainer").animate({ opacity: 'hide' }, time);
}

function triggerModal()
{
	
	$(".modal").show();
	$(".modal").css('opacity',0);
	$(".mainContainer").css('z-index',12000);
	
	$(".modal").click(function () {
		var divtag = document.getElementById('panel');
		divtag.closeExpandedPanel();
	});	
	
}

function hideModal()
{
	
	$(".modal").hide(); 
	$(".shoppingToolsContainer").animate({ opacity: 'show' }, "slow");
	$(".tools").animate({ opacity: 'show' }, "slow");
	$(".mainContainer").css('z-index',1);
}

hld_documentReady("removeImageLinkStyling");
function removeImageLinkStyling(){
	try {
		$(".fullTextContent a > img").each(
			 function( intIndex ){
				$(this).parent().css("text-decoration","none");
			 }
		 );
	} catch (err) {
		return false;
	}
}
/*
GLOBAL JAVASCRIPT FUNCTIONS 
*/
//used to make IE7 behave the same as other browsers
hld_documentReady("formStyling");
function formStyling(){
	try {
		$(".phoneNumber span.errorMessageSubscribe").each(
			function(intIndex){
			$(this).parent().css("height","80px");
		});
	} catch (err) {
		return false;
	}
}

//remove border on last item in .contentModule
hld_documentReady("removeborder");
function removeborder(){
	try {
		$(".contentModule:last-child").css("border-bottom","0px");
	} catch (err) {
		return false;
	}
		
}

//remove border on last item in .contentModule
hld_documentReady("shoppingToolsFix");
function shoppingToolsFix(){
	try {
		$(".dealerTemplate .shoppingToolsContainer").css("position","relative");
	} catch (err) {
		return false;
	}
		
}

//REMOVE MARGIN FROM GRANDmASTERS lIST
hld_documentReady("removeMargin");
function removeMargin(){
	try {
		// Make the last div in each row have no right margin.
		$(".grandMastersWinners ul > li:nth-child(3n)").css("margin-right","0px");
	} catch (err) {
		return false;
	}
}

//FIX LEFT NAV TOP MENU ITEM LENGTH BY ADJUSTING LEFT PADDING
hld_documentReady("adjustPadding");
function adjustPadding(){
	
	try {
		//CHECK TO SEE IF A STRING IS MATCHED THEN APPLY SOME CSS TO IT
		$('li.sideNavTop:contains("Holden Assist Members")').each(function(){
	     if($(this).children().length < 1) 
	          $(this).addClass("menuLenghtFix") });
			
		$('li.sideNavTop:contains("Environment")').each(function(){  //used in Fleet Environment and Innovation section
	     if($(this).children().length < 1) 
	          $(this).addClass("menuLenghtFix") });

	} catch (err) {
		return false;
	}
}

//FIX INPUTS WITH A TYPE OF "IMAGE" TO HAVE NO BORDERS, BORDERS ARE ADDED TO MAKE THE :FOCUS PSEUDO BEHAVE NICELY
hld_documentReady("removeBorder");
function removeBorder(){
	try {
		$('.primaryContent input[type=image]').css("border","none");
		$('.primaryContent input[type=radio]').css("border","none");
		$('.primaryContent input[type=checkbox]').css("border","none");
	} catch (err) {
		return false;
	}
	
}
//PRIVACY POLICY UPDATES FOR DEALERS
hld_documentReady("showHidesection");
function showHidesection(){
	try {
		$(".holdenPolicy")
			.hide();
			
		$(".policyLinkA")
			.click(function(){
				$(this)
					var css = $("#HoldenPolicy").attr("class");
				
					if(css.indexOf('expanded') == -1) {
						$(".dealerPolicy").slideUp();
						$(".holdenPolicy").slideToggle();
						
						$("#HoldenPolicy").attr("class", "policy holdenPolicy expanded");
						
						//$("#gmPolicy").attr("class", "policyLinkA selected");
						//$("#dealerPolicy").attr("class", "policyLinkB");
					}
					
	            return false;
			});
			
		$(".policyLinkB ")
			.click(function(){
				$(this)
					var css = $("#HoldenPolicy").attr("class");
					
					if(css.indexOf('expanded') > -1) {
						$(".holdenPolicy").slideUp();
						$(".dealerPolicy").slideToggle();
						
						$("#HoldenPolicy").attr("class", "policy holdenPolicy");
						
						//$("#gmPolicy").attr("class", "policyLinkA");
						//$("#dealerPolicy").attr("class", "policyLinkB selected");
					}
	            return false;
			});
	} catch (err) {
		return false;
	}
}
//Enquire form height fix
hld_documentReady("equalheight");
function equalheight(){

	try {
		// Make each div as tall as the tallest div
		var maxHeight = 0;
		var listheight = $(".section2 li");
			
		listheight
			.each(function() {
				if ($(this).height() > maxHeight) { maxHeight = $(this).height(); }
			}).height(maxHeight);
	} catch (err) {
		return false;
	}
			
}

