/*
********************************************************************************
* 
* EVENTHANDLER.JS
* Plore: Event Handler with Cache
* 
* v2.0 (March 2011)
* 
********************************************************************************
*/


/*
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
EVENTCACHE + ADDEVENT + HOOK/UNHOOK
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
*/
var EventCache=function(){var listEvents=[];return{listEvents:listEvents,add:function(node,sEventName,fHandler,bCapture){listEvents.push(arguments)},flush:function(){var i,item;for(i=listEvents.length-1;i>=0;i=i-1){item=listEvents[i];if(item[0].removeEventListener){item[0].removeEventListener(item[1],item[2],item[3])};if(item[1].substring(0,2)!="on"){item[1]="on"+item[1]};if(item[0].detachEvent){item[0].detachEvent(item[1],item[2])};item[0][item[1]]=null}}}}();function addEvent(obj,type,fn){if(obj.addEventListener){obj.addEventListener(type,fn,false);EventCache.add(obj,type,fn)}else if(obj.attachEvent){obj["e"+type+fn]=fn;obj[type+fn]=function(){obj["e"+type+fn](window.event)};obj.attachEvent("on"+type,obj[type+fn]);EventCache.add(obj,type,fn)}else{obj["on"+type]=obj["e"+type+fn]}};addEvent(window,'unload',EventCache.flush);function addLoadEvent(func){var oldonload=window.onload;if(typeof window.onload!='function'){window.onload=func}else{window.onload=function(){oldonload();func()}}};function hookEvent(e,m,f){if(e=$E(e)){if(e.addEventListener){if(m=='mousewheel'){e.addEventListener('DOMMouseScroll',f,false)}e.addEventListener(m,f,false);return e}else if(e.attachEvent){e.attachEvent("on"+m,f);return e}}return};function unhookEvent(e,m,f){if(e=$E(e)){if(e.removeEventListener){if(m=='mousewheel'){e.removeEventListener('DOMMouseScroll',f,false)}e.removeEventListener(m,f,false);return e}else if(e.detachEvent){e.detachEvent("on"+m,f);return e}}return};function cancelEvent(e){if(e=e?e:window.event){if(e.stopPropagation)e.stopPropagation();if(e.preventDefault)e.preventDefault();e.cancelBubble=true;e.cancel=true;e.returnValue=false}return false};


var $Plore,
	$PloreSlide,
	$slider,
	PloreModuleSlideControls,
	PloreModuleSlide,
	$f;


