
function removefromcart(item)
{ 

	
		//alert(form.action);
 	
		
		//alert(form.action);
	    YAHOO.util.Connect.asyncRequest('GET', "remove.php?iid="+item.id+"&session="+sessionID+"&ajax=true", removefromcartback); 

	
	return false;

}


function updatecart(form) {
	
		YAHOO.util.Connect.setForm(form);
		//alert(form.action);
	    YAHOO.util.Connect.asyncRequest('POST', form.action, removefromcartback, 'session='+sessionID+'&ajax=true'); 

	
}


function addtocart(form)
{ 

	
	
 	
		YAHOO.util.Connect.setForm(form);
		//alert(form.action);
	    YAHOO.util.Connect.asyncRequest('POST', form.action, addtocartback, 'session='+sessionID+'&ajax=true'); 

	
	return false;

}

function setshipstate(form)
{ 

	
	
 	
	YAHOO.util.Connect.setForm(form);
	//alert(form.action);
	YAHOO.util.Connect.asyncRequest('POST', form.action, setstateback, 'session='+sessionID+'&ajax=true'); 

	
	return false;

}

function updateminicart(){
		YAHOO.util.Connect.asyncRequest('GET', "minicart.php?session="+sessionID+"&ajax=true", updateminicartback); 
}

var updateminicartback = 
{	customevents:{

		onSuccess:function(eventType, args) {
		
		document.getElementById('minicart_div').innerHTML = args[0].responseText;
		initPageChangers();
	   
		}
	}
}

var removefromcartback = 
{	customevents:{
		onStart:function(eventType, args) {
		
		$.setStyle('cs_modal_container', 'z-index', '97');
		$.setStyle('cs_modal_container', 'display', 'block');
			

		},
		onComplete:function(eventType, args) {
		$.setStyle('cs_modal_container', 'z-index', '0');
		$.setStyle('cs_modal_container', 'display', 'none');

		},
		onSuccess:function(eventType, args) {
		
		document.getElementById('subcontent_div').innerHTML = args[0].responseText;
		if (!document.getElementById('cs_cart_form')) {
			document.getElementById('minicart_div').innerHTML = '';
		}
		else
		{
			updateminicart();
		}
		initPageChangers();
		initTextLinks();
	   
		},
		onFailure:function(eventType, args) {

		},

		onUpload:function(eventType, args) {

		},
		onAbort:function(eventType, args) {

		}
	}
}

var setstateback = 
{	customevents:{
		onStart:function(eventType, args) {
		
		$.setStyle('cs_modal_container', 'z-index', '97');
		$.setStyle('cs_modal_container', 'display', 'block');
			

		},
		onComplete:function(eventType, args) {
		$.setStyle('cs_modal_container', 'z-index', '0');
		$.setStyle('cs_modal_container', 'display', 'none');

		},
		onSuccess:function(eventType, args) {
			
		document.getElementById('subcontent_div').innerHTML = args[0].responseText;
		initPageChangers();
		initTextLinks();
	   
		},
		onFailure:function(eventType, args) {

		},

		onUpload:function(eventType, args) {

		},
		onAbort:function(eventType, args) {

		}
	}
}

var addtocartback = 
{	customevents:{
		onStart:function(eventType, args) {
		
		$.setStyle('cs_modal_container', 'z-index', '97');
		$.setStyle('cs_modal_container', 'display', 'block');
			

		},
		onComplete:function(eventType, args) {
		$.setStyle('cs_modal_container', 'z-index', '0');
		$.setStyle('cs_modal_container', 'display', 'none');

		},
		onSuccess:function(eventType, args) {
			
		document.getElementById('minicart_div').innerHTML = args[0].responseText;
		initPageChangers();
		initTextLinks();
	   
		},
		onFailure:function(eventType, args) {

		},

		onUpload:function(eventType, args) {

		},
		onAbort:function(eventType, args) {

		}
	}
}
	

var formBack = 
{	customevents:{
		onStart:function(eventType, args) {
		
		$.setStyle('cs_modal_container', 'z-index', '97');
		$.setStyle('cs_modal_container', 'display', 'block');
			

		},
		onComplete:function(eventType, args) {
		$.setStyle('cs_modal_container', 'z-index', '0');
		$.setStyle('cs_modal_container', 'display', 'none');

		},
		onSuccess:function(eventType, args) {
			//alert('hello');
		var content = args[0].responseText;
		content = content.replace(/\\'/g, '\'');
		//alert(content);
		document.getElementById('subcontent').innerHTML = content;
		if (document.getElementById('cart_shipping')){
			//alert('hello');
			document.getElementById('cart_shipping_amount').innerHTML = document.getElementById('shiprate').value;
			document.getElementById('cart_shipping').style.display="block";
		}
							 
	   
		},
		onFailure:function(eventType, args) {

		},

		onUpload:function(eventType, args) {

		},
		onAbort:function(eventType, args) {

		}
	}
	
}

