/* --- All Javascript For Catered Art --- */

jQuery(document).ready(function(){
	// Newsletter: Show on Hover
	jQuery("#newsletter").hover(function(){
		jQuery("#newsletter form").stop().animate({opacity:1},500);
	},function(){
		var newsletter_opacity=jQuery("#newsletter form").css("opacity");
		if(newsletter_opacity==1){jQuery("#newsletter form").stop().delay(1000).animate({opacity:0},1000);
		}else{jQuery("#newsletter form").stop().animate({opacity:0},500);}
	});



	// Content: Round Bottom-Right Corner if Exceeds Default Height	
	if(jQuery("#content").height()<=379){jQuery("#content").css({"-moz-border-radius":"10px 0 0 10px","-webkit-border-radius":"10px 0 0 10px","border-radius":"10px 0 0 10px"});}
	else if(jQuery("#content").height()==380){jQuery("#content").css({"-moz-border-radius":"10px 0 1px 10px","-webkit-border-radius":"10px 0 1px 10px","border-radius":"10px 0 1px 10px"});}
	else if(jQuery("#content").height()==381){jQuery("#content").css({"-moz-border-radius":"10px 0 2px 10px","-webkit-border-radius":"10px 0 2px 10px","border-radius":"10px 0 2px 10px"});}
	else if(jQuery("#content").height()==382){jQuery("#content").css({"-moz-border-radius":"10px 0 3px 10px","-webkit-border-radius":"10px 0 3px 10px","border-radius":"10px 0 3px 10px"});}
	else if(jQuery("#content").height()==383){jQuery("#content").css({"-moz-border-radius":"10px 0 4px 10px","-webkit-border-radius":"10px 0 4px 10px","border-radius":"10px 0 4px 10px"});}
	else if(jQuery("#content").height()==384){jQuery("#content").css({"-moz-border-radius":"10px 0 5px 10px","-webkit-border-radius":"10px 0 5px 10px","border-radius":"10px 0 5px 10px"});}
	else if(jQuery("#content").height()==385){jQuery("#content").css({"-moz-border-radius":"10px 0 6px 10px","-webkit-border-radius":"10px 0 6px 10px","border-radius":"10px 0 6px 10px"});}
	else if(jQuery("#content").height()==386){jQuery("#content").css({"-moz-border-radius":"10px 0 7px 10px","-webkit-border-radius":"10px 0 7px 10px","border-radius":"10px 0 7px 10px"});}
	else if(jQuery("#content").height()==387){jQuery("#content").css({"-moz-border-radius":"10px 0 8px 10px","-webkit-border-radius":"10px 0 8px 10px","border-radius":"10px 0 8px 10px"});}
	else if(jQuery("#content").height()==388){jQuery("#content").css({"-moz-border-radius":"10px 0 9px 10px","-webkit-border-radius":"10px 0 9px 10px","border-radius":"10px 0 9px 10px"});}
	else if(jQuery("#content").height()>=389){jQuery("#content").css({"-moz-border-radius":"10px 0 10px 10px","-webkit-border-radius":"10px 0 10px 10px","border-radius":"10px 0 10px 10px"});}
	
	// Content: Scroll Overflowed Content if Exceeds Max Height
	/*if(jQuery("#content").hasClass("no-header")){
		if(jQuery("#content-overflow").height()>575){jQuery("#content-overflow").css({"height":"575px","padding":"0 20px 0 30px","overflow":"auto"});}
	}else{
		if(jQuery("#content-overflow").height()>415){jQuery("#content-overflow").css({"height":"415px","padding":"0 20px 0 30px","overflow":"auto"});}
	}*/
	if(jQuery("#content-header").length==0){
		if(jQuery("#content-overflow").height()>575){jQuery("#content-overflow").css({"height":"575px","padding":"0 20px 0 30px","overflow":"auto"});}
	}else{
		if(jQuery("#content-overflow").height()>414){jQuery("#content-overflow").css({"height":"414px","padding":"0 20px 0 30px","overflow":"auto"});}
	}
	
	
	
	// Left Menu: Show Submenu
	jQuery("#menu > li").mouseenter(function(){
		jQuery("#menu > li ul").css("display","none");
		jQuery("#menu > li ul").css("opacity","0");
		
		jQuery(this).children("ul").css("display","block");
		jQuery(this).children("ul").css("z-index","500");
		jQuery(this).children("ul").stop().animate({opacity:1},500);
	});
	jQuery("#menu > li").mouseleave(function(){	
		jQuery(this).children("ul").stop().animate({opacity:0},250,function(){
			jQuery(this).css("z-index","10");
			jQuery(this).css("display","none");
		});	
	});
	// Left Menu: Slight Fade on Hover
	jQuery("#menu > li > a").mouseenter(function(){jQuery(this).stop().animate({"color":"#99bb55"},350);});
	function leftmenu_mouseleave(){jQuery("#menu > li > a").stop().animate({"color":"#eaeaea"},150);}
	jQuery("#menu, #menu > li, #menu > li > a").mouseleave(leftmenu_mouseleave);
	
	
	
	// Top Navigation: Show Menu
	function topnav_mouseleave(){
		jQuery("div.nav-container, #topnav").css("overflow","hidden");
		jQuery("#top-menu").css("background-position","230px 0px");
	}	
	jQuery("#topnav").mouseenter(function(){
		jQuery(this).stop();
		jQuery("#top-menu").css("background-position","230px -10px");
		jQuery(this).stop().animate({"bottom":"0px","height":"70px"},250,function(){
			jQuery("div.nav-container, #topnav").css("overflow","visible");
		});
	});
	jQuery("#topnav").mouseleave(function(){
		jQuery(this).stop();
		var topnav_bottom=jQuery("#topnav").css("bottom");
		if(topnav_bottom=="0px"){
			jQuery(this).stop().delay(2000).animate({"bottom":"-62px","height":"8px"},500,topnav_mouseleave);
		}else{
			jQuery(this).stop().animate({"bottom":"-62px","height":"8px"},500,topnav_mouseleave);
		}
	});
	
	// Top Navigation: Show on Page Load
	jQuery("#top-menu").css("background-position","230px -10px");
	var topnav_bottom=jQuery("#topnav").css("bottom");
	if(topnav_bottom=="0px"){
		jQuery("#topnav").stop().delay(5000).animate({"bottom":"-62px","height":"8px"},500,topnav_mouseleave);
	}
	
	// Top Navigation: Show Sub-menu
	jQuery("#top-menu > li > div > ul").each(function(){
		var thisHeight = jQuery(this).height();
		var thisParentHeight = jQuery(this).parent().height();
		var totalHeight = thisHeight + thisParentHeight + 15;/*15 is the margin-top*/
		var usable = totalHeight+'px';
		jQuery(this).parent().mouseenter(function(){
			jQuery(this).stop().animate({height:usable},200);
		});
		jQuery(this).parent().mouseleave(function(){
			jQuery(this).stop().animate({height:"40px"},0);
		});
	});
	
	
	
	// Datepicker
	jQuery(".datepicker").datepicker({dateFormat:'MM d, yy'});
	
	
	
	// (Site) Background Fade
	jQuery("#gallery").mouseenter(function(){
		jQuery("#view-gallery").css({"display":"block"});
		jQuery("#view-gallery").stop().animate({"right":"0px"},250);
	});
	jQuery("#gallery").mouseleave(function(){
		jQuery("#view-gallery").stop().animate({"right":"-25px"},250,function(){
			jQuery("#view-gallery").css({"display":"none"});
		});
	});
	jQuery("#view-bg a").click(function(){
		if(!jQuery(this).hasClass("active")){
			jQuery("#view-bg a").addClass("active");
			jQuery("#header, #middle, #footer").stop().fadeOut(500).delay(6000).fadeIn(500,function(){
				jQuery("#view-bg a").removeClass("active");
			});
		}else{
			jQuery("#view-bg a").removeClass("active");
			jQuery("#header, #middle, #footer").stop().fadeIn(500);
		}
	});
	
	// Gallery
	jQuery("#view-gallery a[rel^='prettyPhoto']").prettyPhoto({theme:'light_rounded'});
	/*jQuery("#view-gallery a").click(function(){
		jQuery("div.pp_fade").append('<a id="lightbox-flickr" href="http://www.flickr.com/photos/cateredart/" target="_blank">View all of Catered Art\'s images on Flickr &raquo;</a>');
	});*/
	
	

	// Inquire Form
	jQuery("div.inquire-tab-button").click(function(){
		var hiddenForm=jQuery(this).parent("h3").siblings("div.inquire-hidden");
		var hiddenFormHeight=jQuery(hiddenForm).height();
		if(hiddenFormHeight==0||hiddenFormHeight=="0px"||hiddenFormHeight=="0pt"){
			jQuery(hiddenForm).stop().animate({"height":"114px"},500);
		}else{
			jQuery(hiddenForm).stop().animate({"height":"0px"},250);
		}
	});
	
});