$f=
{
	/*
	IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
	CSS
	IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
	*/
	css :
	{
		/*
		IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
		CSS : string toJs(attribue: String)
		IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
		*/
		toJs : function(a)
		{
			if (a = a.replace(/\s/g,'').toLowerCase().split(''))
			{
				var i = 0,
					n = 0,
					l = a.length;
				
				do
				{
					if (a[i] == '-')
					{
						if (i < l)
						{
							a[n=i+1] = a[n].toUpperCase()
						}
						
						a[i] = ''
					}
				}
				while (++i < l);
				
				if (/^[a-z]+$/i.test(a = a.join('')))
				{
					return a
				}
			}
			
			return
		},
		
		
		/*
		IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
		CSS : string get(element: Mixed, attribute: String)
		IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
		*/
		get : function(e,a)
		{
			if (e = typeof e === 'object' ? e : $E(e))
			{
				if (e.currentStyle) return e.currentStyle[a];
				else
				{
					if (window.getComputedStyle)
					{
						return document
							.defaultView.getComputedStyle(e,null)
							.getPropertyValue(a)
					}
				}
			}
			
			return
		},
		
		
		/*
		IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
		CSS : element apply(element: Mixed, style: String)
		IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
		*/
		apply : function(e,c)
		{
			if (e = typeof e === 'object' ? e : $E(e))
			{
				var a = c.split(';'),
					i = 0,
					u = 0,
					l = a.length,
					f = $f.css.toJs,
					k,
					v;
				
				while (i < l)
				{
					if (/([a-z]+(\-[a-z]+)*)\s*:\s*(.*)/i.test(a[i++]))
					{
						k = RegExp.$1;
						v = RegExp.$3;
						
						if (k = f(k))
						{
							e.style[k] = v;
							
							u++
						}
					}
				}
				
				return e
			}
			
			return
		},
		
		
		/*
		IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
		CSS : bool hasClassName(element: Mixed, classname: String)
		IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
		*/
		hasClassName : function(e,c)
		{
			if (e = typeof e === 'object' ? e : $E(e))
			{
				if (
				  c != null
				  && /\S/.test(c)
				  && new RegExp(
						'^(.*\\s)?'+c.replace(/-/g,'\\-')+'(\\s.*)?$'
						).test(e.className))
				{
					return true
				}
			}
			
			return
		}
	},
	
	
	get :
	{
		/*
		IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
		GET : array pos(element: Mixed[, relative_to: Mixed])
		IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
		*/
		pos : function(e,r)
		{
			if (e = typeof e === 'object' ? e : $E(e))
			{
				var x = 0,
					y = 0;
				
				if (e.offsetParent)
				{
					do
					{
						x += e.offsetLeft;
						y += e.offsetTop;
					}
					while (e = e.offsetParent);
				}
				
				if (
				  r != null
				  && (typeof r === 'object' || (r = $E(r))))
				{
					{
						var xyo = $f.get.pos(r)
					}
					
					x -= xyo[0];
					y -= xyo[1];
				}
				
				return [x,y]
			}
			
			return
		},
		
		
		/*
		IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
		GET : array sizeOf(element: Mixed)
		IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
		*/
		sizeOf : function(e)
		{
			if (e = typeof e === 'object' ? e : $E(e))
			{
				return [e.offsetWidth, e.offsetHeight]
			}
			
			return
		},
		
		
		/*
		IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
		GET : mixed opacityOf(
			element: Mixed
			[, return_decimal: Boolean]
			)
		IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
		*/
		opacityOf : function(e,d)
		{
			var sty = $f.css.get(e,isIE?'filter':'opacity'),
				max = 100;
			
			if (
			  sty != null
			  && /\S/.test(sty))
			{
				if (isIE)
				{
					var n = /opacity=(\d+)/i.test(sty)
					  ? parseInt(RegExp.$1)
					  : max;
					
					return d
					  ? parseFloat(n/100)
					  : parseInt(n)
				}
				
				return !d
				  ? parseInt(sty*100)
				  : parseFloat(sty);
			}
			
			return d
			  ? parseFloat(max/100)
			  : parseInt(max)
		}
	},
	
	
	set :
	{
		/*
		IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
		SET : mixed pos(
			element: Mixed,
			[x: Integer][, y: Integer],
			[relative_to: Mixed][, return_position: Boolean]
			)
		IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
		*/
		pos : function(e,xpos,ypos,r,bReturn)
		{
			if (e = typeof e === 'object' ? e : $E(e))
			{
				var gp = $f.get.pos;
				
				if (
				  xpos == null
				  || ypos == null)
				{
					{
						var oxy = gp(e)
					}
					
					if (xpos == null) xpos = oxy[0];
					if (ypos == null) ypos = oxy[1];
				}
				
				if (
				  r != null
				  && (typeof r === 'object' || (r = $E(r))))
				{
					{
						var xyo = gp(r)
					}
					
					xpos += xyo[0];
					ypos += xyo[1];
				}
				
				e.style.left = xpos+'px';
				e.style.top  = ypos+'px';
				
				return bReturn ? gp(e) : e
			}
			
			return
		},
		
		
		/*
		IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
		SET : mixed opacity(
			element: Mixed, value: Integer,
			[return_opacity: Boolean]
			)
		IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
		*/
		opacity : function(e,n,ro)
		{
			if (e = typeof e === 'object' ? e : $E(e))
			{
				n = parseInt(n);
				n = n < 0 ? 0 : (n > 100 ? 100 : n);
				
				if (isIE) e.style.filter = 'alpha(opacity='+n+')';
				else e.style.opacity = n/100;
				
				return ro
				  ? $f.get.opacityOf(e)
				  : e
			}
			
			return
		}
	}
};


Array.prototype.inArray = function (value)
{
	for (var i=0,il=this.length;i<il;i++)
	{
		if (this[i] === value)
		{
			return true
		}
	}
	
	return false
};

/*function FixMyHome()
{
	this.Forms = ['product_addtocart_form_2839','product_addtocart_form_2843'];
};
*/

/*
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
mixed $E(element: Mixed[, return: mixed Function(Element)][, document: Object])
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
*/
function $E(e,r,d)
{
	if (
	  typeof e === 'object'
	  || (e = (d?d:document).getElementById(e)))
	{
		return r ? r(e) : e
	}
	
	return
};


/*
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
objects $C(
	string class
	[, string tag][, object container]
	)
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
*/
function $C(strClass,strTag,objContElm)
{
	strTag=strTag||"*";
	objContElm=objContElm||document;
	var objColl=objContElm.getElementsByTagName(strTag);
	if (!objColl.length&&strTag=="*"&&objContElm.all) objColl=objContElm.all;
	var arr=new Array();
	var delim=strClass.indexOf('|')!=-1?'|':' ';
	var arrClass=strClass.split(delim);
	for (var i=0,j=objColl.length;i<j;i++)
	{
		var arrObjClass=objColl[i].className.split(' ');
		if (delim==' ' && arrClass.length>arrObjClass.length) continue;
		var c=0;
		comparisonLoop:
		for (var k=0,l=arrObjClass.length;k<l;k++)
		{
			for (var m=0,n=arrClass.length;m<n;m++)
			{
				if (arrClass[m]==arrObjClass[k]) c++;
				if ((delim=='|'&&c==1) || (delim==' '&&c==arrClass.length))
				{
					arr.push(objColl[i]);
					break comparisonLoop
				}
			}
		}
	}
	return arr
};


/*
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
string $GET_HTTP_VAR(
	[object document],
	string name_of_variable[, string url]
	[, bool case_sensitive]
	)
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
*/
function $GET_HTTP_VAR()
{
	if (typeof(arguments[0])=='object')
	{
		var Document	= arguments[0];
		var Name		= arguments[1];
		var Url			= arguments[2]?arguments[2]:Document.location.href;
		var bCS			= arguments[3]?true:false;
	}
	else
	{
		var Document	= document;
		var Name		= arguments[0];
		var Url			= arguments[1]?arguments[1]:Document.location.href;
		var bCS			= arguments[2]?true:false;
	}
	
	var rx="/\\b"+Name+"\\b=([^&#]*)/"+(bCS?"":"i");
	return eval(rx).test(Url)?RegExp.$1:""
};




