// JavaScript Document

var timeout         = 500;
var closetimer		= 0;
var ddmenuitem      = 0;

function jsddm_open()
{	jsddm_canceltimer();
	jsddm_close();
	ddmenuitem = $(this).find('ul').eq(0).css('visibility', 'visible');}

function jsddm_close()
{	if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

function jsddm_timer()
{	closetimer = window.setTimeout(jsddm_close, timeout);}

function jsddm_canceltimer()
{	if(closetimer)
	{	window.clearTimeout(closetimer);
		closetimer = null;}}

$(document).ready(function() {	
	$(".hp-banner-description .desc").show(); //Show Banner
	$(".hp-banner-description .block").animate({ opacity: 0.85 }, 1 ); //Set Opacity
	
	$(".image_thumb ul li:first").addClass('active');  //Add the active class (highlights the very first list item by default)
	$(".image_thumb ul li").click(function(){
		//Set Variables
		var imgAlt = $(this).find('img').attr("alt"); //Get Alt Tag of Image
		var imgTitle = $(this).find('a').attr("href"); //Get Main Image URL
		var imgDesc = $(this).find('.block').html();  //Get HTML of the "block" container
		var imgDescHeight = $(".hp-banner-description").find('.block').height(); //Find the height of the "block"
	
		if ($(this).is(".active")) {  //If the list item is active/selected, then...
			return false; // Don't click through - Prevents repetitive animations on active/selected list-item
		} else { //If not active then...
			//Animate the Description
			$(".hp-banner-description .desc .block").animate({ opacity: 0}, 250 , function() { //Pull the block down (negative bottom margin of its own height)
				$(".hp-banner-description .desc .block").html(imgDesc).animate({ opacity: 0.85}, 250 ); //swap the html of the block, then pull the block container back up and set opacity
				$(".hp-banner-image img").attr({ src: imgTitle , alt: imgAlt}); //Switch the main image (URL + alt tag)
			});
		}
		//Show active list-item
		$(".image_thumb ul li").removeClass('active'); //Remove class of 'active' on all list-items
		$(this).addClass('active');  //Add class of 'active' on the selected list
		return false;
	
	}) .hover(function(){ //Hover effects on list-item
		$(this).addClass('hover'); //Add class "hover" on hover
		}, function() {
		$(this).removeClass('hover'); //Remove class "hover" on hover out
	});
	
	$("a.collapse").click(function(){
		$(".main_banner .block").slideToggle(); //Toggle the description (slide up and down)
		$("a.collapse").toggleClass("show"); //Toggle the class name of "show" (the hide/show tab)
	});
	
	$('#main-navigation > li').bind('mouseover', jsddm_open);
	$('#main-navigation > li').bind('mouseout',  jsddm_timer);
	
	$('#nav-tabs').tabify();
	
});//Close Function	

document.onclick = jsddm_close;

