$(document).ready(function(){ 	   
       	/*$.fn.colorbox.settings.transition = "elastic";
		$.fn.colorbox.settings.bgOpacity = "0.9";
		$.fn.colorbox.settings.contentCurrent = "image {current} of {total}";
		$(".cpModal").colorbox();
		
		var options2 = {
            direction:  'left',
            duration:   230            
        }
		
        $('#popeye1').popeye(options2);*/
		
		$("ul.sf-menu").superfish({ 
			animation: {opacity:'show'},   // slide-down effect without fade-in 
			delay:     1200               // 1.2 second delay on mouseout 
		});
}); 

// Function for clickable row navigation.
function DoNav(theUrl)
{
  document.location.href = theUrl;
}

// Google Maps.
var map = null;
var geocoder = null;

function initialize() {
	if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(53.5444, -113.456), 10);
        geocoder = new GClientGeocoder();
		var mapControl = new GMapTypeControl();
		map.addControl(mapControl);
		map.addControl(new GSmallMapControl());
      }
    }

function showAddress(address) {
if (geocoder) {
	geocoder.getLatLng(
	address,
	function(point) {
			if (!point) {
				alert(address + " not found");
			} else {
				/*map.setCenter(point, 10);*/
				var marker = new GMarker(point);
				map.addOverlay(marker);
				
				}
			}
		);
	}
}


function stopRKey(evt) { 
  var evt = (evt) ? evt : ((event) ? event : null); 
  var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null); 
  if ((evt.keyCode == 13) && (node.type=="text"))  {return false;} 
} 

document.onkeypress = stopRKey;



function getCookie(c_name) { 
	if (document.cookie.length>0) {
		
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1) {
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
		
	}
	return "";
}

function setCookie(c_name,value,expiredays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
	
}


function addToCart(name, price, o1, o2) {
	
	var cart = getCookie("prevailCart");
	
	
	var f = document.getElementById("orderForm");
	var quantity = (f.quantity.selectedIndex + 1);
	
	var option1 = "&nbsp;";
	var option2 = "&nbsp;";
	
	if (o1 == true) {
		option1 = f.option1[f.option1.selectedIndex].value;
	}
	
	if (o2 == true) {
		option2 = f.option2[f.option2.selectedIndex].value;
	}
	
	if (option1 == "" || option1 == null || option1 == undefined || option1 == "undefined") {
		option1 = "&nbsp;";	
	}
	
	if (option2 == "" || option2 == null || option2 == undefined || option2 == "undefined") {
		option2 = "&nbsp;";	
	}
	
	var purchase = (name + "%%%" + price + "%%%" + quantity + "%%%" + option1 + "%%%" + option2 + "%%%%");
	
	if (cart != undefined) {
		purchase = cart+purchase;
	}
	
	setCookie("prevailCart", purchase, 365);
	
	alert ("Item Added To Cart");
}


function removeFromCart(id) {
	
	var cart = getCookie("prevailCart");
	
	cart = cart.split("%%%%");
	var updated = "";
	
	for (i=0; i<cart.length-1; i++) {
		if (i!= id) {
			updated += cart[i] + "%%%%";
		}
	}
	
	setCookie("prevailCart", updated, 365);
	alert ("Item Removed To Cart");
}

function checkout () {
	
	var f = document.getElementById("orderForm");
	
	var name = f.name.value;
	var phone = f.phone.value;
	var email = f.email.value;
	var address = f.address.value;
	var city = f.city.value;
	var province = f.province.value;
	var postalcode = f.postalcode.value;
	var comments = f.comments.value;
	
	var success = true;
	
	if (name == "" || phone == "" || email == "" || address == "" || city == "" || province == "" || postalcode == "") {
		success = false;
	}
	
		
	
	if (success) {
		f.submit();	
	} else {
		alert ("All Fields Are Required");	
	}
}

function deleteCart () {
	setCookie("prevailCart", "", -3600);
}

function setTheme(theme) {
	setCookie("prevailTheme", theme, 365);
}