/*
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
COOKIE
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
*/
$cookie =
{
	/*
	IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
	COOKIE : string Make(name: String[, value: Mixed][, days: Integer])
	IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
	*/
	Make : function(k,v,d)
	{
		if (document.cookie)
		{
			if (d)
			{
				var today=new Date();
					today.setTime(today.getTime()+(d*24*60*60*1000));
				
				var until = ';expires='+today.toGMTString()
			}
			else
			{
				var until = ""
			}
			
			return document.cookie = k+'='+v+until+';path=/'
		}
		
		return
	},
	
	
	/*
	IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
	COOKIE : string Read(name: String)
	IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
	*/
	Read : function(k)
	{
		if (document.cookie)
		{
			var nameEQ = k+'=',
				ca = document.cookie.split(';'),
				i = 0,
				l = ca.length,
				c;
			
			while (i < l)
			{
				c = ca[i++];
				
				while (c.charAt(0) == ' ')
				{
					c = c.substring(1,c.length)
				}
				
				if (c.indexOf(nameEQ) == 0)
				{
					return c.substring(
						nameEQ.length,
						c.length
						);
				}
			}
		}
		
		return
	},
	
	
	/*
	IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
	COOKIE : bool Kill(name: String)
	IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
	*/
	Kill : function(k)
	{
		if (document.cookie)
		{
			{
				createCookie(k,"",-1)
			}
			
			return true
		}
		
		return
	}
};



/*
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
*/


/*
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
class PloreModuleSlideControls(PloreModuleSlide: Class)
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
*/
PloreModuleSlideControls = function(slide)
{
	{
		this.app = slide
	}
	
	if (
	  this.app
	  && this.app.bag.length)
	{
		this.def = {
			min_opacity : 0,
			max_opacity : 0.85
			};
		
		if (this.layer	= $E(this.app.container.id+'_ctrl'))
		{
			this.bag	= this.layer.getElementsByTagName('img');
			this.size	= $f.get.sizeOf(this.layer);
			
			this.init()
		}
	}
};

PloreModuleSlideControls.prototype.init = function()
{
	{
		this.layer._app = this
	}
	
	this.layer.Blur = new Animator(
		{
			onComplete : new Function(
				  "var e=$E('"+this.layer.id+"');"
				+ "if($f.get.opacityOf(e)==0)e.style.visibility='hidden';"
				+ "else void(0);"
				)
		}
		)
		.addSubject(
			new NumericalStyleSubject(
				this.layer,
				'opacity',
				this.def.max_opacity,
				this.def.min_opacity
				)
		);
	
	var e = this.app.bag,
		i = 0,
		l = e.length,
		o;
	
	do
	{
		if (o = e[i])
		{
			addEvent(
				o, 'mouseover',
				function()
				{
					this._app.ctrl.show()
				}
				);
			
			addEvent(
				o, 'mouseout',
				function()
				{
					this._app.ctrl.hide()
				}
				);
		}
	}
	while (++i < l);
	
	addEvent(this.layer,'mouseover',function(){this._app.show()});
	addEvent(this.layer,'mouseout',function(){this._app.hide()});
	addEvent(window,'resize',new Function(this.app.caller+".ctrl.repos()"));
	
	this.repos();
	this.layer.Blur.play();
	this.finalize();
};

PloreModuleSlideControls.prototype.finalize = function()
{
	var e = this.bag,
		i = 0,
		l = e.length,
		s;
	
	while (i < l)
	{
		o = this.bag[i];
		s = this.app.bag[i++];
		
		if (s)
		{
			o.onclick = new Function(
				this.app.caller+".select("+i+")"
				);
		}
	}
};

PloreModuleSlideControls.prototype.repos = function()
{
	$f.set.pos(
		this.layer,
		0,
		this.app.size[1]-this.size[1],
		this.app.container
		);
};

PloreModuleSlideControls.prototype.show = function()
{
	{
		this.layer.style.visibility = 'visible'
	}
	
	this.layer.Blur.seekTo(0,1)
};

PloreModuleSlideControls.prototype.hide = function()
{
	this.layer.Blur.seekTo(1,0)
};


/*
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
*/


/*
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
class PloreModuleSlide(
	container: Element, varname: String,
	[configuration: {
		delay		> milliseconds: Integer
		interval	> milliseconds: Integer
		}]
	)
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
*/
PloreModuleSlide = function(container,caller,c)
{
	if (this.container = $E(container))
	{
		var k,
			m;
		
		this.def = {
			delay			: 1000,
			interval		: 3000,
			zIndex			: 1000,
			suffix			: '_slide',
			onmouseover		: null,
			onmouseout		: null,
			auto_startstop	: false,
			
			animation : {
				duration : 1000
				}
			};
	}
	else return;
	
	if (this.cfg = this.configure(c))
	{
		this.calls		= 0;
		this.caller		= caller;
		this.timer		= null;
		
		this.FadeOut	= function(o){if(o=$E(o)){o.style.zIndex=1000;o.Blur.play()}};
		this.FadeIn		= function(o){if(o=$E(o)){o.style.zIndex=1001;o.Blur.reverse()}};
		this.stop		= function(){clearInterval(this.timer);this.timer=null};
		this.start		= function(){if(!this.timer)return this.timer=setInterval(this.caller+".next()",this.cfg.interval)};
		
		this.bag	= $C(this.container.id+c.suffix,'div',document);
		this.max	= this.bag.length;
		this.cur	= 1;
		this.size	= $f.get.sizeOf(this.container);
		this.ctrl	= null;
		
		this.init()
	}
};


