

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

   gianni box

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



jQuery.fn.gianniBox = function(modclass) {
	
	if (modclass == "multimedia") {
		var url = "/pages/getMedia/" + $(this).attr("rel");
		
		var type = $(this).attr("alt");
		
		
	} else {
		var url =  $(this).attr("rel");
	}
	
	
	/*if (typeof(url) != "undefined") {
		
		if (!$('.modal').is(":visible")) {
			//alert(url);
			$("BODY").append("<div id="+type+" class='modal "+modclass+"'><a class='modalclose up'>&nbsp;</a><div class='modalcontent'></div><a class='modalclose bottom'>&nbsp;</a></div>");
		} 

		
	}*/	
		$(".centerInt").html("").css({
			background: "url('/img/loadingAnimation.gif') 300px 100px no-repeat"
		})
		.load(url)
		.ajaxComplete(function(){
			$(this).css("background-image","none");
			$(".flashcontent").css({'display':'none'});
			var dida = $(".dida").text();
			$(".didaImg").html(dida);
			$(".dida").hide();
		 	$(".didaImg").show();
			/*
			$('<param name="wmode" value="opaque" />').prependTo('object');
			$('embed').attr('wmode', 'opaque');
			*/
		});
		
		$(".modalclose").click(function(){
			$(".flashcontent").css({'display':'block'});
			$(".modal").remove();
		});

}

jQuery.fn.gianniBoxModal = function(modclass) {
	
	if (modclass == "multimedia") {
		var url = "/pages/getMedia/" + $(this).attr("rel");
		
		var type = $(this).attr("alt");
		
	} else if (modclass == "mymailto") {
		var url = "/pages/mymailto/" + $(this).attr("rel");
		
	} else {
		var url =  $(this).attr("rel");
	}
	
	
	if (typeof(url) != "undefined") {	
		if (!$('.modal').is(":visible")) {
			//alert(url);
			$("BODY").append("<div class='overlay'></div><div id="+type+" class='modal "+modclass+"'><div class='modalcontent'></div></div>");
			var heightM = $(document).height();
			$(".overlay").height(heightM);
			
			
			$(".modalclose, .overlay").click(function(){
				$(".flashcontent").css({'display':'block'});
				$(".modal, .overlay").remove();
			});
			
		} 
	}	
	
	$(".overlay").fadeTo(0.5, 0.8);
	$(".modalcontent").html("").css({
		background: "#FFF url('/img/LoadingAnimationWhite.gif') center 135px no-repeat"
	})
	.load(url)
	.ajaxComplete(function(){
		$(this).css("background-image","none");
		$(".flashcontent").css({'display':'none'});
		var heightM = $(document).height();
		$(".overlay").height(heightM);
		$(".modalclose").click(function(){
			$(".flashcontent").css({'display':'block'});
			$(".modal, .overlay").remove();
		});
	});
		

}


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

   General functions

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

$(document).ready(function(){
	
	//advanced typography settings
	
	$('.content P').next('H1, H2, H3').css('padding-top', '1.25em');
	$('.content UL').next('H1, H2, H3').css('padding-top', '1.25em');
	
	$('H1, H2, H3').next('P').css('text-indent', '0');
	$(".content P:first").css("text-indent", "0");
	
	$('IMG').parent().css('text-indent', '0');
		
	/*var alto = $("#centro").height();
	$(".main").css({"height":alto+"px"});*/
		
	$(".open").click(function () {
		var who = $(this).next();
		$(who).slideToggle('normal');
		$(".open").next().not(who).slideUp('normal');
		
    });
	

	
	
	
	$(".imgHome").hover(
	
      function () {
        $(".didaHome", this).show();
      }, 
      function () {
        $(".didaHome", this).hide();
      }
    );
	
	$(".submenu").hover(
      function () {
	  	$(this).addClass("focused");
        $(".center, .centerInt").css({
			"z-index":"50"
		});
      }, 
      function () {
	  	$(this).removeClass("focused");
        $(".center, .centerInt").css({
			"z-index":"100"
		});
      }
    );
	
	$(".center, .centerInt").mouseover(function () {
		$(this).css({
			"z-index":"100"
		});
		
    });

	/*$(".accessori").mouseover(function(){
		$(".center, .centerInt").css({
			"z-index":"100"
		});
	});*/
	
	

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

   inline images

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

$(".multimediacontainer").not(':has(.flash)').each(function(i){

	var id = $(this).attr("id");

	//innesta l'imamgine prima del paragrafo successivo
	//$("A[rel='"+id+"']").not('.wimage').parents("P").next("P").before(mitem);
	
	//alternativa: innesta l'imamgine subito dopo il paragrafo preceente l'ancoraggio
	//$("A[rel='"+id+"']").not('.wimage').parents("P").after(mitem);
	
	//alternativa: innesta l'imamgine subito dopo l'ancoraggio
	$("A[title='"+id+"']:first").after(this);
		
});
	
	


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

   gianni box

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


$(".gbox").click(function(){
		$(this).gianniBox("multimedia");

		$(".didaImg").hide();
	
		$(".centerInt").css({
			"z-index":"100"
		});
});

$(".gboxM").click(function(){
		
		
		$(this).gianniBoxModal("multimedia");
		
		var position = $(this).position();
		var positionTop = ((position.top)+10)+"px";
		$(".modal").css({'margin-top':''+positionTop+''});
		

});




	
});

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

   jQuery Cookie

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


jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        var path = options.path ? '; path=' + options.path : '';
        var domain = options.domain ? '; domain=' + options.domain : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

