// Copyright 2010 New Wave Media. All rights reserved.

/* --------------------------------------------
|  GLOBAL JAVASCRIPT												
--------------------------------------------- */

// Insert Copyright Year
function copyrightYear(){
	if(document.getElementById('setYear')) document.getElementById('setYear').innerHTML = new Date().getFullYear();
}

// Set External Links
function externalLinks(){
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		if (anchors[i].getAttribute("href") && anchors[i].getAttribute("rel") == "external") anchors[i].target = "_blank";
	}
}

// On Site Load
function siteOnLoad () {
	copyrightYear();
	externalLinks();
}

// Add Load Event
function addLoadEvent(func){
	var oldOnLoad = window.onload;
	if(typeof window.onload != 'function'){
		window.onload = func;
	}
	else{
		window.onload = function(){
			oldOnLoad();
			func();
		}
	}
}

addLoadEvent(siteOnLoad);

// Clear Search Text
function clearSearch() {
	document.getElementById("searchInput").value="";
}

/* --------------------------------------------
|  CUSTOM JAVASCRIPT											
--------------------------------------------- */

// Disable Back-Forward Cache - Helps with Cufon's Hover State "Sticking" on menu list items
if (window.addEventListener) {
	window.addEventListener('unload', function() {}, false);
}

// jQuery DropDown Menu
$(document).ready(function() {

	$("#priNav li ul").hide(); 

	$("#priNav li").hover(
	  function() {
	  	$(this).children("ul").stop(true, true).slideDown("fast");
	  	},
	  function() {
	  	$(this).children("ul").stop(true, true).slideUp("fast");
	  	}
	  );

});

// jQuery Slider - Execute your scripts when DOM is ready. this is a good habit 
$(function() { 
 
  $("div.scrollable").scrollable({
    	size: 1, 
    	items: '#thumbs', 
    	hoverClass: 'hover',
    	pause: 1
  	})
  	.navigator().mousewheel().autoscroll({ 

			interval: 6000         
		}); 
		
		//FADING EFFECT
		api = $('div.scrollable').scrollable(); 
		api.onBeforeSeek(function(event,index){ 
		 
		    /* Use a recursive* function approach here, if the image is faded out 
		     * we will allow advancing to the next slide, which will trigger the 
		     * onSeek event to fade the slides back in */ 
		    var element = jQuery("div.scrollable"); 
		    if (element.css('opacity') == .01) { 
		        return true; 
		    } 
		 
		    /* The slide has not yet started fading out, so we will fade the item 
		     * out */ 
		    element.fadeTo("slow", .01, function(){ 
		        /* Once the fade is complete we will call api.seekTo() to trigger 
		         * the onBeforeSeek event again, which will now advance the slide 
		         * because we will be returning true instead of false */ 
		        api.seekTo(index); 
		    }); 
		 
		    // Prevent advancing the slide on the first call to onBeforeSeek 
		    return false; 
		 
		}).onSeek(function(){ 
		 
		    // Fade the item back in 
		    jQuery("div.scrollable").fadeTo('slow', 1); 
		 
		}); 
		//FADING EFFECT
					 
}); 
