Cufon.replace('h1');
Cufon.replace('h2');
Cufon.replace('h3');
Cufon.replace('h4'); 

$(document).ready(function(){
	try {
		$(document).pngFix();
	}
	catch (err) { }
});

//adjust height of the 3 steps containers so they all match at the bottom
$(window).load(
    function() {
        if ($('.SLInfoBox').length != 0) {
			StepHeighAdjust(".SLInfoBox", ".SLInfoBoxChat");
		}
    }
);

function StepHeighAdjust(elementClass, elementClass2) {
	var highest = 0;
	var boxheight;
	$(elementClass).each(function(index) {
		boxheight = $(this).height();
		if ( boxheight > highest)
		{
			highest = boxheight;
		}
	});
	
	$(elementClass2).each(function(index) {
		boxheight = $(this).height();
		if ( boxheight > highest)
		{
			highest = boxheight;
		}
	});
	
	//have tallest box's height, now change them all to match
	$(elementClass).each(function(index) {
		$(this).height(highest);
	});
	
	$(elementClass2).each(function(index) {
		$(this).height(highest);
	});
}

// Adjust the height of news and home containers
function heightadjust() {
	var homeheight = $('#homeCtn').height();
	var leftheight = $('#leftCtn').height();
	var newsheight = $('#inTheNewsCtn').height();
	if (homeheight > leftheight) { 
		$('#inTheNewsCtn').height( newsheight + ( homeheight - leftheight )); 
	} else {
		$('#homeCtn').height( leftheight ); 
	}
}    
$(document).ready(function(){ 
	heightadjust();        
});
//Run adjustment again on window.onload because the DOM is ready in chrome before images are loaded 
//causing the container height adjustment to happen too early.
window.onload = heightadjust;

/*  slideshow rotator for home page
using jquery cycle plugin:
http://jquery.malsup.com/cycle/
*/
$(document).ready(function() {
	if($("#slideShowContainer").length) {
		var fadeSpeed = 2000;  // milliseconds between slide transitions (0 to disable auto advance)

		if($('#slideShowContainer').length && jQuery.browser.msie) {
			//IE doesn't play nice with cufon and jquery cycle
			$('#slideShowContainer').cycle({
			fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
			cleartype: true,  // true if clearType corrections should be applied (for IE)
			cleartypeNoBg:  true,
			speed: 0,
			timeout: fadeSpeed  // milliseconds between slide transitions (0 to disable auto advance)
			});
		}
		else if ($('#slideShowContainer').length) {
			$('#slideShowContainer').cycle({
			fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
			cleartype: true,  // true if clearType corrections should be applied (for IE)
			cleartypeNoBg:  true,
			timeout:  fadeSpeed  // milliseconds between slide transitions (0 to disable auto advance)
			});
		}
	}
});


//this is for the iframe booking flow, deal with query strings, etc
var iFrameLoaded = false;
function loadFrame(element, source) {
	if (!iFrameLoaded) {
		//deal with query strings too, should be something like:  ?Action=book_online&Locator_Franchisee_ID=324&Zip_Code=80203&Sub_Refered_By_Code=						
		//with parseQueryString this is real easy		
		var queryData = parseQueryString();
		
		var Locator_Franchisee_ID = "";
		try {
			if (queryData['Locator_Franchisee_ID'][0] != '') {
				Locator_Franchisee_ID = queryData['Locator_Franchisee_ID'][0];
			}
		}
		catch(err) { }
		
		var Zip_Code = "";
		try {
			if (queryData['Zip_Code'][0] != '') {
				Zip_Code = queryData['Zip_Code'][0];
			}		
		}
		catch(err) { }
		
		var Sub_Refered_By_Code = "";
		try {
			if (queryData['Sub_Refered_By_Code'][0] != '') {
				Sub_Refered_By_Code = queryData['Sub_Refered_By_Code'][0];
			}
		}
		catch(err) { }
		
		if (Zip_Code != "") {
			source += "?Action=book_online&Locator_Franchisee_ID=";
			if (Locator_Franchisee_ID != "")
				source += Locator_Franchisee_ID;
			else
				source += "324";
			
			if (Zip_Code != "")
				source += "&Zip_Code=" + Zip_Code;
			
			source += "&Sub_Refered_By_Code="+Sub_Refered_By_Code;
		}
		
		element.src = source;
		iFrameLoaded = true;
	}
}