PloreModuleSlide.prototype.select = function(n)
{
	if (this.bag[n-1])
	{
		{
			this.stop()
		}
		
		var selected	= this.bag[n-1],
			i			= 0,
			l			= this.bag.length,
			sop			= $f.set.opacity,
			o;
		
		while (o = this.bag[i++])
		{
			if (o._number != selected._number)
			{
				o.style.zIndex = 1000;
				o.style.visibility = 'hidden';
				sop(o,0);
			}
		}
		
		selected.style.visibility = 'visible';
		sop(selected,100);
		selected.style.zIndex = 1001;
		
		this.cur = n
	}
};


/*
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
object PloreModuleSlide.configure([configuration: Object])
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
*/
PloreModuleSlide.prototype.configure = function(c)
{
	var k,
		v,
		o;
	
	if (typeof c !== 'object') c = this.def;
	else
	{
		for (k in this.def)
		{
			if (c[k] == null)
			{
				c[k] = this.def[k]
			}
		}
	}
	
	if (typeof c === 'object')
	{
		for (k in c)
		{
			switch (k)
			{
				case 'auto_startstop':
				if (c[k])
				{
					c.onmouseover = function()
					{
						var app = this._app;
						app.stop()
					};
					
					c.onmouseout = function()
					{
						var app = this._app;
						this._app.start();
					};
				}
				break;
			}
		}
		
		return c
	}
	
	return
}


/*
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
PloreModuleSlide.init([now: Boolean])
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
*/
PloreModuleSlide.prototype.init = function(now)
{
	if (
	  this.calls > 0
	  || this.finalize())
	{
		if (
		  !now
		  && this.cfg.delay > 0)
		{
			return setTimeout(
				this.caller+".init(true)",
				this.cfg.delay
				);
		}
		
		{
			this.ctrl = new PloreModuleSlideControls(this)
		}
		
		this.start();
		this.next();
	}
};


/*
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
bool PloreModuleSlide.finalize()
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
*/
PloreModuleSlide.prototype.finalize = function()
{
	if (++this.calls > 1) return true;
	else
	{
		addEvent(
			window, 'resize',
			function()
			{
				$PloreSlide.repos()
			}
			);
		
		this.repos()
	}
	
	var bag		= this.bag,
		i		= 0,
		l		= bag.length,
		repos	= $f.set.pos,
		z		= this.cfg.zIndex,
		o;
	
	while (i < l)
	{
		if (o = bag[i++])
		{
			o.id			= this.container.id+'-'+i;
			o.style.zIndex	= z;
			o._number		= i;
			o._app			= this;
			
			var mouseover	= this.cfg.onmouseover;
			var mouseout	= this.cfg.onmouseout;
			
			o.Blur = new Animator(
				{
					onComplete : new Function(
						  "var e=$E('"+o.id+"');"
						+ "var n=e._number;"
						+ "var app=e._app;"
						+ "var previous=$E(e.id.replace(/\\d+/,n==1?"+l+":(n-1)));"
						+ "var last=$E(e.id.replace(/\\d+/,"+l+"));"
						+ "var op=$f.get.opacityOf;"
						
						+ "if(op(e)==0)e.style.visibility='hidden';"
						+ "else if (n == "+l+") {$f.set.opacity(previous,0);e.style.zIndex="+z+";previous.style.visibility='hidden'}"
						+ "else if (n >= 1) {app.FadeOut(previous);}"
						),
					
					duration : this.cfg.animation.duration
				}
				)
				.addSubject(
					new NumericalStyleSubject(
						o,
						'opacity',
						1,
						0
						)
				);
			
			if (mouseover) o.onmouseover = mouseover;
			if (mouseout) o.onmouseout = mouseout;
			
			o.Blur.play()
		}
	}
	
	return l > 0
};


/*
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
PloreModuleSlide.repos()
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
*/
PloreModuleSlide.prototype.repos = function()
{
	var bag		= this.bag,
		i		= 0,
		l		= bag.length,
		repos	= $f.set.pos;
	
	while (i < l)
	{
		repos(
			bag[i++],
			0,
			0,
			this.container
			);
	}
};


/*
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
PloreModuleSlide.next()
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
*/
PloreModuleSlide.prototype.next = function()
{
	if (this.cur > this.max)
	{
		this.cur = 1
	}
	
	this.show();
	this.cur++
};


/*
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
PloreModuleSlide.show()
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
*/
PloreModuleSlide.prototype.show = function()
{
	var layer = $E(
		this.container.id+'-'+this.cur
		);
	
	if ($f.get.opacityOf(layer) == 0)
	{
		layer.style.visibility = 'visible';
		this.FadeIn(layer);
	}
};


/*
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
PloreModuleSlide.hide()
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
*/
PloreModuleSlide.prototype.hide = function(layer)
{
	if ($f.get.opacityOf(layer) > 0)
	{
		this.FadeOut(layer)
	}
};