function formAjax(form)
{
	//alert(form.id);
	var check = FIC_checkForm(form);
	//alert(check);
	if (check)
	{
			YAHOO.util.Connect.setForm(form);
			YAHOO.util.Connect.asyncRequest('POST', form.action, formBack, null);
	}
	
	return false;
}


var callback =
{
	customevents:{
		onStart:function(eventType, args) {
	
		},
		onComplete:function(eventType, args) {
	
		},
		onSuccess:function(eventType, args) {
			
		  	var blah = document.getElementById('cs_tools_image_thumb_div_'+args[0].responseText);
			blah.parentNode.removeChild(blah);
	   
		},
		onFailure:function(eventType, args) {
	
		},

   
		onUpload:function(eventType, args) {
		
		},
		onAbort:function(eventType, args) {
		}
	}
}

function confirmDelete(form)
{ 

	
	
 	if (confirm("Really?"))
	{
		YAHOO.util.Connect.setForm(form);
		//alert(form.action);
	    YAHOO.util.Connect.asyncRequest('POST', form.action, callback, null); 
		
	}
	else
	{
		
	}
	
	return false;

}


var events = YAHOO.util.Event;
var $$ = YAHOO.util.Selector.query;
var fx = YAHOO.widget.Effects;
var $ = YAHOO.util.Dom;
var ani = YAHOO.util.Anim;
var anim;
var bright;
var dim;
var polaroid;
var currenthover = 0;
var currentPage;
var currentMenuHL;
var lastMenuHL = 0;
var newMenuHL = 0;
var thisPage;


var leftBar;
var rightBar;
var polaroid;
var contentFrame;
var menuHeight;
var content;
var polaroidState;



 var YU = YAHOO.util;
  var YD = YAHOO.util.Dom;
  var YE = YAHOO.util.Event;
 
  YAHOO.Scroller = function (el, userConfig) {
	 
      if (el) {
          this.render(el, userConfig);
      } else {
          YAHOO.log("No element or element ID specified" + 
              " for Scroller instantiation", "error");
      }
  };
	YAHOO.Scroller.prototype={
	  render:function(el, userConfig){
      var me=this,anim_running = false, anim = null,tar = null;
      var type = (userConfig.type=="horizontal") ? 1 : 0;
      var cnt = YD.get(userConfig.content);
	  var isIE = (navigator.appName=="Microsoft Internet Explorer");
	  if (isIE) {dur = .001} else { dur = .005}
      a = new YU.Scroll(cnt, {}, dur);
	  try{
      a.onComplete.subscribe(function() {
          if (anim_running) {
              a.attributes = getAttrs(a.getEl().id);
              a.animate();
          }
      });
	  }catch(kuku){}
      var elems = YD.getElementsByClassName("scrollarrows","div",el);
      YE.addListener(elems, 'mouseover', over, anim, true);
      YE.addListener(elems, 'mouseout', out);
      function out(ev) {
            anim_running = false;
      }
      function over(ev) {
        tar = YE.getTarget(ev);
		
        a.attributes = getAttrs();
        anim_running = true;
        a.animate();
      }
      function getAttrs(){
        var arrTo,
        rt=(YD.hasClass(tar,'down')||YD.hasClass(tar,'right')) ? 20 : -20;
        var toVal = ((type) ? parseInt(cnt.scrollLeft) : parseInt(cnt.scrollTop))+rt;    
        return {scroll: {to: ((type) ? [toVal,0] : [0,toVal])}};
      }
    }
  };





function flirInit() {
	FLIR.init( { path: 'cs-includes/facelift-1.2/' } );
}

function flirTitle() {
	FLIR.replace( 'div.page_title', new FLIRStyle({ cFont:'ss', output:'auto', inheritStyle: true }));
}

function flirMenu(){
	
	FLIR.replace( 'a.cs_site_menu_item', new FLIRStyle({ cFont:'Trajan', output:'auto', inheritStyle: true  }));
	FLIR.replace( 'a.cs_site_menu_hl', new FLIRStyle({ cFont:'Trajan', output:'auto', inheritStyle: true  }));
	
}

function initStyles(){
	
	$.setStyle('content', 'height', '0px');
	$.setStyle('cs_site_menu', 'height', '0px');
	$.setStyle('cs_site_menu', 'overflow', 'hidden');

	$.setStyle('cs_menu_div', 'display', 'none');
	
	
}

function blank(){
	$.setStyle('contentFrame', 'display', 'none');
	$.setStyle('contentFrame', 'opacity', '0');
	$.setStyle('cs_splash', 'display', 'none');
	$.setStyle('cs_contact_info', 'opacity', '0');
	$.setStyle('footer', 'opacity', '0');
}


function initSideBars() {
	leftBar = new YAHOO.util.Anim('left_bar', {left: {from:-300, to:10}}, 2, YAHOO.util.Easing.easeOutStrong);
	rightBar = new YAHOO.util.Anim('right_bar', {left: {from:1000, to:738}}, 2, YAHOO.util.Easing.easeOutStrong);
	
}


