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

   gianni box

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



jQuery.fn.gianniBox = 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+"'><a class='modalclose up'>x close</a><div class='modalcontent'></div><a class='modalclose bottom'>&nbsp;</a></div>");
		} 
		
		/*$(".modal").draggable({
			handle : ".modalhandle"
		});*/
		
		
		
	}	
	
		$(".overlay").fadeTo(0.5, 0.8);
		$(".modalcontent").html("").css({
			background: "#FFF url('/img/ajax-loader.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, .overlay").click(function(){
			$(".flashcontent").css({'display':'block'});
			$(".modal, .overlay").remove();
		});

}



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

   jScrollPane

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



function scroller() {	
/* determina la dimensione del div contenitore in base alla somma degli elementi contanuti */
var sum=0;
$('.container UL LI').each( function(){ sum += $(this).width(); });
$('.container UL').width( sum + 10 );


var pane = $('.scroll-pane');
$('.scroll-pane').jScrollPane(
		{
			showArrows: true,
			//reinitialiseOnImageLoad: true,
			animateScroll: true,
			horizontalGutter: 30,
			verticalGutter: 30
			/*horizontalDragMinWidth: 183,
			horizontalDragMaxWidth: 183*/
		}
		
	);

//$("<div id='buttons'><a class='prev' href='#'></a><a class='next' href='#'></a></div>").prependTo(".jspDrag");

var api = pane.data('jsp');

	$('.next').bind(
		'click',
		function()
		{
			// Note, there is also scrollToX and scrollToY methods if you only
			// want to scroll in one dimension
			api.scrollByX(910);
			return false;
		}
	);
	
	$('.prev').bind(
		'click',
		function()
		{
			// Note, there is also scrollToX and scrollToY methods if you only
			// want to scroll in one dimension
			api.scrollByX(-910);
			return false;
		}
	);


}



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

   Do Something!

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

$(document).ready(function(){

$(".note").click(function(){
	$(".note").detach();
	$(".overnote").remove();
	
});

var remove = $(".note").detach();
$(".takeDisc").click(function(){
	
	remove.appendTo("body");
	$("body").append("<div class='overnote'></div>");
	$(".overnote").fadeTo(0.5, 0.8);
	
	$(".overnote").click(function(){
		$(".note").detach();
		$(".overnote").remove();
	});
	
});





/* determina la dimensione del div contenitore in base alla somma degli elementi contanuti */
var sum=0;
$('.container UL LI').each( function(){ sum += $(this).width(); });
$('.container UL').width( sum + 10 );

/*$('.container UL LI IMG').each(function(index) {
    //alert($(this).height());
	if ($(".container UL").height() > $(".container").height()) {
		$(".container").height($(this).height()+20);
	}
 })*/

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

//scroller();

});

$(window).load(function(){
	$(".container").width($(window).width());
 	
 	// iPad detection
 	var browser = navigator.userAgent;
 	if (browser.match(/iPad/i)) {
 		$('.container').jScrollTouch();
	}else{
		scroller();
	}
 	
 	
 	
});


if($.browser.msie){

    $(document).ready(function(){
	$(window).resize( function () { 
	 //scroller();
		}).trigger("resize"); 
	});
   }else{
      $(window).resize(function() {
		 // iPad detection
	 	var browser = navigator.userAgent;
	 	if (browser.match(/iPad/i)) {
	 		$('.container').jScrollTouch();
		}else{
			scroller();
		}
	});
 }




/*
// scroll
jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
return -c * ((t=t/d-1)*t*t*t - 1) + b;
};

jQuery(function( $ ){

	$('.container').serialScroll({
		items:'li',
		prev:'.prev',
		next:'.next',
		//offset:-230, //when scrolling to photo, stop 230 before reaching it (from the left)
		start:0, //as we are centering it, start at the 2nd
		duration:1200,
		force:true,
		stop:true,
		lock:false,
		cycle:false, //don't pull back once you reach the end
		easing:'easeOutQuart', //use this easing equation for a funny effect
		jump: false //click on the images to scroll to them
	});
	

});

*/

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

   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;
    }
};



