function openPopup(file, w, h){
	try{if(newWin.closed==false) newWin.close();}catch(e){}
	var left = Math.floor((screen.width-w)/2);
	var top = Math.floor((screen.height-h)/2);
	var setting="location=no,menubar=no,resizable=no,scrollbars=yes,toolbar=no,width="+w+",height="+h+",top="+top+",left="+left;
	newWin=window.open(file, 'popUp', setting);
	newWin.focus();
}
function xId(id){return document.getElementById(id)}
function addEvent(elm, evType, fnc, useCapture){if(elm.addEventListener){elm.addEventListener(evType, fnc, useCapture);return true;}else if(elm.attachEvent){var r=elm.attachEvent('on'+evType, fnc);return r;}else{elm['on'+evType]=fnc;}}
function preloadImages(){
	var d=document;
	if(d.images){
		d.tmp = new Array();
		for(i=0; i<arguments.length; i++){
			d.tmp[i]=new Image;
			d.tmp[i].src=arguments[i];
		}
	}
}
function getExtension(v){
	return v.substring(v.lastIndexOf(".")+1, v.length);	
}
function writeSWF(fileName, w, h, bgColor, flashVars, wr) { 
	if(bgColor=="") bgColor = "#FFFFFF";
	var id = fileName.replace(".swf", "");
	var str = '';
	str += '<object width="'+w+'" height="'+h+'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http:\/\/download.macromedia.com\/pub\/shockwave\/cabs\/flash\/swflash.cab#version=8,0,0,0" id="' + id + '">';
	if (flashVars != "") str += '<param name="flashVars" value="'+flashVars+'">';
	str += '<param name="movie" value="'+fileName+'">';
	if (bgColor == "transparent") {
		str += '<param name="wmode" value="transparent">';
	} else {
		str += '<param name="bgcolor" value="'+bgColor+'">';
	}
	str += '<param name="allowScriptAccess" value="sameDomain">';
	str += '<param name="quality" value="high">';
	str += '<param name="scale" value="exactfit">';
	str += '<param name="id" value="index">';
	str += '<param name="align" value="">';
	str += '<param name="hspace" value="0">';
	str += '<param name="vspace" value="0">';
	str += '<param name="menu" value="false">';
	str += '<embed src="'+fileName+'" ';
	if (flashVars != "") str += 'flashVars="'+flashVars+'" ';
	str += 'width="'+w+'" height="'+h+'" ';
	if (bgColor == "transparent") {
		str += 'wmode="transparent" ';
	} else {
		str += 'bgcolor="'+bgColor+'" ';
	}
	str += 'quality="high" menu="false" type="application\/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" id="e_' + id + '"><\/embed>';
	str += '<\/object>';
	if (wr === false) {
		return str;
	} else {
		document.write(str);
	}
}
function getObjInfo(obj){
	oLeft = oTop = 0;
	oTag = obj;
	do {
		oLeft += oTag.offsetLeft;
		oTop += oTag.offsetTop;
		oTag = oTag.offsetParent;
	} while (oTag.tagName != "BODY" && oTag.tagName != "HTML");
	oWidth = obj.offsetWidth;
	oHeight = obj.offsetHeight;
	if (isNaN(oWidth) || isNaN(oHeight)) {
		oWidth = parseInt(obj.style.width);
		oHeight = parseInt(obj.style.height);
	}
	return {
		left	: oLeft,
		top		: oTop,
		width	: oWidth,
		height	: oHeight
		
	}
}


function bgOn(img) {
	img.style.opacity = "0.9";
	img.style.khtmlOpacity = "0.9";
}

function bgOut(img) {
	img.style.opacity = "0.7";
	img.style.khtmlOpacity = "0.7";
}


var tmpLeft, tmpWidth, intervalId, evX, dir, doSlide;
function pgStart(obj, ev) {
	var v = getObjInfo(obj);
	tmpLeft = v.left;
	tmpWidth = v.width;
	evX = ev.clientX;

	var x = evX - tmpLeft;
	if (x < tmpWidth / 2) {
		dir = "left";
	} else {
		dir = "right";
	}
	doSlide = true;
	intervalId = setInterval("pgSlide()", 10);
}

function pgStop() {
	 clearInterval(intervalId);
}
function pgUpdate(ev) {
	evX = ev.clientX;
	var x = evX - tmpLeft;
	if (x < tmpWidth / 2) {
		dir = "left";
	} else {
		dir = "right";
	}
	if (x < 250 || x > (tmpWidth - 250)) {
		doSlide = true;
	} else {
		doSlide = false;
	}
}
function pgSlide() {
	if (!doSlide) return;
	div = xId("pg_slider");
	if (dir == "right") {
		var s = 3;
		cx = parseInt(div.style.left);
		if (isNaN(cx)) cx = 0;
		if (Math.abs(cx - s) + 884 > parseInt(div.style.width)) {
			if (parseInt(div.style.width) > tmpWidth) div.style.left = - (parseInt(div.style.width) - 884) + "px";
		} else {
			div.style.left = (cx - s) + "px";
		}
	} else {
		var s = 3;
		cx = parseInt(div.style.left);
		if (isNaN(cx)) cx = 0;
		if (cx >= 0) {
			div.style.left = "0px";
		} else {
			div.style.left = (cx + s) + "px";
		}
	}
}



function showImage(img) {
	mainDiv = document.getElementsByTagName("div")[0];

	mainDiv.style.opacity = "0.7";
	mainDiv.style.mozOpacity = "0.7";
	mainDiv.style.khtmlOpacity = "0.7";
	mainDiv.style.filter = "alpha(opacity=70)";

	var xi = tmpLeft + tmpWidth / 2 - 50;
	var yi = 220;
	xId("imgLoader").style.left = xi + "px";
	xId("imgLoader").style.top = yi + "px";
	xId("imgLoader").style.display = "block";

	var i = new Image();
	i.onload = function() {
		xId("imgLoader").style.display = "none";
		mainDiv.style.background = "url(" + this.src + ") center top no-repeat #cccccc";
		mainDiv.style.opacity = "1";
		mainDiv.style.mozOpacity = "1";
		mainDiv.style.khtmlOpacity = "1";
		mainDiv.style.filter = "alpha(opacity=100)";
	}
	i.src = "/files/" + img;
}