function initPolaroid() {
	
		 var attributes = {
        points: { to: [420, 330], control: [ [100, 100], [1000, 200] ] }
    };
		polaroid = new YAHOO.util.Motion('polaroid', attributes, 6, YAHOO.util.Easing.easeOut);
		
	
}

function clearPolaroid(){
	
	if (polaroid.isAnimated()) { polaroid.stop();}
	polaroid = new YAHOO.util.Anim('polaroid', { top:{to:800}}); 
	polaroid.duration = 1; 
	
	polaroid.onComplete.subscribe(function(){
	$.setStyle('polaroid', 'visibility', 'hidden'); 	
	$.setStyle('polaroid', 'top', '-400px'); 
	$.setStyle('polaroid', 'left', '1000px');
	$.setStyle('polaroid', 'visibility', 'visible'); 
	polaroidState = "cleared";
   });
	
	polaroid.animate();
	
	return false;
}


function showFooter(){

	var footer = new YAHOO.util.Anim('footer', {opacity: {from:0, to:1}}, 1, YAHOO.util.Easing.easeOut);
	footer.animate();
}


function places(){
	$.setStyle('contentFrame', 'display', 'block');
	
	contentFrame = new YAHOO.util.Anim('contentFrame', {opacity: {from:0, to:1}}, 1, YAHOO.util.Easing.easeOut);
	contactInfo= new YAHOO.util.Anim('cs_contact_info', {opacity: {from:0, to:1}}, 1, YAHOO.util.Easing.easeOut);
	menuHeight = new YAHOO.util.Motion('cs_site_menu', {height: {to:400}},2, YAHOO.util.Easing.easeOut);
	
	if (initialPageState == defaultPageState || initialPageState == ''){
	content = new YAHOO.util.Anim('content', {opacity: {to:1}, height: {to: 578} }, 3, YAHOO.util.Easing.easeOutStrong);
	}
	else
	{
		$.setStyle('content', 'height', '578px');
	}
	contentFrame.animate(); 
	$.setStyle('cs_menu_div', 'display', 'block');
	setTimeout("leftBar.animate();", 1000);
	setTimeout("rightBar.animate();", 1000);	
	setTimeout("menuHeight.animate();", 2500);
	setTimeout("content.animate();", 3000);
	
	setTimeout("contactInfo.animate()", 4000);
	
	showFooter();
	setTimeout("loadIconMenuItems()", 4000);
	
}

function loadPage(){

	
		
	menuHeight.onComplete.subscribe(function(){ 

	});
	
}



var splash = $$('#cs_splash');
s = true;



function showSplash() {
	
			$.setStyle('cs_splash', 'display', 'block');
			var intro = new YAHOO.util.Anim(splash, {opacity: {to: 1}});
			intro.animate();
			setTimeout("$.setStyle('cs_splash', 'display', 'none');", 9200);
	
}



		
		
		var exampleCont = null;
var tmpForm = null;

function formInit() {

    var tmpForm = new YAHOO.DHTMLForms.Form('presclubform');


}


		
		function loadIconMenuItems() {
			

			
			var totalLength = 2;
			
			
			
			var iconMenus = $$('.icon_div');
			
			var dur = totalLength / iconMenus.length;
		
			var x = 0;
				
				var f = new ani(iconMenus[x], {opacity: {to:1}}, dur, YAHOO.util.Easing.easeOut);
								
				
				
				f.onComplete.subscribe(function() {
					x++;
					f.setEl(iconMenus[x]);
					
					
					f.animate();
										
																					
				});
				
				f.animate();

		}
		
		function animateOpacity(el, tox, durx)
		{

			var f = new ani(el, {opacity: {to: tox}}, durx, YAHOO.util.Easing.easeOut);
			f.animate();
			
		}
		
		function attachBehaviors() {

			//var iconMenus = $$('.small');
			//YAHOO.util.Event.addListener(iconMenus, "mouseover", hl); 
			//YAHOO.util.Event.addListener(iconMenus, "mouseout", uhl); 
			
			
			var siteMenus = $$('.cs_menu_div_control');
			YAHOO.util.Event.addListener(siteMenus, "mouseover", smhl);

			YAHOO.util.Event.addListener(siteMenus, "mouseout", smuhl); 
			
			
		}
		
		var hl = function(el){
			
			var bright = new YAHOO.util.Anim(this, {opacity: {to: 0}}, .2, YAHOO.util.Easing.easeOut);
			bright.animate();
		
			
			
		}
		
		var uhl = function(el){
		
			var bright = new YAHOO.util.Anim(this, {opacity: {to: 1}}, .4, YAHOO.util.Easing.easeOut);
			bright.animate();
		
			
		}
		
		var smhl = function(el) {
			
			
			
			pageid = this.id.replace('cs_menu_div_control_', '');
			
			
						
			bright = new YAHOO.util.Anim('cs_site_menu_item_'+pageid, {opacity: {to: 0}}, .1);
			bright.animate(); 
			
		
		}
		
		var smuhl = function(el) {
				

			 pageid = this.id.replace('cs_menu_div_control_', '')

			dim = new YAHOO.util.Anim('cs_site_menu_item_'+pageid, {opacity: {to: 1}}, .6, YAHOO.util.Easing.easeOut);
			dim.animate();

			
			} 

