// JavaScript Document
	//initial checkCount of zero
	var checkCount=0
	
	//maximum number of allowed checked boxes
	var maxChecks=2
	
	var ww_root = "";

function changeImg(i) {
	$('loader').setStyle('display','block');
	var myImage = new Asset.image(ww_root+'/root/img/products/thumbs/'+i+'_244.jpg', {id: 'myImage', title: 'myImage', onload: function(){
		
			$('prodimg').setProperty('src',ww_root+'/root/img/products/thumbs/'+i+'_244.jpg');	
			
			MojoZoom.makeZoomable(  
				document.getElementById("prodimg"),   
				ww_root+'/root/img/products/'+i+'.jpg',
				null,  
				400, 400,  
				false
			); 
			
			$('loader').setStyle('display','none');
		}
	});	
}


function loadCatalog(p,c) {
	var url = ww_root+"/root/products/view/"+p+"?page="+c;
	new Ajax(url ,{ 
		method: 'get',
		update: 'content'
	}).request();
}

function refreshDetail(f) {
	checkCount=0;
}

function showDetail(f) {
	SqueezeBox.open(
		ww_root+"/root/store/view/"+f,
		{size:{x:866,y:500},
		closable: true,
		closeBtn: true,
		overlayOpacity: 0
	});	
	
}

function showIDetail(f) {
	SqueezeBox.open(
		ww_root+"/root/store/detail/"+f,
		{size:{x:766,y:500},
		closable: true,
		closeBtn: true,
		overlayOpacity: 0
	});
	
}

function setChecks(obj){
	//increment/decrement checkCount
	if(obj.checked){
	checkCount=checkCount+1
	}else{
	checkCount=checkCount-1
	}
	//if they checked a 4th box, uncheck the box, then decrement checkcount and pop alert
	if (checkCount>maxChecks){
	obj.checked=false
	checkCount=checkCount-1
	alert('You may only choose up to '+maxChecks+' options')
	}
}

function toCart() {
	location.href=ww_root+"/root/store/cart";
}

function addToCart($id) {
	$('addCart').addEvent('submit', function(e) {		
		new Event(e).stop();
		if(validate(this)){
			this.set('send',{
				update: 'cart_status',
				method: 'post',
				onComplete: function() {
					location.href=ww_root+"/root/store/cart";
				}
			});
			this.send();
		} //else {
			//refreshDetail($id);
		//}
	});
	return false;
}
