/*** 
    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 = $('#slider IMG.active');

    if ( $active.length == 0 ) $active = $('#slider IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slider IMG:first');

    // uncomment the 3 lines below to pull the images in random order
    
    // 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 SetMenuSelected(fm, sm,tm){
	if (fm > -1) {
		$('#nav a').eq(fm).css({backgroundPosition: "0 -61px"}).addClass('active');
		if (sm > -1){
		    $('#sotto-menu').animate({height:'320px'}, {duration:1});
			$('#subnav' + fm).show().siblings().hide();
			$('#subnav' + fm + ' a').eq(sm).css({backgroundPosition: "224px 0px"}).addClass('active');		
			if (tm > -1){
				$('#right-submenu').css({'margin-top' : String(166 + (sm * 59)) + 'px'});
			    $('#right-submenu').show();
				$('#mnu' + fm + 'dx' + sm).show().siblings().hide();
				$('#mnu' + fm + 'dx' + sm + ' a').eq(tm).css({backgroundPosition: "0px -59px"}).addClass('active');	
			}
		}
	}
	
	
	
}
$(document).ready(function() {
    setInterval( "slideSwitch()", 5000 );
	$('#sotto-menu').animate({height:'0px'}, {duration:1});
	$('#sotto-menu ul').hide();
	$('#right-submenu').hide();
	/*fade menu*/
	$('#nav a')
		.css( {backgroundPosition: "0px 0px"} )
		.mouseover(function(){
			if ($(this).hasClass('active') == true) {
			
			}
			else
			{
				$(this).stop().animate({backgroundPosition:"(0px -61px)"}, {duration:100})
			}
		})
		.mouseout(function(){
			if ($(this).hasClass('active') == true) {
			
			}
			else
			{
				$(this).stop().animate({backgroundPosition:"(0px 0px)"}, {duration:200, complete:function(){
					$(this).css({backgroundPosition: "0px 0px"})
				}})
			}
		})
		.click(function(){
			var mnu = $('#nav a').index(this);
			$('#right-submenu').hide();
			$(this).addClass('active').parent().siblings().children('a').removeClass('active').animate({backgroundPosition:"(0px 0px)"}, {duration:100});
			if ($('#subnav' + mnu).length == 0) {
			   $('#sotto-menu').animate({height:'0px'}, {duration:1});
			   $('#sotto-menu ul').hide();
			} else {
				$('#sotto-menu').animate({height:'0px'}, {duration:1});
			   $('#sotto-menu').animate({height:'320px'}, {duration:300});
				$('#subnav' + mnu).show().siblings().hide();
			
			}
		 })
	
	  $('.submenu a')
	.css( {backgroundPosition: "0 0"} )
	.mouseover(function(){
		
			if ($(this).hasClass('active') == false) {
				$(this).stop().animate(
				{backgroundPosition:"(224px 0px)"}, 
				{duration:10})
			}	
		
		
		})
	.mouseout(function(){
		if ($(this).hasClass('active') == false) {
			$(this).stop().animate(
				{backgroundPosition:"(0 0)"}, 
				{duration:10})
		}
		})
		
	.click(function(){
		var mnu = $(this).parent().parent().attr('ID');
		var l = String(mnu).length;
		mnu = String(mnu).substring(l, l-1);
		var mnudx = $('#subnav' + mnu +' a').index(this);

		if ($('#mnu' + mnu + 'dx' + mnudx).length == 0) {
		   $('#right-submenu').hide();
		} else {
			$('#right-submenu').css({'margin-top' : String(166 + (mnudx * 59)) + 'px'});
		   $('#right-submenu').show();
			$('#mnu' + mnu + 'dx' + mnudx).show().siblings().hide();
		
		}
	 })
	
	 $('#right-submenu a')
	.css( {backgroundPosition: "0 0"} )
	.mouseover(function(){
			if ($(this).hasClass('active') == false) {
				$(this).stop().animate(
				{backgroundPosition:"(0px -59px)"}, 
				{duration:100})
			}
		})
	.mouseout(function(){
			if ($(this).hasClass('active') == false) {
				$(this).stop().animate(
				{backgroundPosition:"(0 0)"}, 
				{duration:500})
			}
		})
	
	/*popup menu*/
	
	

});