/*
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
*/


/*
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
MagHack v1.0
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
*/
$MagHack=
{
	/*
	IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
	bool isBlank(string)
	IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
	*/
	isBlank : function(str)
	{
		return (str==null || typeof(str)!='string' || !/\S/.test(str))
	},
	
	
	/*
	IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
	MagHack : Search
	IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
	*/
	Search :
	{
		form : null,
		menu : null,
		pr_1 : null,
		pr_2 : null,
		is_ready : false,
		
		
		/*
		IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
		MagHack : Search : bool init(string form_identifier)
		IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
		*/
		init : function(form_name) { with (this)
		{
			if ($E('search_form') || $E('search_form_tabless'))
			{ 
				if ($E('search_form'))
				{
					if (!this.is_ready)
					{
						this.c_id = $GET_HTTP_VAR('parent_idnumber');
						this.tabs = $E('search_form').getElementsByTagName('tr')[0].getElementsByTagName('img');
						this.lyrs = $C('hide_layer','div',$E('search_search_table'));
						this.p_id = $C('parent-idnumber','input');
						this.text = $C('query-input','input');
						
						for (var n=0;n<lyrs.length;n++)
						{
							var Layer				= lyrs[n];
								Layer.number		= n;
								Layer.tab			= tabs[Layer.number];
								Layer.idnumber		= $C('parent-idnumbers','input')[Layer.number].value;
								Layer.form			= $E('search_form').getElementsByTagName('form')[Layer.number];
								Layer.form.holder	= Layer;
								Layer.form.textbox	= n > 0 ? text[n-1] : null;
								Layer.Show			= function(){this.tab.onclick()};
								Layer.Hide			= function(){this.className="hide_layer"};
							
							
							if (Layer.form.textbox)
							{
								Layer.form.onsubmit=function() { with (this)
								{
									{
										textbox.onfocus = textbox.onblur = null
									}
									
									with (textbox)
									{
										if (value == special)
										{
											value = ""
										}
									}
									
									return true
								}
								};
							}
							
							Layer.idnumber == this.c_id
							  ? Layer.Show()
							  : void(0)
						}
						
						
						for (var n=0;n<text.length;n++)
						{
							var Phr			= text[n];
								Phr.number	= n;
								Phr.special	= 'Enter Keyword';
							
							Phr.onfocus=function(){with(this)if(value==special)value=""};
							Phr.onblur=function(){with(this)if(!/\w/.test(value))value=special};
						}
						
						if (c_id == "") lyrs[0].Show();
						this.is_ready = true;
					}
				}
				
				if ($E('search_form_tabless'))
				{
					if (!this.is_ready)
					{
						this.text 		= $C('query-input','input');
						this.textbox	= text[0];
						this.form		= $E('search_form_tabless').getElementsByTagName('form')[0];
						
						if (textbox)
						{
							form.onsubmit=function() { with (this)
							{
								{
									textbox.onfocus = textbox.onblur = null
								}
								
								with (textbox)
								{
									if (value == special)
									{
										value = ""
									}
								}
								
								return true
							}
							};
						}
						
						var Phr			= textbox;
							Phr.special	= 'Enter Keyword';
						
						Phr.onfocus=function(){with(this)if(value==special)value=""};
						Phr.onblur=function(){with(this)if(!/\w/.test(value))value=special};
						
					}	
				}
				
				if (form = $E(form_name))
				{
					form.menu = $C('predefined-price-ranges','select',form.parentNode)[0];
					form.pr_1 = $C('predefined-price-range-1','input',form.parentNode)[0];
					form.pr_2 = $C('predefined-price-range-2','input',form.parentNode)[0];
					
					{
						form.menu.app = form
					}
					
					form.menu.onchange=function() { with (this)
					{
						{
							var Range = options[selectedIndex].value.split('-')
						}
						
						app.pr_1.value = (Range[0] && !$MagHack.isBlank(Range[0])) ? Range[0] : "";
						app.pr_2.value = (Range[1] && !$MagHack.isBlank(Range[1])) ? Range[1] : "";
					}
					};
					
					form.menu.onchange()
				}
			}
			
			return
		}
		}
	}
};



		/*
		IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
		MagHack : LockSearch : bool evaluateUserInput(string form_identifier)
		IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
		*/
		
		function evaluateUserInput(searchForm)
		{
			with (searchForm)
			{
				switch (searchForm.id)
				{
					case "search_liquors_form": 	
					
						//check if at least one fields is selected
						if ( searchForm.price_range_liquors.value!="" 	|| 
							 searchForm.category.value!=12 				|| 
							 searchForm.kosher.value!="" 	  			|| 
							 searchForm.organic.value!=""  				||
							(searchForm.name.value!="" && searchForm.name.value!="Enter Keyword"))
						{
							//check if Type is selected
							if 	(searchForm.category.value!=12)
							{	//check if at least one more field is chosen in addition to Type
								if  (searchForm.price_range_liquors.value!="" 	|| 
									 searchForm.kosher.value!="" 				|| 
									 searchForm.organic.value!=""				|| 
									(searchForm.name.value!="" && searchForm.name.value!="Enter Keyword"))
								{
									/*alert("submit now");*/
									return true;
								}
								else //if type is chosen but no other field then display error message and do NOT submit form
								{
									alert("Please specify at least one search criteria in addition to type\n\nIf you wish to search by type only, please use the navigation bar at the top of the screen");
									return false;
								}
							}//search criteria is chosen but it is NOT Type, submit form
							/*alert("submit now");*/
							return true;
						}
						//if nothing is selected display message, do NOT submit form
						else
						{
							alert("Please specify at least one search criteria");
							return false;
						}
						break;
						
					case "search_wines_form":
						
						//check if at least one fields is selected
						if ( searchForm.price_range_wines.value!=""	|| 
							 searchForm.category.value!=8 			||
							 searchForm.country.value!=""			||
							 searchForm.grape_type.value!=""		||
							 searchForm.kosher.value!="" 	  		|| 
							 searchForm.organic.value!=""  			||
							(searchForm.name.value!="" && searchForm.name.value!="Enter Keyword"))
						{
							//check if Type is selected
							if 	(searchForm.category.value!=8)
							{	//check if at least one more field is chosen in addition to Type
								if  (searchForm.price_range_wines.value!=""	|| 
									 searchForm.country.value!=""			||
									 searchForm.grape_type.value!=""		||
									 searchForm.kosher.value!="" 			|| 
									 searchForm.organic.value!=""			|| 
									(searchForm.name.value!="" && searchForm.name.value!="Enter Keyword"))
								{
									/*alert("submit now");*/
									return true;
								}
								else //if type is chosen but no other field then display error message and do NOT submit form
								{
									alert("Please specify at least one search criteria in addition to type\n\nIf you wish to search by type only, please use the navigation bar at the top of the screen");
									return false;
								}
							}//search criteria is chosen but it is NOT Type, submit form
							/*alert("submit now");*/
							return true;
						}
						//if nothing is selected display message, do NOT submit form
						else
						{
							alert("Please specify at least one search criteria");
							return false;
						}
						break;
				}
			}
			
		}
		




