$(document).ready(function() {
	//$('#gallery a').lightBox();
	
	//$("a.fancybox").fancybox();
	$("a.fancybox").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	true,
		'overlayColor'	:	'#1a1a1a',
		'titlePosition'	:	'inside'
	});

	
	// ** Navigation 
	$("ul.sub-menu").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)

	$("ul.menu li span").hover(function() { //When trigger is clicked...

		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).parent().find("ul.sub-menu").slideDown('fast').show(); //Drop down the subnav on click

		$(this).parent().hover(function() {
		}, function(){
			$(this).parent().find("ul.sub-menu").slideUp('fast'); //When the mouse hovers out of the subnav, move it back up
		});

		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() {
			$(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
	});
	
	//Load the slideshow
	theRotator();
	
	//$('div.rotator').each(){
	//	fadeIn(600);
	//}
    //$('div.rotator ul li').fadeIn(600); // tweek for IE

});

/*** 
    Simple jQuery Slideshow Script
    Released by Jon Raasch (jonraasch.com) under FreeBSD license: free to use or modify, not responsible for anything, etc.  Please link out to me if you like it :)
***/
function slideSwitch() {
    var $active = $('#slideshow DIV.active');

    if ( $active.length == 0 ) $active = $('#slideshow DIV:last');

    // use this to pull the divs in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow DIV:first');

    // uncomment below to pull the divs randomly
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "slideSwitch()", 5000 );
});

/* Drop down menus for IE */
startList = function() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("hover-nav");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
				this.className+=" over";
				  }
				  node.onmouseout=function() {
				  this.className=this.className.replace(" over", "");
				   }
			   }
		  }
	 }
}
window.onload=startList;


/* Smooth scroll */

$(function(){
    $('a[href*=#]').click(function() {
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
        && location.hostname == this.hostname) {
            var $target = $(this.hash);
            $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
            if ($target.length) {
                var targetOffset = $target.offset().top;
                $('html,body').animate({scrollTop: targetOffset}, 1000);
                return false;
            }
        }
    });
});

function theRotator() {
	//Set the opacity of all images to 0
	//$('div.rotator ul li').css({opacity: 0.0});
	
	//Get the first image and display it (gets set to full opacity)
	//$('div.rotator ul li:first').css({opacity: 1.0});
		
	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
   setInterval('rotate()',4000);
	
}

function rotate() {	
	//Get the first image
	
	
	var current1 = ($('div.rotator1 ul li.show')?  $('div.rotator1 ul li.show') : $('div.rotator1 ul li:first'));
	var current2 = ($('div.rotator2 ul li.show')?  $('div.rotator2 ul li.show') : $('div.rotator2 ul li:first'));
	var current3 = ($('div.rotator3 ul li.show')?  $('div.rotator3 ul li.show') : $('div.rotator3 ul li:first'));

    if ( current1.length == 0 ) current1 = $('div.rotator1 ul li:first');
    if ( current2.length == 0 ) curren2t = $('div.rotator2 ul li:first');
    if ( current3.length == 0 ) current3 = $('div.rotator3 ul li:first');

	//Get next image, when it reaches the end, rotate it back to the first image
	var next1 = ((current1.next().length) ? ((current1.next().hasClass('show')) ? $('div.rotator1 ul li:first') :current1.next()) : $('div.rotator1 ul li:first'));
	var next2 = ((current2.next().length) ? ((current2.next().hasClass('show')) ? $('div.rotator2 ul li:first') :current2.next()) : $('div.rotator2 ul li:first'));
	var next3 = ((current3.next().length) ? ((current3.next().hasClass('show')) ? $('div.rotator3 ul li:first') :current3.next()) : $('div.rotator3 ul li:first'));
	
	//Un-comment the 3 lines below to get the images in random order
	
	//var sibs = current.siblings();
        //var rndNum = Math.floor(Math.random() * sibs.length );
        //var next = $( sibs[ rndNum ] );
			

	//Set the fade in effect for the next image, the show class has higher z-index
	next1.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current1.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	//Set the fade in effect for the next image, the show class has higher z-index
	next2.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current2.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	//Set the fade in effect for the next image, the show class has higher z-index
	next3.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current3.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	
};

