
// DOM READY // ========================================================================
$(function(){

// MISC
// ====================================================================================
	$(".widget_recent_entries h2").click(function(){location.href='/category/news';});

// ====================================================================================
// SUPERFISH NAV
// ====================================================================================	
	
	/*
	$("ul.sf-menu > li > a").click(function(){
		return false;
	});
	$("ul.sf-menu > li:first-child > a").click(function(){
		location.href=$(this).attr("href");
	});
	*/

	
  $("ul.sf-menu").supersubs({ 
    minWidth:    12,   // minimum width of sub-menus in em units 
    maxWidth:    50,   // maximum width of sub-menus in em units 
    extraWidth:  1     // extra width can ensure lines don't sometimes turn over 
                       // due to slight rounding differences and font-family 
  }).superfish(); 



// ====================================================================================
// COLORBOX
// ====================================================================================	

	$(".colorbox").colorbox();


// ====================================================================================
// FIX CFORM TEXTAREA ISSUE
// ====================================================================================		
	
	$("textarea.area").keydown(function(event){
		if(event.keyCode == '32'){
			$("textarea.area").val( $(this).val() + " "); 
		}
	});

// ====================================================================================
// IF NOTHING SELECTED IN CHILDREN LI
// ====================================================================================		
	//console.log($("li.current_page_item > ul.children > li.current_page_item").length);
	if($("li.current_page_item > ul.children > li.current_page_item").length < 1){
		$("li.current_page_item > ul.children > li:first").addClass("current_page_item");
	}
	
// ====================================================================================
// Vedanta Gallery
// ====================================================================================	
		
		/// for each href in a regular gallery, add it to the vedanta gallery
		$(".gallery-icon a").each(function(){
			$("#vedanta-gallery").append("<img src='"+$(this).attr("href")+"'/>");
		});
				
		
		var init_vedanta_gallery = function(){
			/// SIMPLE GALLERY, AUTO CYCLES AND HAS BUTTONS TO GO NEXT/PREVIOUS
			$("#vedanta-gallery").prepend("<a id='vedanta-gallery-btn-previous'></a><a id='vedanta-gallery-btn-next'></a>"); 
			
			$("#vedanta-gallery img:first").addClass("vedanta-gallery-on").fadeIn().addClass("vedanta-gallery-first");
			$("#vedanta-gallery img:last").addClass("vedanta-gallery-last");		
			
			
			$("#vedanta-gallery img").css("cursor", "pointer");
			
			/// click image, move to next image
			$("#vedanta-gallery img").click(function(){
				$("#vedanta-gallery-btn-next").trigger("click");
				/// reset cycle
				var vedantaGalleryCycleFlag = true;
				setInterval(vedantaGalleryCycle, 6000);
			});
		
			$("#vedanta-gallery").hover(
				function(){
					/// if gallery is hovered over, fade in prev/next buttons & stop cycle
					//$("#vedanta-gallery-btn-previous, #vedanta-gallery-btn-next").fadeIn();
					vedantaGalleryCycleFlag = false;
				},
				function(){
					/// if gallery is hovered out, fade out prev/next buttons & start cycle
					//$("#vedanta-gallery-btn-previous, #vedanta-gallery-btn-next").fadeOut();
					vedantaGalleryCycleFlag = true;
				}
			);
			
			/// if next button is clicked
			$("#vedanta-gallery-btn-next").live("click", function(){
				/// if the current on image is the last image, don't fade in next, fade in the first
				if ( $(".vedanta-gallery-on").hasClass("vedanta-gallery-last") ){
					$(".vedanta-gallery-on").removeClass("vedanta-gallery-on").fadeOut();
					$(".vedanta-gallery-first").fadeIn().addClass("vedanta-gallery-on");
				} else {
				/// else, fade in next
					$(".vedanta-gallery-on").removeClass("vedanta-gallery-on").fadeOut().next().fadeIn().addClass("vedanta-gallery-on");
				}
			});
	
			/// if previous button is clicked
			$("#vedanta-gallery-btn-previous").live("click", function(){
				/// if the current on image is the first image, don't fade in next, fade in the last
				if ( $(".vedanta-gallery-on").hasClass("vedanta-gallery-first") ){
					$(".vedanta-gallery-on").removeClass("vedanta-gallery-on").fadeOut();
					$(".vedanta-gallery-last").fadeIn().addClass("vedanta-gallery-on");
				} else {
				/// else, fade in prev
					$(".vedanta-gallery-on").removeClass("vedanta-gallery-on").fadeOut().prev().fadeIn().addClass("vedanta-gallery-on");
				}
			});
			
			var vedantaGalleryCycle = function(){
				if(vedantaGalleryCycleFlag){
					$('#vedanta-gallery-btn-next').trigger('click');
				}
			}
			
			/// cycle
			var vedantaGalleryCycleFlag = true;
			setInterval(vedantaGalleryCycle, 6000);	
		}	/// end init func
		
		/// Run init
		var ivg = init_vedanta_gallery();
	

		// I HATE TITLES //
		$("a, img").each(function(){
			var this_a = $(this);
			this_a.attr("data-title", this_a.attr("title"));
			this_a.attr("title", "");
		});

	
});

// END DOM READY // ===================================================================

