$(document).ready(function(){
						   
						   
						   
		$('#m1 a.click').click(function(e) {
		
		 e.preventDefault();
         $('#u_m1').slideDown(600);
		 
		   setTimeout(function(){
           $("#m1 a.click").addClass("on_m1");
           },400);
    });	
	
	
	
	$('#m1 a.on_m1').live('click', function() {
         $('#u_m1').slideUp(400);
		 
		 
		 setTimeout(function(){
     $("#m1 a.click").removeClass("on_m1");
},600);
    });
	
	/*$('#m1 a.click').mouseleave(function() {
		 $('#u_m1').slideUp(400);
    });	*/
	
	
	$('#m2 a.click').click(function(e) {
		 e.preventDefault();
         $('#u_m2').slideDown(600);
		 setTimeout(function(){
           $("#m2 a.click").addClass("on_m2");
           },400);
    });
	
	
	$('#m2 a.on_m2').live('click', function() {
         $('#u_m2').slideUp(400);
		 
		 
		 setTimeout(function(){
     $("#m2 a.click").removeClass("on_m2");
},600);
    });
	/*$('#m2 a.click').mouseleave(function() {
		 $('#u_m2').slideUp(400);
    });	*/
	
	
	
	$('#m3 a.click').click(function(e) {
		 e.preventDefault();
         $('#u_m3').slideDown(600);
		 setTimeout(function(){
           $("#m3 a.click").addClass("on_m3");
           },400);
    });
	
	$('#m3 a.on_m3').live('click', function() {
         $('#u_m3').slideUp(400);
		 
		 
		 setTimeout(function(){
     $("#m3 a.click").removeClass("on_m3");
},600);
    });
	/*$('#m3 a.click').mouseleave(function() {
		 $('#u_m3').slideUp(400);
    });*/	
	
	
	
	$('#m4 a.click').click(function(e) {
		 e.preventDefault();
         $('#u_m4').slideDown(600);
		 setTimeout(function(){
           $("#m4 a.click").addClass("on_m4");
           },400);
    });
	
	$('#m4 a.on_m4').live('click', function() {
         $('#u_m4').slideUp(400);
		 
		 
		 setTimeout(function(){
     $("#m4 a.click").removeClass("on_m4");
},600);
    });
	/*$('#m4 a.click').mouseleave(function() {
		 $('#u_m4').slideUp(400);
    });	*/
	
	
	
	$('#m5 a.click').click(function(e) {
		 e.preventDefault();
         $('#u_m5').slideDown(600);
		 setTimeout(function(){
           $("#m5 a.click").addClass("on_m5");
           },400);
    });
	
	$('#m5 a.on_m5').live('click', function() {
         $('#u_m5').slideUp(400);
		 
		 
		 setTimeout(function(){
     $("#m5 a.click").removeClass("on_m5");
},600);
    });
	
	/*$('#m5 a.click').mouseleave(function() {
		 $('#u_m5').slideUp(400);
    });*/
	
	
	$('#m6 a.click').click(function(e) {
		 e.preventDefault();
         $('#u_m6').slideDown(600);
		 setTimeout(function(){
           $("#m6 a.click").addClass("on_m6");
           },400);
    });
	
	$('#m6 a.on_m6').live('click', function() {
         $('#u_m6').slideUp(400);
		 
		 
		 setTimeout(function(){
     $("#m6 a.click").removeClass("on_m6");
},600);
    });
	
	/*$('#m6 a.click').mouseleave(function() {
		 $('#u_m6').slideUp(400);
    });*/	
	
	$('#m7 a.click').click(function(e) {
		 e.preventDefault();
         $('#u_m7').slideDown(600);
		 setTimeout(function(){
           $("#m7 a.click").addClass("on_m7");
           },400);
    });
	
	$('#m7 a.on_m7').live('click', function() {
         $('#u_m7').slideUp(400);
		 
		 
		 setTimeout(function(){
     $("#m7 a.click").removeClass("on_m7");
},600);
    });
	
	/*$('#m6 a.click').mouseleave(function() {
		 $('#u_m6').slideUp(400);
    });*/	
	
	
	$('#m8 a.click').click(function(e) {
		 e.preventDefault();
         $('#u_m8').slideDown(600);
		 setTimeout(function(){
           $("#m8 a.click").addClass("on_m8");
           },400);
    });
	
	$('#m7 a.on_m8').live('click', function() {
         $('#u_m8').slideUp(400);
		 
		 
		 setTimeout(function(){
     $("#m8 a.click").removeClass("on_m8");
},600);
    });
	
	/*$('#m6 a.click').mouseleave(function() {
		 $('#u_m6').slideUp(400);
    });*/			   
	
	
	
	
	$('#m_polibox a.click').click(function(e) {
		 e.preventDefault();
         $('#polibox_navigation').slideDown(600);
    });

	
	$('#main, #footer, #header').mouseenter(function() {
     $('#polibox_navigation').slideUp(400);
		 $('ul#lang').slideUp(400);
    });
	

	$("a.lang").mouseenter(function() {
         $('ul#lang').slideDown(600);
    });
	
	
	
	
	


//$('div.newsletter').load("form_newsletter.html");


$('#richiamami').click(function(e) {
		 e.preventDefault();
		 $('#wrapper_richiamami div').load('form_richiamami.html');
         $('#wrapper_richiamami').css('display','block');
    });	
	

	
	
	$('#wrapper_richiamami .chiudi').live('click', function(){
	 $('#wrapper_richiamami').css('display','none');
    });
	
	
	$('#form_richiamami').live('submit', function(){
	 $.post(  
            "http://www.polibox.com/invia_callme.php",  
            $("#form_richiamami").serialize(),  
            function(data){  
                $('#wrapper_richiamami div').load('sub_richiamami.html'); 
            }  
        );  
        return false; 
    });
	
	
	
	
/*$('div.newsletter a').click(function(e) {
		 e.preventDefault();
		 $('#wrapper_richiamami div').load('form_newsletter2.html');
         $('#wrapper_richiamami').css('display','block');
    });	
		
	
	
	
	
	$('#form_newsletter').live('submit', function(){
		
		if(!($('#check_p').is(':checked'))){
alert("Error!");
return false
}
		
	 $.post(  
            "http://www.polibox.com/invia_news.php",  
            $("#form_newsletter").serialize(),  
            function(data){  
                $('#wrapper_richiamami div').load('sub_newsletter.html'); 
            }  
        ); 
	
	
        return false; 
    });*/
	
	
	

	
	$('input').live('focus', function(){
	 $(this).val('');
    });
	
	
});	






function reorder(colonna) {
var obj = $('#col'+colonna+' div.index_news');
var count = obj.length;

for(var i=1; i<=count; i++) {
itA = $('#col'+colonna+' div.index_news:nth-child('+i+')');

rnd = rmax(count);
if(rnd==i) continue;

itB = $('#col'+colonna+' div.index_news:nth-child('+rnd+')');

var itAC = itA.clone(true);
var itBC = itB.clone(true);

itBC.insertAfter(itA);
itA.remove();

itAC.insertAfter(itB);
itB.remove();
}
}

function rmax(max){
var n = Math.round(Math.random()*max);
return n == 0 ? 1 : n;
}




function theRotator() {
	//Set the opacity of all images to 0
	$('div.rotator ul li').css({opacity: 0.0});
	$('div.rotator2 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});
	$('div.rotator2 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()',6000);
	setInterval('rotate2()',6000);
	
}

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

    if ( current.length == 0 ) current = $('div.rotator 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.rotator ul li:first') :current.next()) : $('div.rotator 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
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

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


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

    if ( current.length == 0 ) current = $('div.rotator2 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.rotator2 ul li:first') :current.next()) : $('div.rotator2 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
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

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