function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
	do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
			} while (obj = obj.offsetParent);
			
			
			//alert(curleft)
			return [curleft,curtop];
}
}

/*----------------------------------------*/  				  
/*----------------------------------------*/  				  
// jQuery
/*----------------------------------------*/  				  
/*----------------------------------------*/

$(document).ready(function() {
						   
/*----------------------------------------*/  				  
/*----------------------------------------*/  				  
// JQUERY Sandbox 
/*----------------------------------------*/  				  
/*----------------------------------------*/  				  

/*
$("div#menuh ul:first-child").each(function (a) {
$(this).addClass("content-menu");
});
*/

$("div#menuv li a.selected, .intlk-line").each(function (a) {
$(this).append("<small><small>*</small></small>");
});

//$("h3").each(function () {
//var testo = $(this).text();
//if( testo == "General Questions") {$(this).hide();}
//});

/*----------------------------------------*/  				  
/*----------------------------------------*/  				  
// End JQUERY Sandbox 
/*----------------------------------------*/  				  
/*----------------------------------------*/  


$("a.swf, a.flv").each(function (b) {
$(this).media();
});
$("#survey input:text").addClass("text");

$("#send").toggle(
        function () {
            $("#send_container").show();
        },
        function () {
            $("#send_container").hide();
        }
    );

/*----------------------------------------*/  				  
// CONTENT MENU 
/*----------------------------------------*/  				     
initMenu();    
    
function initMenu() {
    $('.content-menu ul').hide();
    $('.content-menu li').not('.content-menu ul li').hover(
        function() {
            $(this).children('ul').show();
        }, 
        function () {
            $(this).children('ul').hide();
        }
    );
};  
/*----------------------------------------*/  				  
// END CONTENT MENU 
/*----------------------------------------*/

/*----------------------------------------*/  				  
// Image block with pop-up 
/*----------------------------------------*/  				  

$("img.thumb-img").each(function (a) {
$(this).wrapAll("<a class='thumb-img'></a>");
});

$("a.thumb-img").each(function (a) {
$(this).click(function () {
$(".popup-content").hide().removeShadow();
$(".popup-content .dropShadow").remove();
var position = {};
$(this).position(position);

    if (findPos(this) [0]<=380){
position.top=findPos(this) [1]-270;
    position.left=findPos(this) [0]+70;
    }
    else
    {
position.top=findPos(this) [1]-200;
position.left=findPos(this) [0]-$(this).width()-210;
    }
$(this).parent().children(".popup-content").css(position).fadeIn(500, function () {
	$(this).parent().children(".popup-content").dropShadow({left:0,top:0});
})
return false;
});
});

$(".popup-content, .item-inside .references, .item-noCover .references, .downloads-cover .references, div.image").click(
function () {
   $(this).hide().removeShadow();
   $(this).parent().children().find(".dropShadow").remove();
   $(this).parent().find(".dropShadow").remove();
  $(".popup-larger-gallery, .popup-text").find(".dropShadow").remove();
return false;
});

/*----------------------------------------*/  				  
// END Image block with pop-up 
/*----------------------------------------*/  				  

/*----------------------------------------*/  				  
// CLOSE 
/*----------------------------------------*/  				  

$(".close-link").each(function (c) {
$(this).click(function () {
$(this).parent().hide().removeShadow();
$("#header").find(".dropShadow").remove();
						return false;
						})
});
/*----------------------------------------*/  				  
// CLOSE 
/*----------------------------------------*/  				  


/*----------------------------------------*/  				  
// REFERENCES 
/*----------------------------------------*/  				  

$("#ref-title").toggle(
		function () {		
$("#ref-list").fadeIn("slow");
		},
		function () {		
$("#ref-list").fadeOut("slow");
		});	
/*----------------------------------------*/  				  
$(".ref-link").click(
function () {		
$("#ref-list").fadeIn("slow");
		});
/*----------------------------------------*/  				  
$(".ref-link").hover(
      function () {
$("#ref-layer, #ref-layer_dropShadow, .dropShadow").remove();
var content= $("#ref_"+ $(this).html().replace("(","").replace(")","").replace("[","").replace("]","")).html();
$(".item-detail").append("<div id='ref-layer'><div id='ref-number'><span>"+ $(this).html() + "</span></div><p>" +content + "</p></div>");
var position = {};
$(this).position(position);
//    if (position.left<=80){
//    position.top=position.top-$("#ref-layer").height()-20;
//    position.left=position.left+20;
//    }
//    if (position.left<=380){
//    position.top=position.top-$("#ref-layer").height()-20;
//    position.left=position.left+20;
//    }
//    else
//    {
    position.top=position.top-$("#ref-layer").height()-20;
    position.left=position.left+20;
//    }
	
//pay attention for possible visual bug with dropShadow function
$("#ref-layer").css(position).fadeIn(500, function () {
	$("#ref-layer").dropShadow({left:0,top:0});
})
		}, 
      function () {
            $("#ref-layer, #ref-layer_dropShadow, .dropShadow").remove();
      }
    );


/*----------------------------------------*/  				  
// END REFERENCES 
/*----------------------------------------*/  				  

/*----------------------------------------*/  				  
// HIDDEN TEXT 
/*----------------------------------------*/  				  

//$(".hidden-text2 .shlk").toggle(
//	function () {
//$(this).parent().css({"margin-bottom":"10px"});
//				$(this).parent().parent().children("*").each(function (i) {
//				if ($(this).attr('class')!='shlk-bkg' || $(this).attr('class')==undefined){
//				$(this).find("*").fadeIn("slow");
//				$(this).fadeIn("slow");
//				$(this).css({"display":"block"});
//								
//$(".ill-center, .ill-lf, .ill-rg").each(function (d) {
//var widthImg = $(this).children(".illustration").width();
//$(this).width(widthImg);});
//
//}
//});
//	},
//	function () {
//
//		$(this).parent().parent().children("*").each(function (i) {
//			if ($(this).attr('class')!='shlk-bkg' || $(this).attr('class')==undefined){
//			$(this).find("*").remove(".remove").fadeOut("slow");
//			$(this).slideUp('fast').fadeOut("slow");
//			};
//			$(this).parent().children(".shlk-bkg").css({"margin-bottom":"0px"});
//		});
//	}					
//);

$(".hidden-text, .hidden-text2, .hidden-text3").append("<div class='close-ht'><span>Close</span></div>");

$(".hidden-text .shlk, .hidden-text2 .shlk, .hidden-text3 .shlk").click(
	function () {
$(this).addClass('opened');
$(this).parent().css({"margin-bottom":"10px"});
				$(this).parent().parent().children("*").each(function (i) {
				$(this).find("*").fadeIn("slow");
				$(this).fadeIn("slow");
				$(this).css({"display":"block"});
				
//$(".ill-center, .ill-lf, .ill-rg").each(function (d) {
//var widthImg = $(this).children(".illustration").width();
//$(this).width(widthImg);});
});
});

$(".close-ht").click(
	function () {
$(this).parent().children("*").not(".shlk, .shlk-bkg").slideUp('fast');
$(this).parent().children(".shlk-bkg").find("a").removeClass('opened');
$(this).parent().children(".shlk-bkg").css({"margin-bottom":"0px"});
});
/*----------------------------------------*/  				  
// ILLUSTRATIONS 
/*----------------------------------------*/  				  

//$(".ill-center, .ill-lf, .ill-rg").each(function (d) {
//var widthImg = $(this).children(".illustration").width();
//$(this).width(widthImg);
//});

/*----------------------------------------*/  				  
// Calendar 
/*----------------------------------------*/  				  

$("#calendar td a").each(function (a) {
	var bianco = "color: White;";		
	var code = $(this).attr("style");		
	if (code == bianco) {
$(this).parent().addClass("selected");
$(this).parent().css({"background-color":"#fbe7b6"});
	}
});

$("#calendar td").each(function (a) {
	var verde1 = "border: 1px solid White; color: rgb(143, 175, 143); background-color: rgb(229, 238, 245); width: 14%;";
	var verde2 = "border: 1px solid White; background-color: rgb(229, 238, 245); width: 14%;";
	var code = $(this).attr("style");		
	if (code == verde1) {
$(this).addClass("verde");
	}
		if (code == verde2) {
$(this).addClass("verde");
	}
});

/*----------------------------------------*/
//	Tabs
/*----------------------------------------*/  

var deftab = $("#events-box2").html();
$("#selected-box").html(deftab);


$("#tabs-index li a.show").click(function (a) {
var code = $(this).parent("li").children("div").html();
$(this).parent().parent("ul").find("li").removeClass("selected");
$(this).parent("li").addClass("selected");
$("#selected-box").html(code);
});


/*----------------------------------------*/
//	Closing jQuery
/*----------------------------------------*/  

	});