/*----------------------------------------*/  				  
/*----------------------------------------*/  				  
// jQuery
/*----------------------------------------*/  				  
/*----------------------------------------*/

$(document).ready(function() {
						   
/*----------------------------------------*/  				  
/*----------------------------------------*/  				  
// JQUERY Sandbox 
/*----------------------------------------*/  				  
/*----------------------------------------*/  				  




/*----------------------------------------*/  				  
/*----------------------------------------*/  				  
// End JQUERY Sandbox 
/*----------------------------------------*/  				  
/*----------------------------------------*/  		
$("a.swf, a.flv").each(function (a) {
$(this).media();
});

/*----------------------------------------*/  				  
// CONTENT MENU 
/*----------------------------------------*/  				  

$("#dLeftMenu .menuv li:last").css({'border-bottom-width': '0px'});


function initMenu() {
  $('#content-menu ul').hide();
  $('#content-menu li a').not('#content-menu ul li a').click(
    function() {
      var checkElement = $(this).next();
	  var position = {};
	$(this).position(position);
	var offset = $(this).width();
if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
        $('#content-menu ul:visible').slideUp('fast');
		return false;
        }
      if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
			if (position.left>=429) {
			$("#content-menu ul:visible").slideUp('fast');
			checkElement.css({left: position.left+offset-320}).fadeIn(800, function (a) {
			checkElement.find("ul").slideDown('slow');

					});
			}
			else {
			$("#content-menu ul:visible").slideUp('fast');
			checkElement.fadeIn(800, function (a) {
			checkElement.find("ul").slideDown('slow');
					});
			}
return false;
        }
      }
    );
  }
initMenu();

/*----------------------------------------*/  				  
// END CONTENT MENU 
/*----------------------------------------*/  				  

$(".send-to a").each(function (a) {
$(this).click(function () {
$("#send-to-expand").hide().removeShadow();
$("#send-to-expand .dropShadow").remove();
var position = {};
$(this).position(position);
$("#send-to-expand").css(position).fadeIn(500, function () {
	$("#send-to-expand").dropShadow({left:0,top:0});
})
});
});




$("img.thumb-img").each(function (a) {
$(this).wrapAll("<a class='thumb-img'></a>");
});

$("img.thumb-img-full").each(function (a) {
$(this).parent().addClass("thumb-img-full");
});

$("img.thumb-3d").each(function (a) {
$(this).parent().addClass("thumb-3d");
});

$("img.thumb-swf").each(function (a) {
$(this).parent().addClass("thumb-swf");
});

$("a.thumb-swf, a.thumb-3d, a.thumb-img-full").click(function (a) {
$("p#statecontent").remove();
var statecontent = $(this).parent().children(".statement").html();
if (!(statecontent=="&nbsp;" || statecontent==" " || statecontent==undefined)){
$("#shadowbox_statement").append("<p id='statecontent'>" + statecontent + "</p>");
}});

$("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;
});
});




$(".hidden-text .show-link").toggle(
	function () {
		$(this).parent().parent().children("*").each(function (i) {
				if ($(this).attr('class')!='show-link-bkg' || $(this).attr('class')==undefined){
				$(this).find("*").fadeIn("slow");
				$(this).fadeIn("slow");
				$(this).css({"display":"block"});
				}
			});
	},
	function () {
		$(this).parent().parent().children("*").each(function (i) {
			if ($(this).attr('class')!='show-link-bkg' || $(this).attr('class')==undefined){
			$(this).find("*").fadeOut("slow");
			$(this).fadeOut("slow");
			}
		});
	}					
);


/*----------------------------------------*/
/*----------------------------------------*/  
$("#ref-title").toggle(
		function () {		
$("#ref-list").fadeIn("slow");
//			$("#ref-title").addClass("closed").removeClass("opened");
//			$("#references").addClass("closed").removeClass("opened");
		},
		function () {		
//$("#ref-list").hide();
$("#ref-list").fadeOut("slow");

//			$("#ref-title").addClass("closed").removeClass("opened");
//			$("#references").addClass("closed").removeClass("opened");
		});	

$(".ref-link").click(
function () {		
$("#ref-list").fadeIn("slow");
		});

$(".ref-link").hover(
      function () {
$("#ref-layer, #ref-layer_dropShadow").remove();
var content= $("#ref_"+ $(this).html().replace("(","").replace(")","").replace("[","").replace("]","")).html();

/*Cut long url in layer*/
    regexp_pattern=/(http:[^\s\n\r\t]*)/ig;
    re = new RegExp(regexp_pattern)
    mymatch = re.exec(content)
	
    if (mymatch){
    myurl=mymatch[0]
    left_string=String(myurl).substring(0,20)
    //right_string=String(myurl).substring(myurl.length,myurl.length-5)
    new_url=left_string + '[...]'// + right_string
    content=content.replace(regexp_pattern,new_url)
    }
	
$("#content_container").append("<div id='ref-layer'><div id='ref-number'><span>"+ $(this).html() + "</span></div><p>" +content + "</p></div>");
var position = {};
$(this).position(position);

    if (findPos(this) [1]<=80){
    position.top=findPos(this) [1]-$("#ref-layer").height()+100;
    position.left=findPos(this) [0]-260;
    }
    if (findPos(this) [0]<=380){
    position.top=findPos(this) [1]-$("#ref-layer").height()-25;
    position.left=findPos(this) [0]+20;
    }
    else
    {
    position.top=findPos(this) [1]-$("#ref-layer").height()-25;
    position.left=findPos(this) [0]-220;
    }

//pay attention for possible visual bug with dropShadow function
$("#ref-layer").css(position).fadeIn(0, function () {
$("#ref-layer").dropShadow({left:0,top:0});
});
		}, 
      function () {
            $("#ref-layer, #ref-layer_dropShadow, .dropShadow").remove();
      }
    );

/*----------------------------------------*/
/*----------------------------------------*/  
$(".open_reference").each(function (a) {
$(this).click(function () {
$(".references").hide().removeShadow();
$(".item .dropShadow, .item-noCover .dropShadow, .downloads-cover .dropShadow").remove();
var position = {};
$(this).position(position);
position.top=position.top-$(this).parents(".item, .item-noCover, .downloads-cover").children(".references").height()+90;
position.left=position.left-$(this).parents(".item, .item-noCover, .downloads-cover").children(".references").width()+570;
$(this).parents(".item, .item-noCover, .downloads-cover").children(".references").css(position).fadeIn(500, function () {
$(this).parents(".item, .item-noCover, .downloads-cover").children(".references").css(position).dropShadow({left:0,top:0});
return false;
});
});
});

/*----------------------------------------*/
/*----------------------------------------*/  				  
// Country selector 
/*----------------------------------------*/  				  
/*----------------------------------------*/
$("#country-link").click(
function () {
$("#country-list").hide().removeShadow();
var position = {};
$(this).position(position);
position.top=position.top+$(this).height()+5;
position.left=position.left-40;
$("#country-list").css(position).fadeIn(500, function () {
						 $("#country-list").dropShadow({left:0,top:0});
					 });
//   $("#altrodivneltop").hide().removeShadow();
      return false;
}
);

/*----------------------------------------*/
/*----------------------------------------*/  				  
// Close links 
/*----------------------------------------*/  				  
/*----------------------------------------*/

$(".popup-content, .item .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;
});

$(".close-link").each(function (g) {
$(this).click(function () {
$(this).parent().hide().removeShadow();
$("#header").find(".dropShadow").remove();
						return false;
						})
});

/*----------------------------------------*/
//	Closing jQuery
/*----------------------------------------*/  

	});