var shoptistik = function() {

var public = {

		
		GetXmlHttpObject: function()
		{
		var xmlHttp;
		try { 
		xmlHttp=new XMLHttpRequest(); 
		} catch (e) { 
		try { 
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); 
		} catch (e) { 
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); 
		} 
		}
		return xmlHttp;
		},
		
		checkOut: function(message) {
		},
		
		
		getCoup: function() {
		xmlHttp=shoptistik.GetXmlHttpObject();
		var coupCode = document.getElementById('coupCode').value;
		var url="cartform.php?c="+coupCode;
		xmlHttp.onreadystatechange=shoptistik.returnCartForm;
		xmlHttp.open("POST",url,true);
		xmlHttp.send(null);
		},
		
		returnCartForm: function() 
		{
		if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
		document.getElementById('cartForm').innerHTML=xmlHttp.responseText;
		}
		},
		
		
		moreItem: function(id) {
		document.getElementById('moreitem').innerHTML="";
		document.getElementById('moreitem').style.display = "inline";
		xmlHttp=shoptistik.GetXmlHttpObject();
		var url="more_item.php?id="+id;
		xmlHttp.onreadystatechange=shoptistik.returnMore;
		xmlHttp.open("POST",url,true);
		xmlHttp.send(null);
		},
		
		closeMore: function() {
		document.getElementById('moreitem').style.display = "none";
		},


		addComment: function(id) {
		document.getElementById('blogContainer').innerHTML="";
		xmlHttp=shoptistik.GetXmlHttpObject();
		var url="addcomment.php?id="+id;
		xmlHttp.onreadystatechange=shoptistik.returnComment;
		xmlHttp.open("POST",url,true);
		xmlHttp.send(null);
		},
		
		editComment: function(id,name,comment) {
		var name = document.getElementById('name').innerHTML;
		var encodedComment = encodeURIComponent(document.getElementById('comment').innerHTML);
		xmlHttp=shoptistik.GetXmlHttpObject();
		var url="addcomment.php?id="+id+"&n="+name+"&c="+encodedComment;
		xmlHttp.onreadystatechange=shoptistik.returnComment;
		xmlHttp.open("POST",url,true);
		xmlHttp.send(null);
		},
		
		previewComment: function(id) {
		var encodedName = document.getElementById('name').value;
		var encodedComment = encodeURIComponent(document.getElementById('comment').value);
		xmlHttp=shoptistik.GetXmlHttpObject();
		var url="preview.php?id="+id+"&n="+encodedName+"&c="+encodedComment;
		xmlHttp.onreadystatechange=shoptistik.returnComment;
		xmlHttp.open("POST",url,true);
		xmlHttp.send(null);
		},
		
		saveComment: function(id) {
		var encodedName = document.getElementById('name').value;
		var encodedComment = encodeURIComponent(document.getElementById('comment').value);
		xmlHttp=shoptistik.GetXmlHttpObject();
		var url="savecomment.php?id="+id+"&n="+encodedName+"&c="+encodedComment;
		xmlHttp.onreadystatechange=shoptistik.returnComment;
		xmlHttp.open("POST",url,true);
		xmlHttp.send(null);
		},
		
		savePreview: function(id) {
		var encodedName = document.getElementById('name').innerHTML;
		var encodedComment = encodeURIComponent(document.getElementById('comment').innerHTML);
		xmlHttp=shoptistik.GetXmlHttpObject();
		var url="savecomment.php?id="+id+"&n="+encodedName+"&c="+encodedComment;
		xmlHttp.onreadystatechange=shoptistik.returnComment;
		xmlHttp.open("POST",url,true);
		xmlHttp.send(null);
		},
		
		getCart: function() {
		document.getElementById("storecontainer").style.display = "none";
		document.getElementById("cartContainer").style.display = "block";
		document.getElementById("cartContainer").style.height =  "1000px";
		//document.getElementById("checkOutDetails").style.display = "inline";
		//document.getElementById("checkOutDetails").style.height =  "800px";
		var currentTime = new Date();
		var timestamp = currentTime.getTime();
		document.getElementById("cartContainer").src = "cookcart.php?x="+timestamp;
		},
		
		addItem: function(id) {
		xmlHttp=shoptistik.GetXmlHttpObject();
		var url="add_to_cart.php?id="+id;
		xmlHttp.onreadystatechange=shoptistik.returnCart;
		xmlHttp.open("POST",url,true);
		xmlHttp.send(null);
		},
		
		returnMore: function() 
		{
		if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
		document.getElementById('moreitem').innerHTML=xmlHttp.responseText;
		}
		},
		
		returnComment: function() 
		{
		if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
		document.getElementById('blogContainer').innerHTML=xmlHttp.responseText;
		}
		},
		
		returnCart: function() 
		{
		if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
		document.getElementById('addedmessage').style.display='inline';
		document.getElementById('shoppingCart').innerHTML=xmlHttp.responseText;
		}
		},
		

		
		returnCommentDiv: function() 
		{
		if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
		document.getElementById('comments').innerHTML=xmlHttp.responseText;
		}
		},
		
		
		i: 2,

		startFeatured: function(num) {
		newSlide = document.getElementById("homefeature");
		startint = setInterval("shoptistik.rotateImages("+num+")",3000);
		},
		
		rotateImages: function(num) {
		var total = num;
		if ( typeof(int) != "undefined" ) { clearInterval(int); }
		if ( public.i > total ) { public.i = 1; }
		transnum = 1;
		
		newSlide.style.display = "none";
		newSlide = document.getElementById("homefeature"+public.i);
		newSlide.style.display = "block";
		newSlide.style.filter = "alpha(opacity=0)";
		newSlide.style.opacity = ".0";	
		
		int = setInterval("shoptistik.fadeImageIn()",50);
		},
		
		changeFeaturedPic: function(num) {
		if ( typeof(startint) != "undefined" ) { clearInterval(startint); }
		newSlide.style.display = "none";
		newSlide = document.getElementById("homefeature"+num);
		newSlide.style.display = "block";
		},
		
		fadeImageIn: function() {
		if (transnum >= 9) {
		clearInterval(int);
		newSlide.style.filter = "alpha(opacity=100)";
		newSlide.style.opacity = "1.0";
		transnum = 1;
		public.i++;
		} else {
		newSlide.style.filter = "alpha(opacity="+transnum+"0)";
		newSlide.style.opacity = "."+transnum+"0";
		transnum++;
		}
		},
		
		stateSelect: function() {
		var state=document.getElementById('stateselect').value;
		alert(state);
		},
		
		aboutItem: function(num) {
		document.getElementById("itemabout"+num).style.display = "inline";
		},
		
		aboutItemOff: function(num) {
		document.getElementById("itemabout"+num).style.display = "none";
		},
		
		zoomIn: function(itemnum) {
		obj = document.getElementById("item"+itemnum);
		int = setInterval("shoptistik.makeZoomIn()",50);
		document.onselectstart = function () { return false; };
		document.onmouseup = shoptistik.stopInt;
		},
		
		testUp: function() {

		},
		
		zoomInMore: function(itemnum) {
		obj = document.getElementById("item"+itemnum);
		int = setInterval("shoptistik.makeZoomInMore()",50);
		document.onselectstart = function () { return false; };
		document.onmouseup = shoptistik.stopInt;
		},
		
		zoomOut: function(itemnum) {
		obj = document.getElementById("item"+itemnum);
		int = setInterval("shoptistik.makeZoomOut()",50);
		document.onselectstart = function () { return false; };
		document.onmouseup = shoptistik.stopInt;
		},
		
		zoomOutMore: function(itemnum) {
		obj = document.getElementById("item"+itemnum);
		int = setInterval("shoptistik.makeZoomOutMore()",50);
		document.onselectstart = function () { return false; };
		document.onmouseup = shoptistik.stopInt;
		},
		
		stopInt: function() {
		clearInterval(int);
		},
		
		makeZoomIn: function() {
		var currWidth = obj.offsetWidth;
		if ( currWidth >= 1200 ) {
		clearInterval(int);
		} else {
		var currHeight = obj.offsetHeight;
		var currTop = obj.offsetTop;
		var currLeft = obj.offsetLeft;
		var currTop = Math.round ( currTop - ( currHeight * .08 ) / 2 );
		var currLeft = Math.round ( currLeft - ( currWidth * .08 ) / 2 );
		var currWidth = Math.round( currWidth * 1.08 );
		var currHeight = obj.offsetHeight;
		obj.style.width=currWidth+"px";
		obj.style.top = currTop+"px";
		obj.style.left = currLeft+"px";
		}
		},
		
		makeZoomInMore: function() {
		var currWidth = obj.offsetWidth;
		if ( currWidth >= 1200 ) {
		clearInterval(int);
		} else {
		var currHeight = obj.offsetHeight;
		var currTop = obj.offsetTop;
		var currLeft = obj.offsetLeft;
		var currTop = Math.round ( currTop - ( currHeight * .08 ) / 2 );
		var currLeft = Math.round ( currLeft - ( currWidth * .08 ) / 2 );
		var currWidth = Math.round( currWidth * 1.08 );
		var currHeight = obj.offsetHeight;
		obj.style.width=currWidth+"px";
		obj.style.top = currTop+"px";
		obj.style.left = currLeft+"px";
		}
		},
		
		makeZoomOut: function() {
		var currWidth = obj.offsetWidth;
		if ( currWidth <= 150 ) {
		obj.style.left = "0px";
		obj.style.top = "0px";
		clearInterval(int) 
		} else {
		var currHeight = obj.offsetHeight;
		var currTop = obj.offsetTop;
		var currLeft = obj.offsetLeft;
		var currTop = Math.round ( currTop + ( currHeight * .08 ) / 2 );
		var currLeft = Math.round ( currLeft + ( currWidth * .08 ) / 2 );
		var currWidth = Math.round( currWidth * .92 );
		var currHeight = obj.offsetHeight;
		if ( currTop >= 0 ) { currTop = 0; }
		if ( currLeft >= 0 ) { currLeft = 0; }
		if ( currTop <= ( ( -1 * currWidth ) + 150 ) ) { currTop = ( -1 * currWidth ) + 150; }
		if ( currLeft <= ( ( -1 * currHeight ) + 150 ) ) { currLeft = ( -1 * currHeight ) + 150; }
		obj.style.width=currWidth+"px";
		obj.style.top = currTop+"px";
		obj.style.left = currLeft+"px";
		}
		},
		
		
		makeZoomOutMore: function() {
		var currWidth = obj.offsetWidth;
		if ( currWidth <= 150 ) {
		obj.style.left = "0px";
		obj.style.top = "0px";
		clearInterval(int) 
		} else {
		var currHeight = obj.offsetHeight;
		var currTop = obj.offsetTop;
		var currLeft = obj.offsetLeft;
		var currTop = Math.round ( currTop + ( currHeight * .08 ) / 2 );
		var currLeft = Math.round ( currLeft + ( currWidth * .08 ) / 2 );
		var currWidth = Math.round( currWidth * .92 );
		var currHeight = obj.offsetHeight;
		if ( currTop >= 0 ) { currTop = 0; }
		if ( currLeft >= 0 ) { currLeft = 0; }
		if ( currTop <= ( ( -1 * currWidth ) + 150 ) ) { currTop = ( -1 * currWidth ) + 150; }
		if ( currLeft <= ( ( -1 * currHeight ) + 150 ) ) { currLeft = ( -1 * currHeight ) + 150; }
		obj.style.width=currWidth+"px";
		obj.style.top = currTop+"px";
		obj.style.left = currLeft+"px";
		}
		},
		
		displayMenu: function(menu) {
		if ( typeof(int) != "undefined" ) { clearInterval(int); }
		submenu = document.getElementById(menu);
		if (  parseInt(submenu.style.height) > 1 ) {
		submenu.style.height = "1px";
		submenu.style.display = "none";
		} else {
		menuheight = document.getElementById(menu+"height").offsetHeight;
		submenu.style.height = "1px";
		submenu.style.display = "block";
		num=1;
		int = setInterval("shoptistik.slideMenu("+menuheight+")",10);
		}
		},
		
		slideMenu: function(height) {
		if ( num > height ) {
		clearInterval(int);
		submenu.style.height = height+"px";
		} else {
		submenu.style.height = num+"px";
		num = num+20;
		}
		},
		
