var	n = 6;
	na = 6;

if (document.images) {
	Img = new Array(n);
	 for(i=1; i<=n; i++) { Img[i] = new Image() };
	Img_r = new Array(n);
	 for(i=1; i<=na; i++) { Img_r[i] = new Image() };
	
	Img[1].src = "/img/menu1_1.gif";
	Img[2].src = "/img/menu1_2.gif";
	Img[3].src = "/img/menu1_3.gif";
	Img[4].src = "/img/menu1_4.gif";
	Img[5].src = "/img/menu1_5.gif";
	Img[6].src = "/img/menu1_6.gif";
 	
	Img_r[1].src = "/img/menu1_1r.gif";
	Img_r[2].src = "/img/menu1_2r.gif";
	Img_r[3].src = "/img/menu1_3r.gif";
	Img_r[4].src = "/img/menu1_4r.gif";
	Img_r[5].src = "/img/menu1_5r.gif";
	Img_r[6].src = "/img/menu1_6r.gif";
	
}

function imgover(trg,imgname) {
	if (document.images[trg]) {
	 document.images[trg].src=Img_r[imgname].src;
	}
}
  
function imgout(trg,imgname)  {
	if (document.images[trg]) {
	 	document.images[trg].src=Img[imgname].src; 
	}
}
function gif_over(src) {
	src.children.tags('IMG')[0].src=src.children.tags('IMG')[0].src.replace('.gif','r.gif');
}
   
function gif_out(src) {
	src.children.tags('IMG')[0].src=src.children.tags('IMG')[0].src.replace('r.gif','.gif');
}

window.onresize=___getPageSize;


$(document).ready(function(){
    $(".openPopup").click(function(){
        var info_id = $(this).attr("href").substr(1)-0;
        openPopup($(this),info_id,1);
        return false;
    });
    
	$(document).keypress(function(e){
		if(e.keyCode==27){
			closePopup();
		}
	});
});

function openPopup(obj,info_id,show) {
    var url = "/show_file/db/?id="+info_id+"&rand="+Math.random();
    var insert_div = '<div id="popup_all"><div id="popup"><img src="/img/preloader.gif" width="103" height="24" alt="" onclick="closePopup();" /></div></div><div id="backgroundPopup" style="display:none; position:absolute; height:100%; width:100%; top:0; left:0; background:#000000; z-index:50;" onclick="closePopup();"></div>';
    if(show){
        $("body").append(insert_div);
        centerPopup();
    	$("#popup_all").fadeIn("fast");
    	$("#popup").fadeIn("fast");
        $("#backgroundPopup").css({
    	   "opacity": "0.7"
    	});
        $("#backgroundPopup").fadeIn("fast");
    }else{
        $("#popup").html('<img src="/img/preloader.gif" width="103" height="24" alt="" />');
        centerPopup();
        //return false;
    }
    $("#popup").load(url,function(){
        centerPopup();
        if($("#player").html() != null){
            flowplayer("player", "/img/flash/flowplayer-3.1.1.swf", { clip: { autoPlay:true } } );
        }
        $("#close").css("display","block");
    });
}

function closePopup() {
	$("#popup_all").fadeOut("fast",function(){
	   $("#popup_all").remove();
	   $("#popup").remove();
	});
    $("#backgroundPopup").fadeOut("fast",function(){
	   $("#backgroundPopup").remove();
	});
}

function navPopup(info_id){
    $("#close").css("display","none");
    openPopup("",info_id,0)
}

function ___getPageSize() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else {
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { 
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { 
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
};


function centerPopup(){
    $("#popup").css("width",$("#pic_content").width());
    $("#title").css("width",$("#pic_content").width());
    $("#bottom_popup").css("width",$("#pic_content").width());
	var popupHeight = $("#popup").height();
	var popupWidth = $("#popup").width();
	$("#popup").css({
        "margin-top": -popupHeight/2,
		"margin-left": -popupWidth/2
	});	
    var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var arrPageSizes = ___getPageSize();
	$("#backgroundPopup").css({
		width:arrPageSizes[0],
		height:arrPageSizes[1]
	});
}