//Dropdowns
$(document).ready(function(){

    $("ul.dropdown li").hover(function(){
    
        $(this).addClass("hover");
        $('ul:first',this).css('visibility', 'visible');
    
    }, function(){
    
        $(this).removeClass("hover");
        $('ul:first',this).css('visibility', 'hidden');
    
    });
    
    $("ul.dropdown li ul li:has(ul)").find("a:first").append(" &raquo; ");

});



//Accordion
$(document).ready(function(){
	
	$(".body-accord h4:first").addClass("active");
	$(".body-accord div:not(:first)").hide();

	$(".body-accord h4").click(function(){
		$(this).next("div").slideToggle("slow")
		.siblings("div:visible").slideUp("slow");
		$(this).toggleClass("active");
		$(this).siblings("div").removeClass("active");
	});

});

//Products Sidebar Accordion
$(document).ready(function(){

	$(".products-accord div.true").prev(".products-accord p").addClass("active-p");
	
    $(".products-accord p").click(function(){
		$(this).next("div").slideToggle("slow")
		.siblings("div:visible").slideUp("slow");
		$(this).toggleClass("active-p");
		$(this).siblings("p").removeClass("active-p");
	});

});


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

function slide() {	
	//Get the first image
	var current = ($('div#slides ul li.show')?  $('div#slides ul li.show') : $('div#slides ul li:first'));

	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#slides ul li:first') :current.next()) : $('div#slides ul li:first'));	
	
	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

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

$(document).ready(function() {		
	//Load the slideshow
	theSlider();
});


//Logo Rotation
function theRotator() {
	//Set the opacity of all images to 0
	$('div#logos ul li').css({opacity: 0.0});
	
	//Get the first image and display it (gets set to full opacity)
	$('div#logos 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()',3500);
	
}

function rotate() {	
	//Get the first image
	var current = ($('div#logos ul li.show')?  $('div#logos ul li.show') : $('div#logos ul li:first'));

	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#logos ul li:first') :current.next()) : $('div#logos ul li:first'));	
	
	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

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

$(document).ready(function() {		
	//Load the slideshow
	theRotator();
});


//Fancybox
$(document).ready(function() {
			$("a.zoom").fancybox();
		});


//Fancyvideo
 $(document).ready(function() {
        $("a[@rel*=fancyvideo]").fancybox({
            overlayShow: true,
            frameWidth:480,
            frameHeight:385
        });
    });