addEmail: function(str)
{ 
xmlHttp=shoptistik.GetXmlHttpObject();
var url="addemail.php?addemail="+str;
xmlHttp.onreadystatechange=shoptistik.emailAdded;
xmlHttp.open("POST",url,true);
xmlHttp.send(null);
},

addEmailfromBlog: function(str)
{ 
xmlHttp=shoptistik.GetXmlHttpObject();
var url="../addemail.php?addemail="+str;
xmlHttp.onreadystatechange=shoptistik.emailAdded;
xmlHttp.open("POST",url,true);
xmlHttp.send(null);
},

emailAdded: function() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 document.getElementById("showResponse").innerHTML=xmlHttp.responseText;
 } 
},


		
		slideMenu: function(height) {
		if ( num > height ) {
		clearInterval(int);
		submenu.style.height = height+"px";
		} else {
		submenu.style.height = num+"px";
		num = num+20;
		}
		}
		
		}
		
return public;

}();





var dragElement;	

function startDrag(getboxname) {
boxname=getboxname;
document.onmousedown = OnMouseDown;
document.onmouseup = OnMouseUp;
document.onmousemove = OnMouseMove;		
document.ondragstart = function() { return false; };
}


function OnMouseDown(e)
{
	if (!e) var e = window.event;
	if (e.target != null) 
	{
	target=e.target;
	} else {
	target=e.srcElement;
	}
	dragElement = document.getElementById(boxname);
	startX = e.clientX;
	startY = e.clientY;	
	offsetX = parseInt(dragElement.style.left);
	offsetY = parseInt(dragElement.style.top);
	return false;
}


function OnMouseMove(e)
{
	if (e == null) 
	{
	var e = window.event; 
	}
	
	
	target.style.left = (offsetX + e.clientX - startX) + 'px';
	target.style.top = (offsetY + e.clientY - startY) + 'px';
	
	boxwidth = dragElement.style.width;
	boxheight = dragElement.style.height;
	
	var newX = offsetX + e.clientX - startX;
	var newY = offsetY + e.clientY - startY;
	
	var posXCheck = ( parseInt(dragElement.offsetWidth) * -1 ) + 150;
	var posYCheck = ( parseInt(dragElement.offsetHeight) * -1 ) + 150;
	
	if ( newX >= 0 ) { newX = 0; }
	if ( newY >= 0 ) { newY = 0; }
	if ( newX <= posXCheck ) { newX = posXCheck; }
	if ( newY <= posYCheck ) { newY = posYCheck; }
	
	dragElement.style.left = newX + 'px';
	dragElement.style.top = newY + 'px';
	
}

function OnMouseUp(e)
{

	document.onmousemove = null;
	document.onmouseup = null;
	dragElement = null;
	target = null;	
}




