$(document).ready(function(){

	var strwinloc = unescape(window.location.href);
	strwinloc = strwinloc.toLowerCase();
	var startindex = strwinloc.indexOf('#') + 1;
	var strendindex = strwinloc.length;
	
	
	$('a.menutab').click(function(){
		var menuid=$(this).attr("id");
		var menutabid = $('#' + menuid);
		var aid=$('#' + menuid+'li');
		$('#tabs_container > .tabs > li.active').removeClass('active');
		var path="#tabs_container > .tabs >li."+menuid;
		$(path).addClass('active');
		$('#tabs_container > .tab_contents_container > div.tab_contents_active').removeClass('tab_contents_active');
		var content = $(menutabid).attr("rel");	
		$(content).addClass('tab_contents_active');
		$(aid).addClass('active');
		});
	// Clear input on focus and add value on blur
    $('input[type=text]').focus(function () {
        var inputText = $(this).val();
        $(this).val('');

        $(this).blur(function () {
            if ($(this).val() == '') {
                $(this).val(inputText);
            }
            else {
                // don't do clear the input
            }
        })
    });

    $('.locationInput').focus(function () {
        var locationText = $(this).val();
        $(this).val('');

        $(this).blur(function () {
            if ($(this).val() == '') {
                $(this).val(locationText);
            }
            else {
                // don't do clear the input
            }
        })
	});
	
	
	
 	/* ********** TABS ********** */
 	$('.tab').click(function () {
	  	// Remove the 'active' class from the active tab.
	  	$('#tabs_container > .tabs > li.active').removeClass('active'); 	

	  	// Add the 'active' class to the clicked tab.
	  	$(this).parent().addClass('active');
	
	  	// Remove the 'tab_contents_active' class from the visible tab contents.
	  	$('#tabs_container > .tab_contents_container > div.tab_contents_active').removeClass('tab_contents_active');
	
	  	// Add the 'tab_contents_active' class to the associated tab contents.
	  	$(this.rel).addClass('tab_contents_active');

 	});

	/* ********** SECONDARY TAB 1 ********** */
 	$('.tab1').click(function () {
	  	// Remove the 'active' class from the active tab.
	  	$('#tabs_container1 > .tabs1 > li.active1').removeClass('active1');	  
	  	// Add the 'active' class to the clicked tab.
	  	$(this).parent().addClass('active1');	
	  	// Remove the 'tab_contents_active' class from the visible tab contents.
	  	$('#tabs_container1 > .tab_contents_container1 > div.tab_contents_active1').removeClass('tab_contents_active1');	
	  	// Add the 'tab_contents_active' class to the associated tab contents.
	  	$(this.rel).addClass('tab_contents_active1');
 	});
	/* ********** SECONDARY TAB 2 ********** */
 	$('.tab2').click(function () {
	  	// Remove the 'active' class from the active tab.
	  	$('#tabs_container2 > .tabs2 > li.active2').removeClass('active2');	  
	  	// Add the 'active' class to the clicked tab.
	  	$(this).parent().addClass('active2');	
	  	// Remove the 'tab_contents_active' class from the visible tab contents.
	  	$('#tabs_container2 > .tab_contents_container2 > div.tab_contents_active2').removeClass('tab_contents_active2');	
	  	// Add the 'tab_contents_active' class to the associated tab contents.
	  	$(this.rel).addClass('tab_contents_active2');
 	});
	/* ********** SECONDARY TAB 3 ********** */
 	$('.tab3').click(function () {
 		
	  	// Remove the 'active' class from the active tab.
	  	$('#tabs_container3 > .tabs3 > li.active3').removeClass('active3');	  
	  	// Add the 'active' class to the clicked tab.
	  	$(this).parent().addClass('active3');	
	  	// Remove the 'tab_contents_active' class from the visible tab contents.
	  	$('#tabs_container3 > .tab_contents_container3 > div.tab_contents_active3').removeClass('tab_contents_active3');	
	  	// Add the 'tab_contents_active' class to the associated tab contents.
	  	$(this.rel).addClass('tab_contents_active3');
	  

 	});
	/* ********** SECONDARY TAB 4 ********** */
    $('.tab4').click(function () {
        // Remove the 'active' class from the active tab.
        $('#tabs_container4 > .tabs4 > li.active4').removeClass('active4');
        // Add the 'active' class to the clicked tab.
        $(this).parent().addClass('active4');
        // Remove the 'tab_contents_active' class from the visible tab contents.
        $('#tabs_container4 > .tab_contents_container4 > div.tab_contents_active4').removeClass('tab_contents_active4');
        // Add the 'tab_contents_active' class to the associated tab contents.
        $(this.rel).addClass('tab_contents_active4');
    });

	$('a.link').click(function(){
		var tabid=$(this).attr("href");		
		$('#tabs_container > .tabs > li.active').removeClass('active');
		$(tabid).parent().addClass('active');
		//alert($('#'+tabid).parent().id);
	});
	


 	/* *********** COMPARE PAGE COLUMN REMOVER *********** */
 	$('.btnRemove').click(function() {
		// hide the product when remove buttton is clicked
		$(this).parent().parent().parent().fadeOut('fast').hide('productColumn');		
		return false;
 	});
 	/* *************************************************** */
    /* 				SELECT BOX IMAGE SWAPPING 			   */
    /* *************************************************** */
    var systemTypeImages = new Array("icon_type_aconly", "icon_type_allinone", "icon_type_furnaceonly", "icon_type_indooroutdoor", "Icon_type_packagedac");
    var systemFuelImages = new Array("icon_fuel_allelectric", "Icon_fuel_gaselectric", "icon_fuel_oilelectric");


    // System Type
    $("select.system_type_select").change(function () {
        var str = "";
        $("select.system_type_select option:selected").each(function () {
            str += $(this).text() + " ";
            $("#systemTypeImage").attr("src", "/PublishingImages/PageImages/" + systemTypeImages[$(this).index()] + ".jpg");
        });
        $("p.system_type_txt").text(str);
    })
    .change();

    // Fuel Type
    $("select.system_fuel_select").change(function () {
        var str = "";
        $("select.system_fuel_select option:selected").each(function () {
            str += $(this).text() + " ";
            $("#systemFuelImage").attr("src", "/PublishingImages/PageImages/" + systemFuelImages[$(this).index()] + ".jpg");
        });
        $("p.fuel_type_txt").text(str);
    })
	.change();
	
	if(strwinloc.indexOf('products.aspx#') > - 1)
	{
		var mainid = strwinloc.substring(startindex , strendindex);
		
		if(mainid.length > 0)
		{
			var tabid = '#' + mainid;
			$('#tabs_container > .tabs > li.active').removeClass('active');	
			
			if(mainid  == "how")
			{			
     			$('#tabs_container > .tabs > li.tabsli').addClass('active');	
			}		
			if(mainid  == "plan")
			{			
     			$('#tabs_container > .tabs > li.plantabsli').addClass('active');	
			}
		
			$(tabid).addClass('linkactive').show();			
			
			$('#tabs_container > .tab_contents_container > div.tab_contents_active').removeClass('tab_contents_active');
			var a1 = $(tabid).attr("rel");	
			
			$(a1).addClass('tab_contents_active');
			$(tabid).addClass('linkactive').show();		
		}
	}
	if(strwinloc.indexOf('why.aspx#') > - 1)
	{
		var mainid = strwinloc.substring(startindex , strendindex);	
		if(mainid.length > 0)
		{
			var tabid = '#' + mainid;
			$('#tabs_container > .tabs > li.active').removeClass('active');			
			$('#tabs_container > .tab_contents_container > div.tab_contents_active').removeClass('tab_contents_active');
			var a1 = $(tabid).attr("rel");	
			$(a1).addClass('tab_contents_active');
			$(tabid).addClass('linkactive').show();	
			$(tabid+'li').addClass('active').show();	
		}
	}
});