String.prototype.stripHTML = function()

{

        // What a tag looks like

        var matchTag = /<(?:.|\s)*?>/g;

        // Replace the tag

        return this.replace(matchTag, "");

};
var AjaxObject = {

	handleSuccess:function(o){

		
	
		if (document.getElementById('content')){
		document.getElementById('content').innerHTML = o.responseText;
		}
		if (newState) {document.title = document.getElementById('newtitle').innerHTML;}
		
		//var listItems = $$('.cs_list_menu_item');
		//YAHOO.util.History.navigate("item", listItems[0].innerHTML);
		//initSifr();
		//FLIR.replace( 'div.cs_site_menu_item', new FLIRStyle({ cFont:'Trajan', output:'auto', inheritStyle: true }));
		//FLIR.replace( 'div.cs_site_menu_hl', new FLIRStyle({ cFont:'Trajan', output:'auto', inheritStyle: true }));
		FLIR.replace( 'div.secret-scrypt', new FLIRStyle({ cFont:'ss', output:'auto', inheritStyle: true }));
		FLIR.replace( 'span.secret-scrypt', new FLIRStyle({ cFont:'ss', output:'auto', inheritStyle: true }));
		FLIR.replace( 'div.wine_blurb', new FLIRStyle({ cFont:'Trajan', output:'png', inheritStyle: true }));
		FLIR.replace( 'div.trajan', new FLIRStyle({ cFont:'Trajan', output:'png', inheritStyle: true }));

		YAHOO.util.Dom.setStyle('content', 'visibility', 'visible');
		
		var content = new YAHOO.util.Anim('content', {opacity: {to:1}}, .5, YAHOO.util.Easing.easeOut);
		content.animate();
		var submenu = new YAHOO.util.Anim($$('.cs_list_menu'), {top: {to:2}}, 1.5, YAHOO.util.Easing.easeBothStrong);
		var subcontent = new YAHOO.util.Anim('subcontent_div', {top: {to:4}}, 1.5, YAHOO.util.Easing.easeBothStrong);
		var vScroller = new YAHOO.Scroller("subcontent_div",{type:"vertical",content:"subcontent"});
		submenu.animate();
		//alert('hello');
		//if(document.getElementById('cs_list_menu')){
		initSubNav();
			
		initTextLinks();
		if(document.getElementById('cs_checkout_form')){
			
				YAHOO.util.History.register("step", "default", function (state) {
	
        		//checkoutAjax.startRequest(state);
    			});
			//alert('hello');
			//YAHOO.util.History.navigate("step", "");
			YAHOO.util.History.navigate("step", 'states');
			initCheckoutLinks();
		}


		//}
		
		subcontent.animate();
	},

	handleFailure:function(o){

	},

	processResult:function(o){

	},

	startRequest:function(page) {

		currentPage = page;

		YAHOO.util.Dom.setStyle('subcontent', 'overflow', 'hidden');
		var content = new YAHOO.util.Anim('content', {opacity: {to:0}}, .15, YAHOO.util.Easing.easeOut);
		content.animate();
		content.onComplete.subscribe(function(){
		YAHOO.util.Dom.setStyle('content', 'visibility', 'hidden');
		
		YAHOO.util.Connect.asyncRequest('GET', 'page.php?page=' + page + '&session=' + sessionID, callback);});
	 	
	}

};


var callback =
{
	success:AjaxObject.handleSuccess,
	failure:AjaxObject.handleFailure,
	scope: AjaxObject
};


