// Change Contact Form
var currentStep = 1;

function getQueryStrings() {
    var argList = new Object();
    if(window.location != null && window.location.search.length > 1) {
        var urlParms = window.location.search.substring(1);
        var argPairs = urlParms.split('&');
        for(var i = 0; i < argPairs.length; i++) {
            var pos = argPairs[i].indexOf('=')
            if(pos == -1)
                continue;
            else {
                var argName = argPairs[i].substring(0, pos);
                var argVal = argPairs[i].substring(pos + 1);

                if(argVal.indexOf('+') != -1)
                    argVal = argVal.replace(/\+/g, ' ');

                argList[argName] = unescape(argVal);
            }
        }
    }
    return argList;
}

function loadcssfile(filename){
    var fileref = document.createElement("link");
    fileref.setAttribute("rel", "stylesheet");
    fileref.setAttribute("type", "text/css");
    fileref.setAttribute("href", filename);
    
    if (typeof fileref != "undefined")
    document.getElementsByTagName("head")[0].appendChild(fileref);
}

var queryStrings = new Array();
queryStrings = getQueryStrings();

if(queryStrings["print"] == "true"){
    // add to button for print style to load (window.location.href=window.location.href+'?print=true')
    loadcssfile("css/print.css");
}

$(document).ready(function() {

    // Test if flashObject exists otherwise don't call swfobject
    var swfObjectArray = $('.flashObject');
    if(swfObjectArray[0] != undefined){
        // Set the variable values to pass into flash onload
        var flashvars = { };

        // Set the parameters of the flash object
        var params = { wmode: "transparent" };

        // Set the attributes of the flash object
        var attributes = { wmode: "transparent" };
        swfobject.embedSWF("/flash/homepage-2.swf", "flashPlaceholder", "815", "300", "8.0.0","/flash/expressInstall.swf", flashvars, params, attributes);
    }
    
    // Search By Keyword hide
    $('#header input').focus(function(){
        $(this).addClass("typing");
        if($(this).attr('value') == "Search by keyword"){
            $(this).attr('value', '');
        }
    });
    $('#header input').blur(function(){
        $(this).removeClass("typing");
        if($(this).attr('value') == ""){
            $(this).attr('value', 'Search by keyword');
        }
    });
  
	//Used to find the index of the current item
	findIndex = function(currentArray, itemToLocate){
		var itemIndex;
		for(i=0; i < currentArray.length; i++){
			if(currentArray[i] == itemToLocate[0]){
				itemIndex = i;
			}
		}
		return itemIndex;
	}
    
    var buttonList = $('.tabbedCalloutNav a');
    var tabList = $('.tabbedSection');
    
    $(buttonList).click(function(){
        // button clicked
        var currentButton = findIndex(buttonList,$(this));
        
        // Remove Active Styles/ Hide Divs
        $(tabList).addClass(" hide");
        $(buttonList).removeClass(" active");
        
        // Add back Active Styles
        $(buttonList[currentButton]).addClass(" active");
        $(tabList[currentButton]).removeClass(" hide");
        
    });
    
    var contactList = $('.selectList');
    if(contactList[0] != undefined){
        contactList.change(function(){
            currentStep = 2;
        });
    }
    
    // stagger site map layout
    if ($('ul#siteMap')){
        var liList = $('ul#siteMap').children();
        for(i=0; i < liList.length; i++){
            if(i>0 && 1-(i%2)){
                $(liList[i]).css("clear","left");
            }
        }
    }
    
    if ($.browser.msie){
        // hr fix
        var postHrElement = $('hr').next();
        $(postHrElement).css('margin-top', '-5px');
    }
});