<!--

function FindPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
	while (obj = obj.offsetParent);
		var objPos = new Object();
		objPos.x = curleft;
		objPos.y = curtop;
		return objPos;
	}
}
function ShowCategory(org,ori) {
	sizes = new Array();
	sizes["land"] = Array('800x600','1024x768','1280x720','1280x768','1280x800','1600x960','1280x1024','1440x900','1680x1050','1600x1200','1920x720','1920x1080','1920x1200','1920x1440','2560x1440','2560x1600');
	sizes["port"] = Array('450x600','600x800','1200x1600');
	if (ori != "pano") {
		inp = document.getElementById(org);
		inp.objPos = FindPos(inp);
		inp.bOverlay = false;
		inp.setTimeShow;
		inp.setTimeHide;
		inp.obj = document.createElement('ul');
		inp.obj.id = inp.id+"s";
		inp.obj.className = inp.id;
		id = inp.id;
		//sizes = spec.split(",");
		for (m=0;m<sizes[ori].length;m++) {
			var listItem = document.createElement('li');
			var listLink = document.createElement('a');
			listLink.href = "javascript:void(0);";
			listLink.id = sizes[ori][m];
			sizp = sizes[ori][m].split("x");
			listLink.disp = sizp[0]+" x "+sizp[1];
			listLink.className = inp.id;
			listLink.numer = m;
			listLink.onclick = function() { 
				var newObj = document.getElementById(this.className); 
				var rezWidth = document.getElementById("rezw"); 
				var rezHeight = document.getElementById("rezh"); 
				var idim = this.id.split("x");
				rezWidth.value = idim[0];
				rezHeight.value = idim[1];
				newObj.value = idim[0]+" x "+idim[1];
				newObj.hide();
			}
			listLink.onmouseover = function() { 
				newObj = document.getElementById(this.className); 
				newObj.startShow();
			}
			listLink.onmouseout = function() { 
				var newObj = document.getElementById(this.className); 
				newObj.startHide();
			}
			var someText = document.createTextNode(listLink.disp);
			listLink.appendChild(someText);
			listItem.appendChild(listLink);
			inp.obj.appendChild(listItem);
		}
		inp.obj.style.top = '-600px';
					
		inp.prnt = document.getElementById(ori);
		inp.prnt.appendChild(inp.obj);
		inp.show = function() {
			var id = this.id;
			this.obj.style.left = this.objPos.x + 'px';
			this.obj.style.top = this.objPos.y + 3 + 'px';
			this.bOverlay = true;
		}
		inp.hide = function() {
			obj = document.getElementById(this.id+"s");
			this.bOverlay = false;
			obj.style.top = "-600px";
		}
		inp.startShow = function() {
			if(this.bOverlay) {
				clearTimeout(this.setTimeHide);
			} else {
				var id = this.id;
				this.setTimeShow = setTimeout("document.getElementById('"+id+"').show(this)",500);
			}
		}
		inp.startHide = function() {
			if(this.bOverlay) {
				var id = this.id;
				this.setTimeHide = setTimeout("document.getElementById('"+id+"').hide(this)",400);
			} else {
				clearTimeout(this.setTimeShow);
			}
		}
		inp.onclick = inp.show;
		inp.onmouseover = inp.startShow;
		inp.onmouseout = inp.startHide;
	}
}

function downloadIt() {
	var rezWidth = document.getElementById("rezw"); 
	var rezHeight = document.getElementById("rezh");
	var dwn = document.getElementById("download");
	if ((rezWidth.value == '')||(rezHeight.value == '')) {
		alert("Please select a resolution or specify a width and height in pixels.");
		dwn.blur();
	} else {
		$('#progress').css('display','block');
		window.location = location.href+"/"+rezWidth.value+"x"+rezHeight.value;
	}
}
function sendMessage() {
	if ($('#message').val() == "") {
		$('#commentbox').find('p').html('You must type in a message to send.');
	} else {
		var collect = {
			comment: $('#message').val()
		}
		$.post('/inc/sendMessage.php', collect, function(data){
	    	if(data.length > 0) {
	    		$('#commentbox').html(data+'<div class="clearBoth"></div>');
	    	}
	    });
	}
}
function clearfield(obj) {
	if (!obj.set) {
		obj.val = obj.value;
		obj.value = "";
		obj.set = true;
	} else {
		if ((obj.val)&&(obj.value == obj.val)) {
			obj.value = "";	
		}
	}
	$(obj).removeClass('watermarked');
}
function signUpNewsetter() {
	var address = $('#email').val();
	if ((address == "")||(address == "enter your email address")) {
		$('#newsbox > p.newsmsg').html('<b style="color:#090;">Please enter an email.</b>');
	} else {
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		if (reg.test(address) == false) {
			$('#newsbox > p.newsmsg').html('<b style="color:#090;">Please enter a valid email address.</b>');
		} else {
			var collect = {	email: address }
			$.post('/inc/signUpNewsletter.php', collect, function(data){
				if(data.length > 0) {
					$('#newsbox').html(data);
				}
			});
		}
	}
}
function ratePage(id,num,type) {
	$('#ratebox > div.starating > div').empty();
	var collect = { id: id, rating: num, type: type }
	$.post('/inc/ratepage.php', collect, function(data){
		if (data.length > 0) {
			var stars = data.split(':');
			$('#ratebox > div.starating > div').removeClass().addClass('star'+stars[0]);
			$('#ratenum').html("("+stars[1]+")");
			$('#ratemsg').html("You Voted!");
		}
	});
}

