// -- CUSTOM FUNCTIONS AND EFFECTS --

// -- NO CONFLICT MODE

var $ = jQuery.noConflict();

$(document).ready(function(){
	
	// Twitter Js
	          $(".tweet").tweet({
	            join_text: "auto",
	            username: "visitsaratogany",
	            avatar_size: 0,
	            count: 1,
	            auto_join_text_default: "we said,",
	            auto_join_text_ed: "we",
	            auto_join_text_ing: "we were",
	            auto_join_text_reply: "we replied",
	            auto_join_text_url: "we were checking out",
	            loading_text: "Loading tweets..."
          });
	
	// -- HIDE IMAGES BEFORE LOADING
	
	$(".foldify, .cycle_slider li, #nivo_slider").addClass('preload').find('img').hide();								
	
	
	// -- NAVIGATION MENU
	
	$('.headernavigation ul, .headernavigation2 ul').css({display: "none"});
	$('.headernavigation li:has(ul), .headernavigation2 li:has(ul)').addClass('has_child');
	$('.headernavigation li, .headernavigation2 li').hover(function(){	
		$(this).find('ul:first').css({visibility: "visible",display: "none"}).fadeIn(300);
	},
	function(){
		$(this).find('ul:first').css({visibility: "visible",display: "none"});
	});	
	
	$(".headernavigation ul li:has(ul), .headernavigation2 ul li:has(ul)").removeClass('has_child').addClass("arrow");
	
	$(".headernavigation ul li a, .headernavigation2 ul li a").hover(
		function(){
			$(this).animate({paddingLeft:"12px"},160);
		}, 
		function() {
			$(this).animate({paddingLeft:"5px"},160);
		}
	);
	
	
	// -- ACCORDION
	
	$('h5.handle').click(function() {
		$(this).next().slideToggle(300);
		$(this).toggleClass("activehandle");
		return false;
	}).next().hide();
	
	
	// -- FAQ
	
	$('h5.question').click(function() {
		$(this).next().slideToggle(300);
		$(this).toggleClass("activeques");
		return false;
	}).next().hide();	
	
	
	// -- TOGGLE
	
	$('h5.toggle').click(function() {
		$(this).next().slideToggle(300);
		$(this).toggleClass("activetoggle");
		return false;
	}).next().hide();	
	
	
	// -- PRETTYPHOTO INIT
	
	$("a[rel^='prettyPhoto[group1]'], a[rel^='prettyPhoto[group2]'], a[rel^='prettyPhoto[inline]']").prettyPhoto()


	// -- TOP OF PAGE
	
	$('.top').click(function(){ 
		$('html, body').animate({scrollTop:0}, 500 ); 
		return false; 
	});
	

	// Box Close Button
	
	$(".box").each(function(){
		$(this).append('<span class="hide_box"></span>');
			$(this).find('.hide_box').click(function(){
			$(this).parent().hide();
		});
	});
	
}) // END DOCUMENT.READY

$(window).load( function() {
	
	// -- SHOW IMAGES ON LOAD
	
	$(".foldify, .cycle_slider li, #nivo_slider").removeClass('preload').find('img').fadeIn();
	
	// -- CYCLE SLIDER INIT
	
	$('.cycle_slider').cycle({ 
		fx:     'fade', 
		speed:  400, 
		timeout: 6000, 
		next: '.next',  
		prev: '.prev',
		sync: 1,
		pause: 1,
		cleartype: true,
		pager:  '.cycle_nav', 
		pagerAnchorBuilder: function(idx, slide) { 
			return '<li><a href="#"></a></li>'; 
		} 
	});
	
	
	// -- SHOW/HIDE SLIDER CONTROLS
	
	$('.show_desc').fadeIn();
	$('.controls').hide();
	$('.slider').hover(function(){
		$('.controls').show();
	}, function() {
		$('.controls').hide();
	});

	// -- Foldify Images
	
	$(".foldify").append('<span class="fold_wrap"><span class="fold"></span></span>');
	$(".fold_wrap").css({right:"-50px", bottom:"-50px"});
	$(".fold").css({top:"-25px", left:"-25px"});
	$(".foldify").each(function(){
		$(this).hover(function(){
			$(this).find(".fold_wrap").stop().animate({right:"0px", bottom:"0px"}, 300);
			$(this).find(".fold").stop().animate({top:"0px", left:"0px"}, 300);
		}, function(){
			$(this).find(".fold_wrap").stop().animate({right:"-50px", bottom:"-50px"}, 400);
			$(this).find(".fold").stop().animate({top:"-25px", left:"-25px"}, 400);
		});
	});	
})