var subContentAjax = {

	handleSuccess:function(o){
	
				YAHOO.util.Dom.setStyle('subcontent', 'width', '470px');
				var sc = document.getElementById('subcontent');
				//alert(sc.innerHTML);
				//alert(o.responseText);
				sc.innerHTML = o.responseText;
				FLIR.replace( 'div.trajan', new FLIRStyle({ cFont:'Trajan', output:'png', inheritStyle: true, mode: 'wrap'}));
				FLIR.replace( 'div.cs_site_menu_item', new FLIRStyle({ cFont:'Trajan', output:'auto', inheritStyle: true  }));
FLIR.replace( 'div.cs_site_menu_hl', new FLIRStyle({ cFont:'Trajan', output:'auto', inheritStyle: true  }));
FLIR.replace( 'div.secret-scrypt', new FLIRStyle({ cFont:'ss', output:'png', inheritStyle: true, mode: 'wrap'}));
FLIR.replace( 'span.secret-scrypt', new FLIRStyle({ cFont:'ss', output:'png', inheritStyle: true}));

 				YAHOO.util.Dom.setStyle('subcontent', 'width', '0px');
				$.setStyle('subcontent', 'visibility', 'visible');
				try { document.getElementById('subcontent').scrollTop = '0px'; } catch(err) { }
				try { document.getElementById('divup').style.visibility = 'hidden'; } catch(err) {  } 
				next = new YAHOO.util.Anim('subcontent', {width: {to:470}}, .8, YAHOO.util.Easing.easeInOut);
				
				
				//initSubNav();
				initTextLinks();
				initTextSubLinks();
				//attachToForms(null);
				if (document.getElementById('recaptcha_div')) {
				showRecaptcha('recaptcha_div', 'submit', 'white');
				}
				if (document.getElementById('foxyform')) {
				//alert('hello');

				//fc_tb_init('a.foxycart');
				//fc_tb_init('form.foxycart');
				
				}
				next.animate();
				return false;
		
	},

	handleFailure:function(o){

	},

	processResult:function(o){

	},

	startRequest:function(table, id, donly) {

		var content = new YAHOO.util.Anim('subcontent', {width: {to:1}}, .15, YAHOO.util.Easing.easeOut);
		content.animate();
		
		content.onComplete.subscribe(function(){
									   
									
					  YAHOO.util.Dom.setStyle('subcontent', 'visibility', 'hidden');

				YAHOO.util.Connect.asyncRequest('GET', 'item.php?table=' + table + '&id=' + id + '&do=' + donly + '&session='+sessionID, scaCallBack, "");
											  });return false;
	}
		
};


var checkoutAjax = {

	handleSuccess:function(o){
	
				YAHOO.util.Dom.setStyle('subcontent', 'width', '470px');
				var checkout = document.getElementById('subcontent');
				//alert(sc.innerHTML);
				//alert(o.responseText);
				checkout.innerHTML = o.responseText;
				if (document.getElementById('receipt_div')){
					document.getElementById('minicart_div').innerHTML='';
				}
				//ini
 				YAHOO.util.Dom.setStyle('subcontent', 'width', '0px');
				$.setStyle('subcontent', 'visibility', 'visible');
				//try { document.getElementById('subcontent').scrollTop = '0px'; } catch(err) { }
				//try { document.getElementById('divup').style.visibility = 'hidden'; } catch(err) {  } 
				var next = new YAHOO.util.Anim('subcontent', {width: {to:470}}, .8, YAHOO.util.Easing.easeInOut);
				
				
				//initSubNav();
				//initTextLinks();
				initCheckoutLinks();
				
				
				next.animate();
				$.setStyle('cs_modal_container', 'z-index', '0');
		$.setStyle('cs_modal_container', 'display', 'none');
				return false;
		
	},

	handleFailure:function(o){

	},

	processResult:function(o){

	},

	startRequest:function(step) {
$.setStyle('cs_modal_container', 'z-index', '97');
		$.setStyle('cs_modal_container', 'display', 'block');
		var content = new YAHOO.util.Anim('subcontent', {width: {to:1}}, .15, YAHOO.util.Easing.easeOut);
		content.animate();
		
		content.onComplete.subscribe(function(){
									   
									
					
					YAHOO.util.Dom.setStyle('subcontent', 'visibility', 'hidden');
						
					if (checkoutForm !== "" && step !== checkoutForm.id) {

					YAHOO.util.Connect.setForm(checkoutForm);
					
					YAHOO.util.Connect.asyncRequest('POST', 'post.php', checkoutCallback, 'session='+sessionID+'&step=' + step);
					}
					else
					{
					//alert(step);
					YAHOO.util.Connect.asyncRequest('GET', 'item.php?plugin=checkout&step='+step+'&session='+sessionID, checkoutCallback, "");
					}
				
											  
											 });
		return false;
	}
		
};
var checkoutCallback =
{
	success:checkoutAjax.handleSuccess,
	failure:checkoutAjax.handleFailure,
	scope: checkoutAjax
};



var scaCallBack =
{
	success:subContentAjax.handleSuccess,
	failure:subContentAjax.handleFailure,
	scope: subContentAjax
};

var wineMenuAjax = {

	handleSuccess:function(o){
			$.setStyle('wine_menu', 'visibility', 'hidden');	
				
				document.getElementById('wine_menu').innerHTML = o.responseText;
				
			FLIR.replace( 'div.trajan', new FLIRStyle({ cFont:'Trajan', output:'png', inheritStyle: true, mode: 'wrap'}));	

  				
				$.setStyle('wine_menu', 'visibility', 'visible');
				
				anim = new YAHOO.util.Anim('wine_menu', { height: {to: 140}, top: {to: 44 }}, .5); 
				
				anim.animate();
			
	},

	handleFailure:function(o){
	},

	processResult:function(o){
		
	},

	startRequest:function(color) {
		var content = new YAHOO.util.Anim('wine_menu', {height: {to:0}, top: {to:80}}, 1, YAHOO.util.Easing.easeOut);
		content.animate();
				
	content.onComplete.subscribe(function(){
				YAHOO.util.Connect.asyncRequest('GET', 'cs-content/plugins/wines/winemenu.php?color=' + color, lmaCallBack, "");
											  
											  });
	}

};

