$(document).ready(function() {
	
	// Nivo Slider
	$('#slides').nivoSlider({
		effect:'random',
		directionNav: false,
		animSpeed:500,
		pauseTime:4000,
		captionOpacity: 1
	});
	
	// Media Slideshow
	$("#media_slideshow").tabs({ fx:{ opacity: "toggle" } }).tabs("rotate", 5000, true);
	$("#media_slideshow").hover(function() {
		$("#media_slideshow").tabs("rotate",0,true);
	},function() {
		$("#media_slideshow").tabs("rotate",5000,true);
	});
	
	// Drop down menus
	$("div#header #nav li ul").each(function() {
		$(this).prepend('<li class="arrow"></li>');
		$(this).css({
			'left' : -($(this).width() / 2 - ($(this).parent().width() / 2) + 10)
		});
	});
	$("div#header #nav li").hover(function() {
		if($(this).find("ul").size != 0) {
			$(this).find("ul").stop(true, true).fadeIn("fast");
		}
	}, function() {
		$(this).find("ul").stop(true, true).fadeOut("fast");
	});
	
	$("div#header ul#nav li").each(function() {
		$("ul li:last a", this).css({ 'border' : 'none' });
	});
	
	// Hours Drop Down
	$(".hours").css({ 'top' : "-"+($(".hours").outerHeight())+"px" });
	$("a.hours_toggle").click(function() {
		if($(this).hasClass("active")) {
			$(".hours").animate({ 'top' : "-"+($(".hours").outerHeight())+"px" }, 300);
			$(this).animate({ 'top' : '-1px' }, 300)
						 .removeClass("active")
						 .find("span")
						 .addClass("down").removeClass("up");
		} else {
			$(".hours").animate({ 'top' : 0 }, 300);
			$(this).animate({ 'top' : $(".hours").height() + $(this).outerHeight() - 6 }, 300)
						 .addClass("active")
						 .find("span")
						 .removeClass("down").addClass("up");
		}
	});
	
	// Our story reviews slideshow
	$("#reviews").tabs({ fx:{ opacity: "toggle" } }).tabs("rotate", 3000, true);
	
	// Gallery Slideshow 
	$("#slideshow").nivoSlider({
			effect:'fade',
	    controlNavThumbs:true,
			controlNavThumbsReplace: '.jpg',
			directionNav: false,
			captionOpacity: 1,
			afterLoad: function(){
				$(".nivo-controlNav a:nth-child(7n) img").css({ 'margin-right' : 0 });
			}
	});
	
	// Gallery hover
    $("div#gallery .three_column li, div#gallery .four_column li, div#gallery .products_list li").each(function () {
		$("a", this).append('<div class="hover"></div>');
	});
	$("div#gallery .three_column li, div#gallery .four_column li, div#gallery .products_list li").hover(function() {
		$("a", this).find(".hover").stop(true, true).fadeIn(400);
	}, function() {
		$("a", this).find(".hover").stop(true, true).fadeOut(400);
	});

// Gallery Fancyboxes

    //	$("a.gallery_image").fancybox({
    //		'transitionIn'	:	'elastic',
    //		'transitionOut'	:	'elastic',
    //		'speedIn'		:	400, 
    //		'speedOut'		:	400, 
    //		'overlayShow'	:	false
    //	});

	$("#gallery ul.three_column li:nth-child(3n)").addClass("last");
	$("#gallery ul.four_column li:nth-child(4n)").addClass("last");
	
	// Small Sidebar
	$("div#flickr ul li").hover(function() {
		$(this).animate({ 'opacity' : '0.6' }, 300);
	}, function() {
		$(this).stop(true,true).animate({ 'opacity' : '1' }, 300)
	});
	
	// Tabs, toggles and accordions
	$(".tabs").tabs();
	$(".accordion").accordion({ autoHeight: false, header: '.heading' });
	$(".small_accordion").accordion({ autoHeight: false });
	$(".list_accordion").accordion({ autoHeight: false, active: false });
	
	// Button hover state
	$(".button").stop(true,true).hover(function() {
		$(this).animate({ 'opacity' : '0.8' }, 300);
	}, function() {
		$(this).stop(true,true).animate({ 'opacity' : '1' }, 300)
	});
	
	// Pricing table hover
	$(".pricing_box").hover(function() {
		$(this).stop(true,true).animate({ 'opacity' : '1' }, 300).addClass("active");
	}, function() {
		$(this).stop(true,true).animate({ 'opacity' : '0.8' }, 300).removeClass("active");
	});
	
	// Default text field values
	$(".text_field").focus(function(srcc)
  {
      if ($(this).val() == $(this)[0].title) {
          $(this).addClass("text_field_active");
          $(this).val("");
      }
  });
  $(".text_field").blur(function() {
      if ($(this).val() == "") {
          $(this).removeClass("text_field_active");
          $(this).val($(this)[0].title);
      }
  });
  $(".text_field").blur();
	
	// Fix table borders
	$("table").each(function() {
		$("tr th:last", this).addClass("no_right_border");
		$("tr:last td", this).addClass("no_bottom_border");
		$("tr", this).each(function() {
			$("td:last", this).addClass("no_right_border");
		});
	});	
	
	// Twitter Arrows
	//$("div#feedback div.tweets ul li").append('<em class="arrow"></em>');
	
	// UL borders
	$(".press ul li:last, .specials ul li:last").css({ 'border-bottom' : 'none' });
	
	// Hours & location hover states
	$(".directions a").css({ 'opacity' : 0.6 }).append("<span></span>");
	$(".directions a").hover(function() {
		$(this).stop(true, true).animate({ 'opacity' : 1 }, 200);
	}, function() {
		$(this).stop(true, true).animate({ 'opacity' : 0.6 }, 200);
	});

// Ajax contact form

    //	$('#contact_form').submit(function() {
    //       
    //		var this_form = $(this);
    //  	$.ajax({
    //  		type: 'post',
    //  		data: this_form.serialize(),
    //  		url: 'scripts/send_email.php',
    //  		success: function(res) {
    //  			if(res == "true") {
    //					$(this_form)[0].reset();
    //					$(".notice").removeClass("error").text("Thank you for contacting us!").addClass("success").fadeIn("fast");
    //  			} else {
    //  				$(".notice").text("Please check all fields and try again.").addClass("error").fadeIn("fast");
    //  			}
    //  		}
    //  	});
    //		
    //   });
	
});

