function viewImage(src, title){
	if (!document.getElementById('jscontainer')) document.body.innerHTML += '<div id="jscontainer"></div>';
	document.getElementById('jscontainer').innerHTML = '<div onclick="closeImage()" id="overlay"></div><div id="lightbox"><div id="outerImageContainer"><div id="imageContainer"><img src="/images/px.gif" id="lightboxImage"><div id="loading"><a href="#" id="loadingLink"><img src="/images/loading.gif"></a></div></div></div><div id="imageDataContainer"><div id="imageData"><div id="imageDetails"><span id="caption">' +title + '</span></div><div id="bottomNav"><a onclick="closeImage()" id="bottomNavClose"><img src="/images/closelabel.gif"></a></div></div></div>';
	overlay();
	if (document.images)
	{
		if (document.getElementById('htmli').scrollTop>0){
			st = document.getElementById('htmli').scrollTop;
		}else{
			st = document.body.scrollTop;
		}
		document.getElementById('lightbox').style.top = (st+100) + 'px';
		preload_image_object = new Image();
	   	preload_image_object.src = src;
		if (preload_image_object.width){
			ts();
		}else{
			preload_image_object.onload = ts;
		}
	}
}
function closeImage(){
	if (document.getElementById('jscontainer')){
		document.getElementById('jscontainer').innerHTML = '';
	}
}
function ts(){
	if (document.getElementById('htmli').scrollTop>0){
		st = document.getElementById('htmli').scrollTop;
	}else{
		st = document.body.scrollTop;
	}
	document.getElementById('loading').style.display = 'none';
	document.getElementById('outerImageContainer').style.width = (preload_image_object.width + 20) + 'px';
	document.getElementById('outerImageContainer').style.height = (preload_image_object.height + 20) + 'px';
	document.getElementById('imageDataContainer').style.width = (preload_image_object.width + 20) + 'px';
	document.getElementById('lightboxImage').src = preload_image_object.src;
	document.getElementById('lightbox').style.top = (st+100) + 'px';
	overlay();
}
function overlay(){
	if (window.innerWidth){
		document.getElementById('overlay').style.width=(window.innerWidth)+'px';
		document.getElementById('overlay').style.height=document.getElementById('htmli').scrollHeight+'px';
	}else{
		document.getElementById('overlay').style.width=(document.body.clientWidth)+'px';
		document.getElementById('overlay').style.height=document.getElementById('htmli').scrollHeight+'px';
	}
}

function scrimg(hg){
	if (document.getElementById('productI')){
		if (hg>550){
			cfh = hg-550+335;
		}else{
			cfh = 275;
		}
		if (document.getElementById('htmli').scrollTop>0){
			st = document.getElementById('htmli').scrollTop;
		}else{
			st = document.body.scrollTop;
		}
		if (st>(cfh+20)){
			document.getElementById('productI').style.marginTop = st-cfh + 'px';
		}else{
			document.getElementById('productI').style.marginTop = 20 + 'px';
		}
	}
}

$(document).ready(function() {
	$('#login').focus(function() {
		if (this.value == this.defaultValue) this.value = '';
		if(this.value != this.defaultValue) this.select();
	});
	$('#login').blur(function() {
  		if ($.trim(this.value) == '') this.value = (this.defaultValue ? this.defaultValue : '');
	});
	$('#pass').focus(function() {
		if (this.value == this.defaultValue){
			this.value = '';
			this.type = 'password';
		}
		if(this.value != this.defaultValue) this.select();
	});
	$('#pass').blur(function() {
  		if ($.trim(this.value) == ''){
			this.type = 'text';
  			this.value = (this.defaultValue ? this.defaultValue : '');
  		}
	});
});

function showMWin(obj, rval, bal){
	c = Math.round(obj.val());
	id = obj.attr('id')+'s';
	if (c>0 && c%rval != 0){
		if (!$('#'+id).length){
			obj.parent().append('<div id="'+id+'" class="rndr"></div>');
		}
		if (c > rval){
			c = Math.round(c/rval)*rval;
		}else{
			c = Math.ceil(c/rval)*rval;
		}
		if (c > bal){
			c = Math.floor(bal/rval)*rval;
		}
		$('#'+id).text(c);
		obj.blur(function(){
			if ($('#'+id).length){
				$(this).val(c);
				$('#'+id).remove();
			}
		});
		$('#'+id).click(function(){
			obj.val(c);
			$(this).remove();
		});
	}
}
