


//LOAD AFTER ALL ITEMS LOADED
//PRELOAD IMAGES
$(window).bind('load', function() {
    var preload = new Array();
    $(".hover").each(function() {
        s = $(this).attr("src").replace(/\.(.+)$/i, "_over.$1");
        preload.push(s)
    });
    var img = document.createElement('img');
    $(img).bind('load', function() {
        if(preload[0]) {
            this.src = preload.shift();
        }
    }).trigger('load');
});




// ON LOAD ITEMS
$(document).ready(function() {
	var domain = "http://www.cavtel.com";
	var homeServices = "/services-available";
	var businessServices = "/business-services-available";
	var widget = "/apps/check-service/widget.php";
	var loadingCss = {display:"inline",position:"relative",top:"-6px",marginLeft:"5px"};


	//LOAD TABS
	if($("#servicecheck > ul").length > 0){
		$("#servicecheck > ul").tabs();
	}
	
	//CHECK SERVICE FUNCTIONS
	if($("#check-service-home").length>0 || $("#servicecheck-personal").length>0){
		$("#home-loading-icon").hide();
		
		$("#address").focus(function(){
			if($(this).val()=="Street Address"){
				$(this).val("");
			}
		});
		
		$("#city").focus(function(){
			if($(this).val()=="City"){
				$(this).val("");
			}
		});
		
		$("#zip").focus(function(){
			if($(this).val()=="Zip Code"){
				$(this).val("");
			}
		});
		
	}
	
	
	//CHECK SERVICE FUNCTIONS BUSINESS
	if($("#check-service-business").length>0){
		
		$("#phone_business").focus(function(){
			if($(this).val()=="Phone Number"){
				$(this).val(" ");
			}
		});
		$("#business-loading-icon").hide();
		
		
	}
	
	
	//HANDLE MOUSE OVER
    $(".hover").each(function() {
							  
        if ($(this).attr("src").match(/_over\.(.+)$/i)) {
            $(this).removeClass("hover");
        }
		
    });
	
	
    $(".hover").hover(function() {
        s = $(this).attr("src").replace(/\.([^.]+)$/i,"_over.$1");
        $(this).attr("src", s);
    }, function() {
        s = $(this).attr("src").replace(/_over\.(.+)$/i, ".$1");
        $(this).attr("src", s);
    });
	
	
		
});
