/************************* img mngement ***************************************/
function im_preload( img_obj, img_src ) {
	if ( document.images ) {
		eval( img_obj + ' = new Image()' );
		eval( img_obj + '.src = "' + img_src + '"' );
	}
}
function img_change( layer, img_name, img_obj ) {
	if (img_init){
		if ( document.images ) {
			if ( document.layers && layer != null ) eval( 'document.layers["' + layer + '"].document.images["' + img_name + '"].src = ' + img_obj + '.src');
			else if (document.images[img_name]) document.images[ img_name ].src = eval( img_obj + ".src" );
		}
	}
}
function preload_img() {
	im_preload('m1_on','img/buttons/home-on.gif');
	im_preload('m1_off','img/buttons/home.gif');
	im_preload('m2_on','img/buttons/chronographs-on.gif');
	im_preload('m2_off','img/buttons/chronographs.gif');
	im_preload('m3_on','img/buttons/dress-on.gif');
	im_preload('m3_off','img/buttons/dress.gif');
	im_preload('m4_on','img/buttons/military-on.gif');
	im_preload('m4_off','img/buttons/military.gif');
	im_preload('m5_on','img/buttons/previously-on.gif');
	im_preload('m5_off','img/buttons/previously.gif');
	im_preload('m6_on','img/buttons/useful-on.gif');
	im_preload('m6_off','img/buttons/useful.gif');
	im_preload('m7_on','img/buttons/warranty-on.gif');
	im_preload('m7_off','img/buttons/warranty.gif');

	im_preload('m8_on','img/buttons/send_email_about_watch-on.gif');
	im_preload('m8_off','img/buttons/send_email_about_watch.gif');
	im_preload('m9_on','img/buttons/warranty-on.gif');
	im_preload('m9_off','img/buttons/warranty.gif');
	img_init = true;
}
preload_img();
function eventHandler(e){
	var targ;
	if (!e) var e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	if (targ.nodeType == 3) // defeat Safari bug
		targ = targ.parentNode;
	if (!targ.id) targ.id = targ.childNodes[0].id;
	if (e.type=="mouseover" || e.type=="focus")	img_change(null,targ.id,targ.id+'_on');
	else img_change(null,targ.id,targ.id+'_off');
}
function doLoad(){
 	for(i=1;document.getElementById("m"+i);i++){
		document.getElementById("m"+i).parentNode.onfocus = eventHandler;
		document.getElementById("m"+i).parentNode.onblur = eventHandler;
		document.getElementById("m"+i).parentNode.onmouseover = eventHandler;
		document.getElementById("m"+i).parentNode.onmouseout = eventHandler;
 	}
}
onload = doLoad;
/************************* DETAIL ***************************************/
var currentImg = "a";
function swapImg(par){
	document.getElementById("imgPreview").src = "img/admin/detail/"+imgID+par+"-normal.jpg";
	currentImg = par;
}
function openImg(){
	var centered_width = 0;
	var centered_height = 0;
	_width = screen.availWidth;
	_height = screen.availHeight;
	if (_width>476) centered_width = (_width-476)/2;
	if (_height>620) centered_height = (_height-620)/2;
	newwin = window.open("_image.php?imgId="+imgID+"&currentImg="+currentImg,"wokno","top="+centered_height+",left="+centered_width+",status=yes,scrollbars=auto,menubar=no,resizable=yes,width=494,height=670");
	newwin.focus();
}
// SPF: previously was width=476,height=620. Better: width=494,height=670

/************************* MISC ***************************************/
function openPopup(par){
	par = par.childNodes[0].src;
	par = par.substring(par.lastIndexOf("/")+1,par.length-4);
	par += "-full";
	var _width = 0;
	var _height = 0;
	var centered_width = 0;
	var centered_height = 0;
	_width = screen.availWidth;
	_height = screen.availHeight;
	if (_width>480) centered_width = (_width-480)/2;
	if (_height>480) centered_height = (_height-480)/2;
	newwin = window.open("popup.php?img="+par,"wokno","top="+centered_height+",left="+centered_width+",status=yes,scrollbars=auto,menubar=no,resizable=yes,width=480,height=480");
	newwin.focus();
}
/************************* MISC ***************************************/

