/*...........................................    

   General funciotns

...........................................*/	

jQuery.fn.toggleText = function(a, b) {
	return this.each(function() {
		jQuery(this).text(jQuery(this).text() == a ? b : a);
	});
};

jQuery.fn.equalHeights=function() {
	var maxHeight=0;
	this.each(function(){
		if (this.offsetHeight>maxHeight) {maxHeight=this.offsetHeight;}
	});
	this.each(function(){
		$(this).height(maxHeight + "px");
		if (this.offsetHeight>maxHeight) {
			$(this).height((maxHeight-(this.offsetHeight-maxHeight))+"px");
		}
	});
};

function menuOpen(){
		$("UL",this).slideDown("slow");
		var cover = $(this).attr("rel");
		var title = $(this).attr("title");
}

function menuClose(){
		$("UL",this).slideUp("slow");
}

function menuNothing(){
		
}

function imgscroll(direction,coeff){
		var size	= -(160*coeff);
		if (direction == "prev") var size = 0;
		$('.imgscroller').animate({marginLeft:size+"px"}, 1000);
}


$(document).ready(function(){



	$(document).pngFix(); 
	
	$(".home .sup TD").hoverIntent({
		sensitivity: 8, 
		interval: 40, 
		over: menuOpen, 
		timeout: 0, 
		out: menuClose
	});

	$(".insidemenu .menu").hoverIntent({
		sensitivity: 8, 
		interval: 40, 
		over: menuOpen, 
		timeout: 0, 
		out: menuClose
		//out: menuNothing
	});


	
	$(".inside").click(
		function () {
		  	$(".menu UL").slideUp("slow");
 		}
    );
	
	
 	$(".menu LI:has(A)").hover(
      function () {
        $(this).addClass("on");
      }, 
      function () {
        $(this).removeClass("on");
      }
    ).click(
		function () {
			var dest = $("A",this).attr("href");
		  	window.location.href = dest;
 		}
    );


//$(".catalogue").css("margin-left","-5px").find("A").prepend(". ");


/*...........................................    

   SlideShow Home

...........................................*/


 $('.slideshow').cycle({
		fx: 'fade',
		timeout: 10000,
		speed:  1200
	});


$(function() {

    //setInterval("slideSwitch()", 1500);

});


/*...........................................    

   Images

...........................................*/

	$(".moreimg").css("cursor","pointer").click(function(){
		var imgurl = $(this).attr('rel'); 
		$("#cover IMG").hide().attr("src", imgurl);
		$("#cover").addClass("loading");
		$("#cover IMG").fadeIn('slow');
	});

/*
	$(".moreimg.scroll").click(function(){	
		var kind = $(this).attr('title');
		var coeff	= 3
		var size	= -(160*coeff);
		if (kind == "prev") var size = 0;
		$('.imgscroller').animate({marginLeft:size+"px"}, 1000);
	});
*/

$(".gbox").click(function(){
	var imgurl = $(this).attr('rel');
	$('.col').toggle();
	$('.gboximg').addClass("loading").toggle();
	
});




/*...........................................    

   Structure

...........................................*/


//$(".sx, .dx").equalHeights();

$(".catalogue .sub, .dx").equalHeights();

/*
var csubh = $(".sub .col").height();
$(".sub").height(csubh);


*/

/*...........................................    

   news e varie

...........................................*/

$(".newsmenu").unbind();

$(".newsmenu").click(function(){
	$(".homenews").hide();
	var trigged  = $(this).attr("rel");
	$("#"+trigged+"").toggle('fast');
});



/*
$(".marchio").hover(function() {
  this.src = this.src.replace("_b","_a");
 }, function() {
  this.src = this.src.replace("_a","_b");
 });
*/

$(".trigger").click(function(){
	var trigged  = $(this).attr("rel");
	$("#"+trigged+"").toggle('fast');
});



/*...........................................    

   applicationform

...........................................*/

$(".requestform").click(function(){

//	var url = "/subscribe .subtest";

	$('#applicationform').slideToggle('slow');
/*
	$("#applicationform .desc")
	.css({
		minHeight: "400px",
		background: "transparent url('/img/loadingAnimation.gif') center 40px no-repeat"
	})
	.load(url)
	.ajaxComplete(function(){
		$(this).css("background-image","none");
	});
*/
	
});


	

	
	
	
	
	



	
});