var lmaCallBack =
{
	success:wineMenuAjax.handleSuccess,
	failure:wineMenuAjax.handleFailure,
	scope: wineMenuAjax
};

var cartAjax = {

	handleSuccess:function(o){
		
		document.getElementById('content').innerHTML = o.responseText;
		$.setStyle('cart_container', 'display', 'block');
		//drawCart();
	
		FLIR.replace( 'div.cs_site_menu_item', new FLIRStyle({ cFont:'Trajan', output:'auto', inheritStyle: true  }));
FLIR.replace( 'div.cs_site_menu_hl', new FLIRStyle({ cFont:'Trajan', output:'auto', inheritStyle: true  }));
FLIR.replace( 'div.secret-scrypt', new FLIRStyle({ cFont:'ss', output:'auto', inheritStyle: true}));
FLIR.replace( 'span.secret-scrypt', new FLIRStyle({ cFont:'ss', output:'auto', inheritStyle: true}));
FLIR.replace( 'div.wine_blurb', new FLIRStyle({ cFont:'Trajan', output:'png', inheritStyle: true}));
FLIR.replace( 'div.trajan', new FLIRStyle({ cFont:'Trajan', output:'png', inheritStyle: true}));

		YAHOO.util.Dom.setStyle('content', 'visibility', 'visible');
		//initSubNav();
		initTextLinks();
		var content = new YAHOO.util.Anim('content', {opacity: {to:1}}, .5, YAHOO.util.Easing.easeOut);
		content.animate();
		var submenu = new YAHOO.util.Anim($$('.cs_list_menu'), {top: {to:2}, opacity: {to: .8}}, 1.5, YAHOO.util.Easing.easeBothStrong);
		var subcontent = new YAHOO.util.Anim('subcontent_div', {top: {to:4}, opacity: {to: .8}}, 1.5, YAHOO.util.Easing.easeBothStrong);
		 var vScroller = new YAHOO.Scroller("subcontent_div",{type:"vertical",content:"subcontent"});
		submenu.animate();
		
		
		
		subcontent.animate();
		
		//fc_tb_init('a.foxycart');
		//fc_tb_init('form.foxycart');
			
	},

	handleFailure:function(o){
	
	},

	processResult:function(o){
	},

	startRequest:function(mode, action) {
				YAHOO.util.Connect.asyncRequest('GET', 'page.php?page=Shopping Cart&item=' + mode + '&session='+sessionID, cartCallBack, "");
				
	}

};

var cartCallBack =
{
	success:cartAjax.handleSuccess,
	failure:cartAjax.handleFailure,
	scope: cartAjax
};