$(document).ready(function() {
	if ($('#wallpaper').length) {
		rezClass = $('#myRes').attr('class');
		$('#myRes').html("Your current screen resolution is <a href='/photo/"+rezClass+"/"+screen.width+"x"+screen.height+"'>"+screen.width+" x "+screen.height+"</a>");
		orient = $('body').attr('id');
		ShowCategory("wallpaper",orient);
	}
	if (($('#series').length)&&($('#current').length)) {
		pos = $('#default').position();
		$('#series').clone().appendTo('#current').removeClass('aro').addClass('series').css('left',pos.left).css('top',pos.top+2).attr('id','serieslist');
		$('#default').mouseover(function() { $('#serieslist').css('display','block');	});
		$('#default').mouseout(function() { $('#serieslist').css('display','none');	});
		$('#serieslist').mouseover(function() {	$(this).css('display','block');	});
		$('#serieslist').mouseout(function() { $(this).css('display','none'); });
	}
	//STAR RATING
	if ($('#ratebox').length) {
		var page = $('#ratebox').attr('class').substr(1);
		var type = $('#ratebox').attr('class').substr(0,1);
		collect = { id: page, type: type }
		$.get('/inc/getrating.php', collect, function(data){
			if (data.length > 0) {
				var stars = data.split(':');
				$('#ratebox > div.starating > div').removeClass().addClass('star'+stars[0]);
				$('#ratenum').html("("+stars[1]+")");
				if (stars[2] == 1) { $('#ratebox > div.starating > div').empty(); $('#ratemsg').html("You Voted!"); }
				var defclass = 'star'+stars[0];
				$('#ratebox > div.starating > div > a').each(function(){
					$(this).hover(
						function(){ $(this).parent('div').removeClass().addClass('star'+$(this).attr('rel')+'0'); },
						function(){ $(this).parent('div').removeClass().addClass(defclass); }
					);
				});	
			}
		});

	}
	var currentTime = new Date();
	var month = (currentTime.getMonth() < 9 ? '0' : '') + (currentTime.getMonth() + 1);
	var day = (currentTime.getDate() < 9 ? '0' : '') + (currentTime.getDate() + 1);
	var year = currentTime.getFullYear();
	var today = year+'-'+month+'-'+day;
	$('a').each(function() {
		if ($(this).attr('rel').length) {
			if ($(this).attr('rel') == 'external') {
				$(this).attr('target','_blank');
				if ($(this).parent().attr('id').length) {
					var theid = $(this).parent().attr('id');
				} else if ($(this).attr('id').length) {
					var theid = $(this).attr('id');
				} else {
					var theid = 'generic';
				}
				var href = $(this).attr('href');
				if (href.indexOf('http') == 0) {
					$(this).click(function() {
						var collect = {
							id: theid,
							date: today,
							url: href,
							page: $(location).attr('href')
						}
						$.post('/inc/trackit.php', collect);
					});
				} else if (href.indexOf('highres/') == 0) {
					$(this).click(function() {
						var collect = {
							id: theid,
							date: today
						}
						$.post('/inc/highres.php', collect);
					});
				}
			}
		}
	});
	// WATERMARKED FIELDS
	if ($('.special').length) {
		$('.special').each(function() {
			this.set = false;
			this.val = false;
			$(this).click(function() { clearfield(this); });
			$(this).focus(function() { clearfield(this); });
			$(this).keyup(function() {
				$(this).removeClass('watermarked');	
				this.set = true;
			});
			$(this).blur(function() {
				if (this.value == "") {
					if (this.val != false) {
						$(this).addClass('watermarked');
						this.value = this.val;
					}
				} else {
					if (this.val) {
						if (this.value == this.val) {
							$(this).addClass('watermarked');
						}
					}
				}
			});
		});
	}

});

//-->
