var cartOpen = false;

menuoffsetleft=0;
menuoffsettop=20;

menuvease=5;

menuhease=2;

menus=new Array("<div class='menuholder' id='menu1'><div class='menuitem_top_multiline' onMouseOver='this.style.cursor=\"pointer\"; javascript:menuclick(this,4,1); makeGrayJQ(this);' style='cursor: pointer;'><a href='?page=wines&typeID=all'>Most Popular<br>Wines</a> </div><div class='menuitem' onmouseover='javascript:hidesubmenus(); makeGray(this);'onMouseOut='javascript:makeNotGray(this);' ><a href='?page=wines&categoryID=2'><br>Trading Up</a></div><div class='menuitem' onmouseover='javascript:hidesubmenus(); makeGray(this);' onMouseOut='javascript:makeNotGray(this);'><a href='?page=commingsoon'><br>Secret Cellar</a></div><div class='menuitem_bottom_multiline'  onmouseover='javascript:hidesubmenus(); makeGray(this);' onMouseOut='javascript:makeNotGray(this);'><a href='?page=wines&categoryID=3'>Sparkling & Champagne</a></div></div>", 

"<div class='menuholder' id='menu2'><div style='clear:both;'/><div class='menuitem_top' onmouseover='javascript:hidesubmenus(); makeGray(this);' onMouseOut='javascript:makeNotGray(this);'><a href='?page=partyplanner_events'><br>Events</a></div><div style='clear:both;'/><div class='menuitem_bottom' onmouseover='javascript:hidesubmenus(); makeGray(this);' onMouseOut='javascript:makeNotGray(this);'><a href='?page=partyplanner_birthdays'><br>Friends Birthdays</a></div></div>", 

"<div class='menuholder' id='menu3'><div style='clear:both;'/><div class='menuitem_top' onmouseover='javascript:hidesubmenus(); makeGray(this);' onMouseOut='javascript:makeNotGray(this);'><a href='?page=personalised_special'><br>Special Occasions</a></div><div style='clear:both;'/><div class='menuitem' onmouseover='javascript:hidesubmenus(); makeGray(this);' onMouseOut='javascript:makeNotGray(this);'><a href='?page=personalised_corporate'><br>Corporate</a></div></div><div style='clear:both;'/><div class='menuitem_bottom' onmouseover='javascript:hidesubmenus(); makeGray(this);' onMouseOut='javascript:makeNotGray(this);'><a href='?page=personalised_function'><br>Function</a></div></div>", 

"<div class='menuholder' id='menu4'><div style='clear:both;'/><div class='menuitem_single' onmouseover='javascript:hidesubmenus(); makeGray(this);' onMouseOut='javascript:NotGray(this);'><br><a href='?page=friends_gifts'><center>All Gifts</center></a></div></div>",

"<div class='menuholder' id='menu5'><div class='menuitem_top' onmouseover='javascript:makeGray(this);' onMouseOut='javascript:makeNotGray(this);'><a href='?page=wines&typeID=1'><br>Red</a></div><div class='menuitem' onmouseover='javascript:makeGray(this);' onMouseOut='javascript:makeNotGray(this);'><a href='?page=wines&typeID=2'><br>White</a></div><div class='menuitem_bottom' onmouseover='javascript:makeGray(this);' onMouseOut='javascript:makeNotGray(this);'><a href='?page=wines&typeID=3'><br>Rose</a></div></div>");



//dont change these

selectedmenu=1000;
submenupresent=false;


