// Javascript Document
$ = jQuery.noConflict();
$ = jQuery;

$(document).ready(function(){
	$("#menu-main-navigation > li").hover(
		function(){ $("ul:first", this).css({display: 'block'}); },
		function(){ $("ul:first", this).css({display: 'none'}); }
	);
	
	$("#menu-main-navigation > li ul li").hover(
		function(){ $("ul:first", this).css({display: 'block'}); }, 
		function(){ $("ul:first", this).css({display: 'none'}); } 
	);
	
	$("#menu-main-navigation > li ul li ul li").hover(
		function(){ $("ul:first", this).css({display: 'block'}); }, 
		function(){ $("ul:first", this).css({display: 'none'}); } 
	);
	
	$("#menu-main-navigation > li ul li ul li ul li").hover(
		function(){ $("ul:first", this).css({display: 'block'}); }, 
		function(){ $("ul:first", this).css({display: 'none'}); } 
	);
	
	$("#menu-main-navigation li ul").css({display: 'none'});
	
	if($('#banner').length > 0){ //If element exists
		$('#banner').cycle({
			fx : 'fade',
			speed :  900, 
    		timeout : 6000,
			pause : 0,
			random : false,
			cleartype :  1, // enable cleartype corrections
			cleartypeNoBg: true
		});
	}
	
	if($('#carousel-slider').length > 0){ //If element exists
		$('#carousel-slider').cycle({
			fx: 'scrollHorz',
			speed :  900, 
    		timeout : 10000,
			cleartype:  1, // enable cleartype corrections
			cleartypeNoBg: true,
			next : '#carousel-slider-next',
			prev : '#carousel-slider-previous'
		});
	}
	
	$(".estimate-icon").click(function(e) {
		e.preventDefault();
		$(".estimate-container").toggle();
		$("div#shade").toggle();
		$(".estimate-icon").toggleClass("menu-open");
	});

	$(".estimate-container").mouseup(function() {
		return false
	});
	$(document).mouseup(function(e) {
		if($(e.target).parent("a.estimate-icon").length==0) {
			$(".estimate-icon").removeClass("menu-open")
			$(".estimate-container").hide();
			$("div#shade").hide();
		}
	});
	
	$(document).ready(function(e){
		if(location.hash){
		var newhash = window.location.hash.substring(1);
			$(".estimate-container").toggle();
			$("div#shade").toggle();
			$(".estimate-icon").toggleClass("menu-open");
		}else{
		}
	});

	
	$(".phone-dropdown-icon").click(function(e) {
		e.preventDefault();
		$(".phone-dropdown-container").toggle();
		$(".phone-dropdown-icon").toggleClass("menu-open");
	});

	$(".phone-dropdown-container").mouseup(function() {
		return false
	});
	$(document).mouseup(function(e) {
		if($(e.target).parent("a.phone-dropdown-icon").length==0) {
			$(".phone-dropdown-icon").removeClass("menu-open");
			$(".phone-dropdown-container").hide();
		}
	});
	
});
	
$(function(){$.fn.scrollToTop=function(){$(this).hide().removeAttr("href");if($(window).scrollTop()!="0"){$(this).fadeIn("fast")}var scrollDiv=$(this);$(window).scroll(function(){if($(window).scrollTop()=="0"){$(scrollDiv).fadeOut("fast")}else{$(scrollDiv).fadeIn("fast")}});$(this).click(function(){$("html, body").animate({scrollTop:0},"slow")})}});
$(function() {
	$("#toTop").scrollToTop();
});
