﻿   var intervalRun= ""
   $(function() {
   

       	
	    //HOMEPAGE SLIDER
	     $("#slides .prev").click(function() {
   	        clearInterval(intervalRun)
	        slideSwitch('forward');
            intervalRun= setInterval("slideSwitch('forward')", 5000);
	     });
    	
    	
	    $("#slides .next").click(function(){
	        clearInterval(intervalRun)	
	        slideSwitch('previous');
	        intervalRun= setInterval("slideSwitch('forward')", 5000);
	    });
    	
    	
	    //LIGHTBOX
	     $("#lightbox a.lightbox").lightBox();
	


    });

	
    function slideSwitch(direction) {
        var $active = $('#slideshow IMG.active');
        if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

	    if(direction=='forward'){	
	        var $next =  $active.next().length ? $active.next() : $('#slideshow IMG:first');
	    }
	    else{
	      var $next =  $active.prev().length ? $active.prev() : $('#slideshow IMG:last');

	    }
        $active.addClass('last-active');

        $next.css({opacity: 0.0})
            .addClass('active')
            .animate({opacity: 1.0}, 1000, function() {
                $active.removeClass('active last-active');
            });
    }

 
function hpLoadingFinished() {
    $('#hp-loading').fadeOut();
    intervalRun= setInterval( "slideSwitch('forward')", 5000 );
}