/*
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
*/

function $reallyLoad(bNow)
{
	if (!bNow)
	{
		return setTimeout("$reallyLoad(true)",1000);
	}
	else
	{
		$MagHack.Search.init('search_wines_form');
		$MagHack.Search.init('search_liquors_form');
		
		var $Sliders=
		{
			Bag :
			[
				document.getElementById('my-slider1'),
				document.getElementById('my-slider2'),
				document.getElementById('my-slider3')
			]
		};
		
		if ($Sliders.Bag[0])
		{
			for (var n=0;n<$Sliders.Bag.length;n++)
			{
				$Sliders.Bag[n].onmousemove = function(e)
				{
					Mouse.refresh(e)
				};
			}
			
			loadSliders()
		}
	}
};


/*
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
*/


function loadSliders()
		//window.onload = function()
{		
	var radiosValue = document.getElementsByName('ratings[2]');
	var radiosQuality = document.getElementsByName('ratings[1]');
	var radiosPrice = document.getElementsByName('ratings[3]');
	
	new Slider('my-slider1', 
	{
		steps: 200, 
		snapping: false,
		callback: function(value)
		
		{
			value = value * 10 ;
			value = Math.round(value);
			if (value < 1) 
			{ 
				value = 1; 
			}
			radiosValue[value-1].click()
			//document.getElementById('score1').innerHTML = value;
		}
	});
				
	
	
	new Slider('my-slider2', 
	{
		steps: 200, 
		snapping: false,
		callback: function(value)
		
		{
			value = value * 10 ;
			value = Math.round(value);
			if (value < 1) 
			{ 
				value = 1; 
			}
			radiosQuality[value-1].click()
			//document.getElementById('score2').innerHTML = x;
		}
	});
	new Slider('my-slider3', 
	{
		steps: 200, 
		snapping: false,
		callback: function(value)
		
		{
			value = value * 10 ;
			value = Math.round(value);
			if (value < 1) 
			{ 
				value = 1; 
			}
			radiosPrice[value-1].click()
			//document.getElementById('score3').innerHTML = x;
		}
	});
};



/*
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
$getPos(element)
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
*/
function $getPos(e)
	{
		var o = e;
		
		var x = y = 0;
		
		if (o.offsetParent)
		{
			x = o.offsetLeft;
			y = o.offsetTop;
			
			while (o = o.offsetParent)
			{
				x += o.offsetLeft;
				y += o.offsetTop;
			}
		}
		
		return [x,y]
	};

/*
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
$setPos(element)
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
*/
/*function $setPos(xy, box)
	{
		
		
	};*/
	
	
/*
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
$setVis(object,status, bool doFade)
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
*/
function $setVis(obj,status)
	{
		obj.style.visibility = status ? "visible" : "hidden"
	}






/*
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
$fade(elementID)
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
*/
var  TimeToFade = 300.0;

function fade(eid)
{
  var element = document.getElementById(eid);
  if(element == null)
    return;
   
  if(element.FadeState == null)
  {
    if(element.style.opacity == null
        || element.style.opacity == ''
        || element.style.opacity == '1')
    {
      element.FadeState = 2;
    }
    else
    {
      element.FadeState = -2;
    }
  }
   
  if(element.FadeState == 1 || element.FadeState == -1)
  {
    element.FadeState = element.FadeState == 1 ? -1 : 1;
    element.FadeTimeLeft = TimeToFade - element.FadeTimeLeft;
  }
  else
  {
    element.FadeState = element.FadeState == 2 ? -1 : 1;
    element.FadeTimeLeft = TimeToFade;
    setTimeout("animateFade(" + new Date().getTime() + ",'" + eid + "')", 33);
  }  
}



