
$(document).ready(function(){
	var flashvars = {};
	var params = {};
		params.wmode = "transparent";
	var attributes = {};
	swfobject.embedSWF("/assets/flash/cipp_home.swf", "home_flash", "901", "361", "9.0.0", false, flashvars, params, attributes);
	swfobject.embedSWF("/assets/flash/installer_map.swf", "installer_map", "615", "390", "9.0.0", false, flashvars, params, attributes);
	swfobject.embedSWF("/assets/flash/cipp_process.swf", "process_flash", "600", "300", "9.0.0", false, flashvars, params, attributes);
	swfobject.embedSWF("/animation/cippprocess.swf", "cipp_process_flash", "850", "400", "9.0.0", false, flashvars, params, attributes);

	/* **** IE HACKS **** */
	$('#cipp_pipe').ifixpng();
	$('#head_text_logo').ifixpng();
	
	$("#nav06").hover(
		function(){
			$(this).addClass("hover");
			$("#nav06 ul").css({"display":"block","top":"52px","left":"-133px"});
		},
		function(){
			$(this).removeClass("hover");
			$("#nav06 ul").css("display","none");
		}	
	);
});


$(function(){
    $('a.new-window').click(function(){
        window.open(this.href);
        return false;
    });
});

var toCapitalCase = function(strObj){
	return(strObj.charAt(0).toUpperCase()+strObj.substr(1).toLowerCase());
}

var get_installer_by_state = function(state){
	//
	location.href = "#installers";
	//add animation
	$("#installer_listing").html('<img src="/assets/img/loading.gif" id="ajax-loading"/>')

	$.getJSON("/remote/?method=get_installers_for_state&state="+state+"&jsoncallback=?",
	    function(data){
			//clear out existing dealer area			
			$("#installer_listing").html('');
			if (data.response == "success") {			
				$("#installer_listing").css("display","none");
				
				$('#installer_listing').createAppend(
					'h2', {}, 'CIPP Installers For ' + toCapitalCase(data.items[0].service_state)
				);
	          	$.each(data.items, function(i,item){
						$('#installer_listing').createAppend(
						'div', { className: 'installer'}, [
							'div', { className: 'installerLeft'}, [
								'img', { src: '/assets/img/installers/'+item.logo }
							],							
							'div', { className: 'installerRight'}, [
							'h3', {}, item.title, 
							'p', {}, item.address, 
							'p', {}, item.city + ', ' + item.state + " " + item.zip, 
							'p', {}, 'Contact: <a href="mailto:' + item.email + '?subject=CIPP Install" >' + item.contact + "</a>", 
							'p', {}, item.phone,
							'p', {}, [
								'a', {href:item.website,target:"_blank"}, 'Visit Website' 
								]
							]
						])
				});	
			}else{
				$("#installer_listing").html('');
				$('#installer_listing').createAppend('h3', {}, 'No Installers For This Area, Sorry!')
			}
			$("#installer_listing").slideDown();
			
			
		}
	);
}