function clearMenuHLs() {
			var last = lastSection.replace(/ /g, '');
			last = last.replace(/'/g, '');
			
			var el = $$('a.'+last);

			$.setStyle(el[0], 'display', 'block');
			var next = new YAHOO.util.Anim('cs_site_menu_item_'+currentId, {opacity: {to:1}}, .4, YAHOO.util.Easing.easeOut);
			next.animate();

}

function selectDetail(id){

	var details = $$('.wine_details > div');
	
	
	
	for (x = 0; x < details.length; ++x) {
		
		if (details[x].id == id) {
			var bright = new YAHOO.util.ColorAnim('dm_'+details[x].id, {backgroundColor: {to: '#EADCC8'}}, .1);
			bright.animate();
			var bright = new YAHOO.util.ColorAnim(details[x].id, {backgroundColor: {to: '#EADCC8'}}, .1);
			bright.animate();
			var next = new YAHOO.util.Anim(details[x].id, {opacity: {to:1}}, .4, YAHOO.util.Easing.easeOut);
			YAHOO.util.Dom.setStyle(details[x].id, 'visibility', 'visible');
			YAHOO.util.Dom.setStyle(details[x].id, 'z-index', '10');
			next.animate();
		}
		else
		{
			var bright = new YAHOO.util.ColorAnim('dm_'+details[x].id, {backgroundColor: {to: '#F5F5DC'}}, .1);
			YAHOO.util.Dom.setStyle(details[x].id, 'z-index', '0');
			var next = new YAHOO.util.Anim(details[x].id, {opacity: {to:0}}, .1, YAHOO.util.Easing.easeOut);
			next.animate();
			bright.animate();
		}
		
	}
	
}





function Unhighlight(el){
	var bright = new YAHOO.util.ColorAnim(el, {backgroundColor: {to: '#968D6C'}}, .1);
	bright.animate();
	
}


function Highlight(el){
	var dark = new YAHOO.util.ColorAnim(el, {backgroundColor: {to: '#A59C72'}}, .6);
	dark.animate();
	
}


function noclick(){

	return false;
}





var html, lastSection = '', lastSubsection, bookmarkedSection, bookmarkedSubsection, currentSection, currentSubsection, querySection, querySubsection, initSection, initSubsection, currentId;
  var anchors, i, len, href, section, subsection, subLinks, iconLinks, anchor, iconLink, subLink;

function loadSubsection(content) {
	
	//alert(content);
	if(content!=''){
	subContentAjax.startRequest('cs_copy', content, true);
	}
	
}


function loadSection(content){
		

	if (content=="Shopping Cart")
	{
		cartAjax.startRequest(content, '');		
	}
	else
	{
		AjaxObject.startRequest(content);
	}
	
	
	
	if (content == defaultPageState){
		if (polaroidCount == 1) {
			initPolaroid();
			polaroid.animate();
			polaroidState = "visible";
		}
	}

		if (content !== initialPageState) {
			clearPolaroid();

		}

	var menuclass = content.replace(/ /g, '');
	
	menuclass = menuclass.replace(/'/g, "");
	
	
}

var newState = '', newItemState, currentState, currentItemState, initialPageState, bookmarkedPageState, queryPageState, polaroidCount;

events.onDOMReady(function(){
		
		//alert('hello');
		
		
		/*initNavHistory2();
				
		blank();
		initPolaroid();
		flirInit();
		flirMenu();
		flirTitle();
		initStyles();
		initSideBars();
		
		attachBehaviors();	
		
		
		if (initialPageState == defaultPageState || initialPageState == ''){
			showSplash();
			setTimeout('places()', 9200);
			setTimeout('polaroid.animate()', 9200);
			setTimeout('loadPage()', 9200);
			polaroidState = "visible";
			polaroidCount = 1;
		}
		else
		{
			places();
			loadPage();
		}
		
		*/
		
	});




function initNavHistory2() {



    var today = new Date();
    defaultPageState = "About Us";
    bookmarkedPageState = YAHOO.util.History.getBookmarkedState("page");
	queryPageState = YAHOO.util.History.getQueryStringParameter("page");
	
    initialPageState = bookmarkedPageState || queryPageState || defaultPageState;
	var queryItemState = YAHOO.util.History.getQueryStringParameter("item");
    var bookmarkedItemState = YAHOO.util.History.getBookmarkedState("item");
	
    var initialItemState = bookmarkedItemState || queryItemState || "";
	
	
	
    var page;
    var sub;

	if (newState == '')
	{
		newState = initialPageState;
		newItemState = initialItemState;
		
		loadSection(newState);
		loadSubsection(newItemState);
	}

    YAHOO.util.History.register("page", initialPageState, function (state) {
    	loadSection(state);
		currentItemState = YAHOO.util.History.getCurrentState("item");
		if (newItemState !== currentItemState) {
						YAHOO.util.History.navigate("item", newItemState);
					}
	});

    YAHOO.util.History.register("item", initialItemState, function (state) {
	
        loadSubsection(state);
    });

	YAHOO.util.History.register("step", "", function (step) {
		if (step !== "") {
        checkoutAjax.startRequest(step);
		}
    });

    function handleItemChange (e) {
        var newState, currentState;

        newState = e;

        try {
            currentState = YAHOO.util.History.getCurrentState("item");
            if (newState != currentState) {
                YAHOO.util.History.navigate("item", newState);
            }
        } catch (e) {
           loadSubsection(newState);
        }
    }
	
    YAHOO.util.History.onReady(function () {
		
		
		
		
        var currentPageState;

        currentPageState = YAHOO.util.History.getCurrentState("page");
         initPageChangers();
	   initSubChangers();
	   initCheckoutLinks();
        currentItemState = YAHOO.util.History.getCurrentState("item");
	   
        
    });
    try {
		
        YAHOO.util.History.initialize("yui-history-field", "yui-history-iframe");
    } catch (e) {
	    
       initPageChangers();
	   initSubChangers();
    }

}
    function initPageChangers() {
        	
			
			
			var anchors = $$('a.nav_item');
			//alert(anchors.length);
			for (i = 0, len = anchors.length; i < len; i++) {
			
			
            anchor = anchors[i];
            YAHOO.util.Event.addListener(anchor, "click", function (evt) {
                href = this.getAttribute("href");
				currentId = this.id.replace('cs_site_menu_item_', '');
                newState = YAHOO.util.History.getQueryStringParameter("page", href) || "about us";
				newItemState = YAHOO.util.History.getQueryStringParameter("item", href) || "";
				try {
					currentState = YAHOO.util.History.getCurrentState("page");
					//currentItemState = YAHOO.util.History.getCurrentState("item");
					if (newState !== currentState) {
						YAHOO.util.History.navigate("page", newState);
					}
					
				} catch (e) {
					loadSection(newState);
		
				}
                YAHOO.util.Event.preventDefault(evt);
            });
        }
    }
function initSubNav() {
        	
			//alert('hello');
			
			sublinks = $$('a.cs_list_menu_item');
			//alert(sublinks.length);
			
			for (i = 0, len = sublinks.length; i < len; i++) {
			
            sublink = sublinks[i];
		//  alert(sublink.href);
            YAHOO.util.Event.addListener(sublink, "click", function (evt) {
                href = this.getAttribute("href");
			
				currentId = this.id.replace('cs_list_menu_item', '');
				newItemState = YAHOO.util.History.getQueryStringParameter("item", href) || "";
				try {
					currentItemState = YAHOO.util.History.getCurrentState("item");
					if (newItemState !== currentItemState) {
						YAHOO.util.History.navigate("item", newItemState);
					}
					
				} catch (e) {
					loadSubsection(newItemState);
		
				}
                YAHOO.util.Event.preventDefault(evt);
            });
        }
    }
    
    function initTextLinks() {
        	
			
			
			var textlinks = $$('#subcontent_div p a, .text_link');
			//alert(textlinks.length);
			for (i = 0, len = textlinks.length; i < len; i++) {
			
			
            textlink = textlinks[i];
            YAHOO.util.Event.addListener(textlink, "click", function (evt) {
                href = this.getAttribute("href");
				
                newState = YAHOO.util.History.getQueryStringParameter("page", href);
				newItemState = YAHOO.util.History.getQueryStringParameter("item", href);
				try {
					currentState = YAHOO.util.History.getCurrentState("page");
					currentItemState = YAHOO.util.History.getCurrentState("item");
					if (newState !== currentState) {
						YAHOO.util.History.navigate("page", newState);
					}
					
				} catch (e) {
					loadSection(newState);
		
				}
                YAHOO.util.Event.preventDefault(evt);
            });
        }
    }
    
        function initTextSubLinks() {
        	
			
			
			var textsublinks = $$('.sub_nav_text');
			//alert(textlinks.length);
			for (i = 0, len = textsublinks.length; i < len; i++) {
			
			
            textsublink = textsublinks[i];
            YAHOO.util.Event.addListener(textsublink, "click", function (evt) {
                href = this.getAttribute("href");
				
               // newState = YAHOO.util.History.getQueryStringParameter("page", href);
				newItemState = YAHOO.util.History.getQueryStringParameter("item", href);
				try {
					//currentState = YAHOO.util.History.getCurrentState("page");
					currentItemState = YAHOO.util.History.getCurrentState("item");
					if (newItemState !== currentItemState) {
						YAHOO.util.History.navigate("item", newItemState);
					}
					
				} catch (e) {
					loadSubsection(newItemState);
		
				}
                YAHOO.util.Event.preventDefault(evt);
            });
        }
    }

var checkoutForm = "";

    function initCheckoutLinks() {
        	
			//alert('hello');
			
			var forms = $$('form.checkout');
			//alert(forms.length);
			for (i = 0, len = forms.length; i < len; i++) {
			
			
            form = forms[i];
            YAHOO.util.Event.addListener(form, "submit", function (evt) {
                action = this.getAttribute("action");
			 nextStep = action.replace('.php', '');
				try {

						
						
						var check = FIC_checkForm(this);
						//alert(check + ' ' + action + ' ' + nextStep);
						//var check = true;
						if (check)
						{
							
							//var myobj = {form:this, step:nextStep};
							//alert (myobj.form.id);
							checkoutForm = this;
							YAHOO.util.History.navigate("step", nextStep);
						}
					
				} catch (e) {
					//loadSection(newState);
		
				}
                YAHOO.util.Event.preventDefault(evt);
            });
        }
    }


function ClickHereToPrint(){

	var whatever = document.getElementById('cs_content').innerHTML;
	var win = window.open('', '', 'width=600,height=800');
	win.document.open();
	win.document.write("<body onload='self.print();'>" + whatever + "</body>");
	//win.document.close();
	//win.focus();
	return false;
	
}


function cardType(number) {

//alert(number);

document.getElementById('inp_card').value=number.substr(number.length-4);
var ctype; 

switch (number.substr(0, 1)) { 
	case '4':  ctype='visa';  cardmsg = '<img class="card_type_thumb" src="cs-content/images/cc_'+ctype+'_sm.png\" />';
	break; 
	case '5':  ctype='mastercard';  cardmsg = '<img class="card_type_thumb" src="cs-content/images/cc_'+ctype+'_sm.png\" />';
	break; 
	case '6':  ctype='discover';  cardmsg = '<img class="card_type_thumb" src="cs-content/images/cc_'+ctype+'_sm.png\" />';
	break; 
	case '3':  ctype='amex';  cardmsg = '<img class="card_type_thumb" src="cs-content/images/cc_'+ctype+'_sm.png\" />';
	break;   
	default:
	cardmsg = '16 digits, no spaces or dashes';
}
	//alert(cardmsg);
	document.getElementById('inp_card_type').value = ctype;
	document.getElementById('card_tip').innerHTML = cardmsg;
}