/*
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
$animateFade(lastTick,elementID)
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
*/
function  animateFade(lastTick, eid)
{  
  var curTick = new Date().getTime();
  var elapsedTicks = curTick - lastTick;
 
  var element = document.getElementById(eid);
 
  if(element.FadeTimeLeft <= elapsedTicks)
  {
    element.style.opacity = element.FadeState == 1 ? '1' : '0';
    element.style.filter = 'alpha(opacity = '
        + (element.FadeState == 1 ? '100' : '0') + ')';
    element.FadeState = element.FadeState == 1 ? 2 : -2;
    return;
  }
 
  element.FadeTimeLeft -= elapsedTicks;
  var newOpVal = element.FadeTimeLeft/TimeToFade;
  if(element.FadeState == 1)
    newOpVal = 1 - newOpVal;

  element.style.opacity = newOpVal;
  element.style.filter = 'alpha(opacity = ' + (newOpVal*100) + ')';
 
  setTimeout("animateFade(" + curTick + ",'" + eid + "')", 33);
}


/*
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
ONLOAD
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
*/
window.addEventListener
  ? window.addEventListener("load",$init_MagHack,false)
  : window.attachEvent("onload",$init_MagHack);





/*
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
$checkAgreement(checkboxId)
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
*/
	function checkAgreement(checkboxId)
	{
		var agreementCheckbox = document.getElementById(checkboxId);
		if (agreementCheckbox.checked == true)
		{
			return true;
		}
		else
		{
			alert ("You must agree to the terms and conditions first");
			return false;
		}
	}



/*
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
*/


/*
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
class BottleSlider(container_id: String | container: Element)
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
*/
function BottleSlider(container)
{
	if (this.container = $E(container))
	{
		this.dir			= '';
		this.newPosition	= 0;
		this.numbOfItems	= $C('item','td',this.container).length;
		this.timer;
		
		{
			this.container.app = this
		}
	}
};


/*
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
BottleSlider.rotate(direction: String, column_width: Integer)
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
*/
BottleSlider.prototype.rotate = function(dir,colWidth)
{
	if (this.dir = dir)
	{
		var curPosition = this.newPosition;
		
		if (dir == 'L')
		{
			if (curPosition < 0)
			{			
				this.newPosition +=  colWidth
			}
		}
		else
		{
			if (curPosition > -((this.numbOfItems*colWidth)-(colWidth*3)))
			{
				this.newPosition -= colWidth
			}
		}
		
		this.animate()
	}
};

BottleSlider.prototype.animate = function()
{
	{
		clearTimeout(this.timer)
	}
	
	var left = parseInt(this.container.style.left),
		curPosition = this.newPosition,
		dir = this.dir;
	
	if (dir == 'L' && left < curPosition)
	{
		this.container.style.left = (left+23)+'px'
	}
	else if (dir == 'R' && left > curPosition)
	{
		this.container.style.left = (left-23)+'px'
	}
	
	this.timer = setTimeout(
		"$E('" + this.container.id + "').app.animate()",
		10
		);
};


/*
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
*/


/*
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
class BoxOpener(elm_id:string, startClass:string, endClass:string, triggerElementTag:string)
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
*/

function BoxOpener(elm, startClass, endClass, triggerElm, forceOpen)
{	
	var container;
	var box;
	
	//create cookie if doesn't exist
	var boxCookie = $cookie.Read(elm);
	if (!boxCookie)
	{
		if (forceOpen)//this will force open a box if cookie doesn't exist (i.e. first visit)
		{
			$cookie.Make(elm,1,30);	
		}
		else
		{
			$cookie.Make(elm,0,30);
		}
	}
	
	if (container = $E(elm))
	{	
		box 		= new Animator(
						{
							duration : 500,
							transition : Animator.tx.elastic
						}
						).addSubject(new CSSStyleSubject(
					container,
					startClass,
					endClass));
		
		var trigger = container.getElementsByTagName(triggerElm);
		
		//add onClick event to every box title
		addEvent(
			trigger[0],
			'click',
			function()
			{
				box.toggle();
				
				//read value of cookie every time to get newest value
				boxCookie 	= parseInt($cookie.Read(elm));

				if (typeof(boxCookie) == 'number')
				{
					if (boxCookie == 0)
					{	
						//set cookie's value to 1
						$cookie.Make(elm,1,30);
					}
					else
					{	
						//set cookie's value to 0
						$cookie.Make(elm,0,30);
					}
				}				
			}
			);
		
		//make boxes open automatically based on last state
		boxCookie 	= parseInt($cookie.Read(elm));

		if (typeof(boxCookie) == 'number')
		{
			//check if it was opened
			if (boxCookie == 1)
			{
				box.toggle();
			}	
		}
	}
};






/* REMEMBER LOGIN EMAIL */
function rememberEmail(triggerID, emailAddr) 
{
	var trigger;
	if (trigger = $E(triggerID))//if checkbox exists
	{
		if (trigger.checked)	//if checkbox is checked
		{
			$cookie.Make('rememberEmail',emailAddr,365);	//make or update cookie
		}
		else //checkbox not checked
		{
			if ($cookie.Read('rememberEmail')) //if cookie already exists
			{
				$cookie.Make('rememberEmail', ''); //erase cookie
			}
		}
	}
}