function grabURL(srcurl, dName){
 
		if (window.XMLHttpRequest){
			xhttp=new XMLHttpRequest();
		}
		else{
			xhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		xhttp.onreadystatechange = function() {
			if(xhttp.readyState == 4 && xhttp.status == 200) {
				document.getElementById(dName).innerHTML = ''; 
				document.getElementById(dName).innerHTML = xhttp.responseText; 
				setupScroller();
			} 
		} 
		xhttp.open("POST",srcurl,true); 
		xhttp.setRequestHeader("content-Type", "text/xml"); 
		document.getElementById("wrapper").innerHTML = "<div id=\"loading_div\"><h3><big> Loading... </big></h3></div>"; 
		xhttp.send(""); 
} 

function changeCell(srcurl){
 
		$('.full-width').load(srcurl);
		
} 

function makeGrayJQ(tObj)
{
	var menuOBJ = tObj.getAttribute("class");
	var jqClass = "." + menuOBJ;
	$(jqClass).css("background-color", "#cdcdcd");
}

function makeGray(tObj)
{
	var menuType = tObj.getAttribute("class");
	if(menuType=="menuitem")
	{
		tObj.setAttribute("style", "width:144px;height:44px;padding-left:10px;font-size:23px;line-height:60%;float:left;font-family: pris, jwe, helvetica, arial, sans-serif; background-color:#cdcdcd;");
	}
	
	if(menuType=="menuitem_top")
	{
		tObj.setAttribute("style", "width:144px;height:44px;padding-left:10px;font-size:23px;line-height:60%;float:left;font-family: pris, jwe, helvetica, arial, sans-serif;background-color:#cdcdcd;");
	}
	
	if(menuType=="menuitem_bottom")
	{
		tObj.setAttribute("style", "width:144px;height:44px;padding-left:10px;font-size:23px;line-height:60%;float:left;font-family: pris, jwe, helvetica, arial, sans-serif;background-color:#cdcdcd;");
	}
	
	if(menuType=="menuitem_top_multiline")
	{
		tObj.setAttribute("style", "width:144px;height:44px;padding-left:10px;font-size:19px;line-height:130%;float:left;font-family: pris, jwe, helvetica, arial, sans-serif;background-color:#cdcdcd;");
	}
	
	if(menuType=="menuitem_bottom_multiline")
	{
		tObj.setAttribute("style", "width:144px;height:44px;padding-left:10px;font-size:19px;line-height:130%;float:left;font-family: pris, jwe, helvetica, arial, sans-serif;background-color:#cdcdcd;");
	}
	
	if(menuType=="menuitem_top_rounded")
	{
		tObj.setAttribute("style", "width:144px;height:44px;padding-left:10px;font-size:23px;line-height:60%;float:left;font-family: pris, jwe, helvetica, arial, sans-serif;background-color:#cdcdcd;");
	}
	
	if(menuType=="menuitem_single")
	{
		tObj.setAttribute("style", "width:144px;height:44px;padding-left:10px;font-size:22px;line-height:80%;float:left;font-family: pris, jwe, helvetica, arial, sans-serif; background-color:#cdcdcd;");
	}
	
}

function makeAllNotGray()
{
	$(".menuitem").css("background-color", "#FFF");
	$(".menuitem_top").css("background-color", "#FFF");
	$(".menuitem_bottom").css("background-color", "#FFF");
	$(".menuitem_single").css("background-color", "#FFF");
	$(".menuitem_top_multiline").css("background-color", "#FFF");
	$(".menuitem_bottom_mutiline").css("background-color", "#FFF");
	$(".menuitem_top_rounded").css("background-color", "#FFF");
	
	
}

function makeNotGray(tObj)
{
	var menuType = tObj.getAttribute("class");

	if(menuType=="menuitem")
	{
		tObj.setAttribute("style", "width:144px;height:44px;padding-left:10px;font-size:23px;line-height:60%;float:left;font-family: pris, jwe, helvetica, arial, sans-serif; background-color:#FFF;");
	}
	
	if(menuType=="menuitem_top")
	{
		tObj.setAttribute("style", "width:144px;height:44px;padding-left:10px;font-size:23px;line-height:60%;loat:left;font-family: pris, jwe, helvetica, arial, sans-serif;background-color:#FFF;");
	}
	
	if(menuType=="menuitem_bottom")
	{
		tObj.setAttribute("style", "width:144px;height:44px;padding-left:10px;font-size:23px;line-height:60%;float:left;font-family: pris, jwe, helvetica, arial, sans-serif;background-color:#FFF;");
	}
	
	if(menuType=="menuitem_top_multiline")
	{
		tObj.setAttribute("style", "width:144px;height:44px;padding-left:10px;font-size:19px;line-height:130%;loat:left;font-family: pris, jwe, helvetica, arial, sans-serif;background-color:#FFF;");
	}
	
	if(menuType=="menuitem_bottom_multiline")
	{
		tObj.setAttribute("style", "width:144px;height:44px;padding-left:10px;font-size:19px;line-height:130%;float:left;font-family: pris, jwe, helvetica, arial, sans-serif;background-color:#FFF;");
	}
	
	if(menuType=="menuitem_top_rounded")
	{
		tObj.setAttribute("style", "width:144px;height:44px;padding-left:10px;font-size:23px;line-height:60%;loat:left;font-family: pris, jwe, helvetica, arial, sans-serif;background-color:#FFF;");
	}
	
	if(menuType=="menuitem_single")
	{
		tObj.setAttribute("style", "width:144px;height:44px;padding-left:10px;font-size:23px;line-height:110%;float:left;font-family: pris, jwe, helvetica, arial, sans-serif; background-color:#FFF;");
	}
}

function makeGrayer(tObj)
{
	tObj.setAttribute("class", "menuitem_bottom_hover");
}

function menuclick(tobj, smenu, isSubMenu){
	var menuOffsetTop = 0;
	var menuOffsetLeft = 0;
	hidesubmenus();
	
    if(!isSubMenu)
    {
        if(selectedmenu==smenu){
            hidemenu();
			hidemenu();
            selectedmenu=1000;
        }else{
            hidemenu();
			hidemenu();
            selectedmenu=smenu;
            ns=document.createElement("div");
            
			
            ns.setAttribute("class", "menu");
            //ns.setAttribute("onmouseout", "javascript:menuout(this);");
            ns.setAttribute("id", "menu");
    	
			if(smenu==0){ menuOffsetop = 12; menuOffsetLeft = 9; } 
			if(smenu==1){ menuOffsetTop = 4; menuOffsetLeft = 9; } 
			if(smenu==2){ menuOffsetTop = 8; menuOffsetLeft = 14; } 
			if(smenu==3){ menuOffsetTop = 8; menuOffsetLeft = 20; }
			
			if(BrowserDetect.browser=="Explorer"){
                ns.style.marginLeft=parseFloat(tobj.offsetLeft - 21 + menuOffsetLeft);
                ns.style.paddingTop=parseFloat(tobj.offsetTop + 33 + menuOffsetTop);
            }else{
				ns.style.position="absolute";
                ns.style.left=tobj.offsetLeft - 21 + menuOffsetLeft;	
                ns.style.top=tobj.offsetTop + 33 + menuOffsetTop;
            }
            ns.style.zIndex=1;
            ns.innerHTML=menus[smenu];
			document.getElementById("overlay").appendChild(ns);
			//$("#overlay").append(ns);
			var iev = getInternetExplorerVersion();
			if(iev!=8){
				var oTop = tobj.offsetTop + 33 + menuOffsetTop;
				var oLeft = tobj.offsetLeft - 21 + menuOffsetLeft;
				$(".menu").css("top", oTop);
				$(".menu").css("left", oLeft);
			}
			$(".menu").hide();
			$(".menu").animate({ height: 'show', opacity: 'show' }, 'slow');
			
        }
    }
    else
    {
    	if(submenupresent){
    		//hidesubmenus();
    	}else{
   	 	submenupresent=true;
    	}
        selectedmenu=smenu;
            ns=document.createElement("div");
            ns.setAttribute("class", "submenu");
            //tobj.setAttribute("onmouseout", "javascript:submenuout(this);");
            ns.setAttribute("style", "float:left;width:200px;display:inline;");
			spacer = document.createElement("div");
            spacer.setAttribute("class", "clearer");
            //document.getElementById("menu").appendChild(spacer);
            
            document.getElementById("menu").appendChild(ns);
			ns.innerHTML=menus[smenu];
			$(".submenu").hide();
			$(".submenu").animate({ height: 'show', opacity: 'show' }, 'slow');
			
    }
}

function hidesubmenus(){
	if(document.getElementById("menu")){
	submenus=document.getElementById("menu").childNodes;
	for(sc=0;sc<submenus.length;sc++){
		if(submenus[sc].getAttribute("class")=="submenu"){
			document.getElementById("menu").removeChild(submenus[sc]);
		}
	}
	}
	makeAllNotGray();
}

function menuout(src){
	if(submenupresent){
	}else{
		src.parentNode.removeChild(src);
	}
}

function submenuout(src){
		src.parentNode.removeChild(src);
		submenupresent=false;
}



function menuUnHover(tobj)
{
    tobj.setAttribute("class", "menu");
}

function pausecomp(millis) 
{
	var date = new Date();
	var curDate = null;
	
	do { curDate = new Date(); } 
	while(curDate-date < millis);
} 


function hidemenu(){
	
//	$(".menu").fadeToggle("slow", "linear");
	$(".submenu").animate({ height: 'hide', opacity: 'hide' }, 'slow');
	document.getElementById("overlay").innerHTML="";

}


function checkCode(){
	
	var vcode = $("#vcode").val();
	if (vcode=="ChecK1")
	{
		$(".answer").css("background", "#09C");
		document.getElementById("answer").innerHTML="";
		document.getElementById("answer").innerHTML="<center><b>Code Accepted!! Click <a href='javascript:grabURL(\"pick.php\", \"wrapper\");'>here</a> to select prize!</b></center>";
	}
	else
	{
		$(".answer").css("background", "#F00");
		document.getElementById("answer").innerHTML="";
		document.getElementById("answer").innerHTML="<center><b>Incorrect Code Entered</b></center>";
	}
}

function getInternetExplorerVersion()
// Returns the version of Windows Internet Explorer or a -1
// (indicating the use of another browser).
{
   var rv = -1; // Return value assumes failure.
   if (navigator.appName == 'Microsoft Internet Explorer')
   {
      var ua = navigator.userAgent;
      var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
      if (re.exec(ua) != null)
         rv = parseFloat( RegExp.$1 );
   }
   return rv;
}
function checkIEVersion()
{
   var msg = "You're not using Windows Internet Explorer.";
   var ver = getInternetExplorerVersion();
   if ( ver> -1 )
   {
      if ( ver>= 8.0 )
         msg = "You're using Windows Internet Explorer 8.";
      else if ( ver == 7.0 )
    	  msg = "You're using Windows Internet Explorer 7.";
      else if ( ver == 6.0 )
    	  msg = "You're using Windows Internet Explorer 6.";
      else
    	  msg = "You should upgrade your copy of Windows Internet Explorer";
    }
   alert( msg );
}

function sLeft()
		{
			$(".scrollButtons").scrollTo(200);
		}
		
function setupScroller()
{
	$('#wine-list').serialScroll({
			items:'li',
			prev:'#scrollButtonRight',
			next:'#scrollButtonLeft',
			offset:26,
			start:0,
			duration:500,
			//interval:4000,
			force:true,
			stop:true,
			lock:false,
			exclude:1,
			cycle:false, //don't pull back once you reach the end
			jump: false //click on the images to scroll to them
		});
		
	/*	$('#photos a.sidegroup').fancybox({
			hideOnContentClick: false,
			zoomSpeedIn:	40,
			zoomSpeedOut:	40
		});*/
}

function toggleShoppingCart()
{
		//alert("BOOLLCCXX");
		if(cartOpen==false){
			$("#shoppingCartContent").animate({ height: 'show', opacity: 'show' }, 'slow');
			cartOpen=true;
		}
		else{
			$("#shoppingCartContent").animate({ height: 'hide', opacity: 'hide' }, 'slow');
			cartOpen=false;
		}
		
		//$("#shoppingCartContent").bounce();
		//$("#shoppingCartContent").effect("bounce", { times:3 }, 300);
	
}
	
function notifyMSG(msg)
{
		$.notify({title:'Example', text:msg, icon:'image.png'});
}


function toggleBasket(showHideButton, basketDiv){
	basketDiv = '#' + basketDiv;
	//showHideButton = "#" + showHideButton;
	if(document.getElementById(showHideButton).innerHTML=='[X] CLOSE BASKET'){
    		$('#outsideCart').animate({ height: 'hide', opacity: 'hide' }, 'slow', function(){
    			document.getElementById(showHideButton).innerHTML='[ ] OPEN BASKET';
    		});
    	}
     	else{
		$(basketDiv).animate({ height: 'show', opacity: 'show' }, 'slow', function(){
  			document.getElementById(showHideButton).innerHTML='[X] CLOSE BASKET';
		 });
	}
}      	

function notifyBuy(title){
	$('#buyNotify').animate({
	    "top": "+90%"
	    //opacity: 0.7
	    ///marginLeft: "0.6in",
	    //fontSize: "3em",
	    //borderWidth: "10px"
	  }, 'slow' );
}

function pausecomp(ms) {
ms += new Date().getTime();
while (new Date() < ms){}
} 


function notify(notifyDiv, theMessage){
		notifyDiv = "#"+notifyDiv;
		var height = getScrollTop();
		height	=	height	+	screenh;
//		alert(height);
		$(notifyDiv).html('<center><h3 style="font-size: 3em;">'+theMessage+'</h3></center>');
		$(notifyDiv).show();
		
		$(notifyDiv).css('top', height);
		$(notifyDiv).css({position:'absolute', bottom: $(notifyDiv).offset().bottom}).animate({top: $(notifyDiv).offset().top-100},1500,'linear',function() {
			pausecomp(1000);
			$(notifyDiv).css({position:'absolute', bottom: $(notifyDiv).offset().bottom}).animate({top: $(notifyDiv).offset().top+100},1000,'linear', function() { $(notifyDiv).hide()});
		});
}

var screenw = 0;
var screenh = 0;

//IE
if(!window.innerWidth){
	//strict mode
	if(!(document.documentElement.clientWidth == 0)) {
		screenw = document.documentElement.clientWidth;
		screenh = document.documentElement.clientHeight;
	} else {
		screenw = document.body.clientWidth;
		screenh = document.body.clientHeight;
	}
}
else{
	screenw = window.innerWidth;
	screenh = window.innerHeight;
}

function findPosY(obj){
	var curtop = 0;
	if(obj.offsetParent)
	while(1)
	{
		curtop += obj.offsetTop;
		if(!obj.offsetParent)
		break;
		obj = obj.offsetParent;
	}
	else if(obj.y)
	curtop += obj.y;
	return curtop;
} 

function findPosX(obj){
	var curleft = 0;
	if(obj.offsetParent)
	while(1) 
	{
		curleft += obj.offsetLeft;
		if(!obj.offsetParent)
		break;
		obj = obj.offsetParent;
	}
	else if(obj.x)
	curleft += obj.x;
	return curleft;
}

function getScrollTop(){
	if(typeof pageYOffset!= 'undefined'){
		//most browsers
		return pageYOffset;
	}
	else{
		var B= document.body; //IE 'quirks'
		var D= document.documentElement; //IE with doctype
		D= (D.clientHeight)? D: B;
		return D.scrollTop;
	}
}


/*function changePics(){

	alert("CHANGE PICS!!");
	var lis = $(".image_thumb ul li");
	var fieldCount = lis.length;
	var changed	=	false;
	for(int i=0; i<fieldCount; i++){
	
		
	
		//alert(imgAlt+\' * \'+imgTitle+\' * \'+imgDesc+\' * \'+imgDescHeight);
	
		var iv=0;
		while(!changed){
					var currentLI = $(lis[i]).attr(\'class\');    
					alert("li "+i+" class="+currentLI); 
						if(currentLI==\'active\'){
							alert("item "+i+" is active - scrolling...");
							pausecomp(2000);
							i = i+1;
							$(lis[i]).attr(\'class\', \'active\');
							var imgAlt = $(lis[i]).find(\'img\').attr("alt"); //Get Alt Tag of Image
							var imgTitle = $(lis[i]).find(\'a\').attr("href"); //Get Main Image URL
							var imgDesc = $(lis[i]).find(\'.block\').html(); 	//Get HTML of block
	
							var imgDescHeight = $(".main_image").find(\'.block\').height();	//Calculate height of block	
							$(".main_image .block").animate({ opacity: 0, marginBottom: -imgDescHeight }, 250 , function() {
								$(".main_image .block").html(imgDesc).animate({ opacity: 0.85,	marginBottom: "0" }, 250 );
								$(".main_image img").attr({ src: imgTitle , alt: imgAlt});
							});
							changed = true;
							alert("image changed to image "+i);
							iv = i;
						}
						else lis[i].setAttribute(\'class\',\'\');
		}     
	}
	$(".image_thumb ul li").removeClass(\'active\'); //Remove class of active on all lists
	$(lis[iv]).addClass(\'active\');  //add class of \'active\' on this list only
	
}
*/

//		    while(!changed){
//				var currentLI = lis[i].getAttribute(\'class\');    
//				alert("li "+i+" class="+currentLI); 
//				    if(currentLI==\'active\'){
//				    	alert("item "+i+" is active - scrolling...");
//				    	pausecomp(timeDelay);
//				    	i = i+1;
//				    	lis[i].setAttribute(\'class\', \'active\');
//				    	$(".main_image .block").animate({ opacity: 0, marginBottom: -imgDescHeight }, 250 , function() {
//							$(".main_image .block").html(imgDesc).animate({ opacity: 0.85,	marginBottom: "0" }, 250 );
//							$(".main_image img").attr({ src: imgTitle , alt: imgAlt});
//						});
//						changed = true;
//						alert("image changed to image "+i);
//						iv = i;
//				    }
//				    else lis[i].setAttribute(\'class\','');
//		   }     
//	}
//	$(".image_thumb ul li").removeClass(\'active\'); //Remove class of active on all lists
//	$(lis[iv]).addClass(\'active\);  //add class of \'active\' on this list only




	 
$(function() {
	$('#notify').hide();
});

