// JavaScript Document

var section;
var wallpaperNum;
var popupAttributes = 'toolbar=no,location=no,directories=no,status=yes,'+
	'menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,'+
	'width=864,height=600';

if (navigator.platform == "Win32" && 
	navigator.appName == "Microsoft Internet Explorer" && 
	window.attachEvent) {
	document.writeln('<style type="text/css">img, input.image { visibility:hidden; } </style>');
	window.attachEvent("onload", fnLoadPngs);
}

function popupWallpaper(size) {
	var url = 'wallpaper.php?size='+size+'&num='+wallpaperNum;
	window.open(url, 'wallpaper', popupAttributes);
}

function mouseOverThumbnail(num) {
	if(num != wallpaperNum || arguments[1]==1) {
		var id = 'wallpaper_thumb_'+num;
		var replacement = 'gs/wallpaper_thumb_'+num+'_on.png';
		findObj(id).src = replacement;
	}
}

function mouseOutThumbnail(num) {
	if(num != wallpaperNum || arguments[1]==1) {
		var id = 'wallpaper_thumb_'+num;
		var replacement = 'gs/wallpaper_thumb_'+num+'.png';
		findObj(id).src = replacement;
	}
}

function clickThumbnail(num) {
	if(wallpaperNum)
		mouseOutThumbnail(wallpaperNum, 1);
	mouseOverThumbnail(num, 1);
	wallpaperNum = num;
	var content = findObj('content');
	var url = 'gs/preview_wallpaper_'+num+'.jpg';
	content.style.backgroundImage = 'url('+url+')';
}



/**********************
*
*	UTILITY FUNCTIONS
*
***********************/

function preloadImages() {
	if(document.images) {
		if(!document.imageArray) 
			document.imageArray = new Array();
		var i,j = document.imageArray.length, args = preloadImages.arguments;
		for(i=0; i<args.length; i++) {
			if (args[i].indexOf("#")!=0) {
				document.imageArray[j] = new Image;
				document.imageArray[j++].src = args[i];
			}
		}
	}
}

function MM_swapImgRestore() { //v3.0
	var i,x,a=document.MM_sr; 
  	for(i=0; a&&i<a.length && (x=a[i]) && x.oSrc; i++) 
		x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
	var i, j=0 ,x ,a=MM_swapImage.arguments; 
	document.MM_sr=new Array; 
	for(i=0; i<(a.length-2); i+=3) {
		if ((x=findObj(a[i]))!=null) {
			document.MM_sr[j++]=x; 
			if(!x.oSrc) 
				x.oSrc=x.src; x.src=a[i+2];
		}
	}
}

function findObj(theObj, theDoc) {
  var p, i, foundObj;
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length){
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) 
  	foundObj = theDoc.all[theObj];
	
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
	
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
	
  if(!foundObj && document.getElementById)
  	foundObj = document.getElementById(theObj);
  return foundObj;
}


function fnLoadPngs() {
	var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
	var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5);

	for (var i = document.images.length - 1, img = null; (img = document.images[i]); i--) {
		if (itsAllGood && img.src.match(/\.png$/i) != null) {
			fnFixPng(img);
			img.attachEvent("onpropertychange", fnPropertyChanged);
		}
		img.style.visibility = "visible";
	}

	var nl = document.getElementsByTagName("INPUT");
	for (var i = nl.length - 1, e = null; (e = nl[i]); i--) {
		if (e.className && e.className.match(/\bimage\b/i) != null) {
			if (e.src.match(/\.png$/i) != null) {
				fnFixPng(e);
				e.attachEvent("onpropertychange", fnPropertyChanged);
			}
			e.style.visibility = "visible";
		}
	}
}

function fnPropertyChanged() {
	if (window.event.propertyName == "src") {
		var el = window.event.srcElement;
		if (!el.src.match(/x\.gif$/i)) {
			el.filters.item(0).src = el.src;
			el.src = "x.gif";
		}
	}
}

function fnFixPng(img) {
	var src = img.src;
	img.style.width = img.width + "px";
	img.style.height = img.height + "px";
	img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='scale')"
	img.src = "x.gif";
}