function retrieveEmail()
{
	var emailBox;
	//check if it's login page or checkout page
	if ((emailBox = $E('email')) || (emailBox = $E('login-email')))
	{
		if ($cookie.Read('rememberEmail') && emailBox.value == '')
		{
			emailBox.value = $cookie.Read('rememberEmail');
		}
	}
}

/*
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
*/


/*
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
$init_MagHack()
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
*/
function $init_MagHack()
{
	$reallyLoad(true);
	$slider = new BottleSlider('fp_promo_bottles');
	
	$PloreSlide = new PloreModuleSlide(
		'fp_promos', '$PloreSlide',
		{
			auto_startstop 	: true,
			interval		: 5000
		}
		);
	
	$easySearchOpener 	= new BoxOpener('right_easy_search', 		'collapsed', 'big_easy_search', 'h6', true);
	$advSearchOpener 	= new BoxOpener('right_advanced_search', 	'collapsed', 'big_adv_search', 	'h6', false);
	$videoOpener 		= new BoxOpener('right_video', 				'collapsed', 'big_video', 		'h6', false);
	$connectUsOpener 	= new BoxOpener('right_connect', 			'collapsed', 'big_connect_us',	'h6', false);
	
	retrieveEmail();
	
	new NewsTicker(
		'news-ticker-1',
		[
			//'FREE SHIPPING ON ORDERS OVER $100. CODE: FREESHIP100',
			'GET $20 OFF ORDER OF $100. USE CODE: 20OFF100 IN CART',
			'NY RESIDENTS GET 5% OFF ANY ORDER. CODE: NYSHIPPING',
			'WANT MORE? CHECK OUR WEBSITE DAILY FOR NEW DEALS'
		]
		)
		.start();
	
	new NewsTicker(
		'did-you-know',
		[
			'On average red wine is less-caloric than white wine.',
			'1/3 cup of salt in ice bucket cools wine faster.',
			'To avoid hangover eat plenty of food before drinking - preferably carbohydrates.',
			'CA, NY, FL are the top three U.S. states in terms of wine consumption.',
			'The lip of a red wine glass is sloped inward to capture the aromas of the wine and deliver them to your nose.',
			'California is the fourth-largest wine producer in the world, after France, Italy and Spain.',
			'Wine glasses should always be held by the stem and not the bowl because the heat of the hand will raise the temperature of the wine.',
			'Not all wines improve with time. In fact, a vast majority of wines produced are ready to drink and do not have much potential for aging. Only a rare few will last longer than a decade',
			'One bottle of wine contains about 2.8 pounds of grapes.',
			'Red Burgundy is made from the Pinot Noir grape and is so difficult to make that winemakers all over the world see it as some kind of Holy Grail.',
			'A crop of newly planted grape vines takes four to five years to grow before it can be harvested.'
		]
		)
		.start();
};


/*
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
*/


/*
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
class NewsTicker(container: Element, strings: Array)
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
*/
function NewsTicker(e,bag)
{
	this.elm		= typeof e === 'object' ? e : document.getElementById(e);
	if (!this.elm) return;
	
	this.bag		= bag;
	this.i			= -1;
	this.l			= this.bag.length;
	this.timer		= null;
	this.buf		= null;
	this.elm.app	= this;
	
	this.def = {
		interval	: 6000,
		duration	: 1000,
		delay		: 700
		};
	
	this.elm.Fader = new Animator(
		{
			onComplete : new Function(
				  "var e=document.getElementById('"+this.elm.id+"');"
				+ "var o=$f.get.opacityOf(e);"
				+ "if(o<100&&e.app.buf){e.innerHTML=e.app.buf;e.Fader.reverse()}"
				),
			
			duration : this.def.duration
		}
		)
		.addSubject(
			new NumericalStyleSubject(
				this.elm,
				'opacity',
				1,
				0
				)
		);
	
	this.elm.Fader.play()
};


NewsTicker.prototype = 
{
	/*
	IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
	NewTicker : mixed start([now: Boolean])
	IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
	*/
	start : function(now)
	{
		if (!this.elm) return;
		
		if (!now)
		{
			return setTimeout(
				"document.getElementById('"+this.elm.id+"').app.start(true)",
				this.def.delay
				);
		}
		
		this.timer = setInterval(
			"document.getElementById('"+this.elm.id+"').app.next()",
			this.def.interval
			);
		
		this.next()
	},
	
	
	/*
	IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
	NewTicker : next()
	IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
	*/
	next : function()
	{
		if (++this.i >= this.l) this.i = 0;
		
		this.insert(
			this.bag[this.i]
			);
	},
	
	
	/*
	IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
	NewTicker : string insert(message: String)
	IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
	*/
	insert : function(str)
	{
		if (this.buf = str)
		{
			if ($f.get.opacityOf(this.elm) == 100) this.FadeOut();
			else
			{
				{
					this.elm.innerHTML = this.buf
				}
				
				this.FadeIn()
			}
		}
	},
	
	FadeOut	: function(){this.elm.Fader.play()},
	FadeIn	: function(){this.elm.Fader.reverse()}
};

