// JavaScript Document

$(document).ready(function() {
	//$('.navi').menu();
	//$('#userline').menu();
	
	$(".naviMain > li").hover(
		function() {
			$(this).animate({'opacity':.5});
		},
		function() {
			$(this).animate({'opacity':1});
		}
	)
	
	if($(".photoIcon")) {
		$(".photoIcon").each(function() {
			$(this).hover(
				function() { $(this).css({"background-color":"#666"}); },
				function() { $(this).css({"background-color":"#000"});}
			);						  
		});
	};
	
	//print receipt
	if($("#printNow").length) {
		$('#printNow').click(function() {
			window.open($(this).attr('href'),'receipt',"width=612px;height=720");
			return false;
		});
	}
	
	if($('.help').length) {
		$('.help').click(function() {
			var $this = $(this);
			os = $this.offset();
			url = $this.attr('longdesc');
			$.get(url,function(data) {
				if(!$("#helpBox").length) {
					$this.parent().append('<div id="helpBox"></div>')
				}
				$('#helpBox').html(data);
				$(document).click(function() {
					$('#helpBox').remove();							 
				})
			});
			
		});
	}
	
	//show and position login window
	$('#loginLink').click(function(){
		var os = $('#loginLink').offset();
		var sm = $('.container').offset();
		$('#loginScreen').css("left",(os.left - 170) - sm.left );
		$('#loginScreen').fadeIn('slow');
		return false;
	}); // close
	
	//close login window
	$('#closeLogin').click(function(){
		$('#loginScreen').fadeOut('slow');
	}); // close
	
	//function is for the register page to check if an email address is already in use.
	$("#registerMe").find("input[name='email']").keyup(function() {
		var email = $(this);
		var looking = $("#looking")
		if(email.val().length > 4) {
			looking.html('<img src="images/ajax-loader.gif" alt="looking" width="16" height="16"> Looking Up E-mail');
			looking.fadeIn();
			$.ajax(
			{
				url: "cgi-bin/s_lookupEmail.php",
				data: {email : email.val()},
				 success: function(msg){
				 looking.html(msg);
			   }
			}
			);
		}
	})// close lookupUser
	
	if($("#registerMe").length) {
		$("#registerMe").checkForms({
				'compare':{'password_1':'password_2'}
		});
	}
	
	if($("#enterMe").length) {
		var boleen = true;
		$("#saveMe").toggle(
			function() {$('#passwords').fadeIn('slow'); },
			function() {$('#passwords').fadeOut('slow'); }
		)
		$("#password_1").keyup(function() {
			if($("#password_1").val().length > 0) {
				boleen = false;
			};
		});
		
		var myObjt = {
			'first_name':'minPattern',
			'last_name':'minPattern',
			'address':'minPattern',
			'city':'minPattern',
			'state':'minPattern',
			'zip':'numeric',
			'phone':'phonePattern',
			'email':'emailPattern',
			'password_1':'passwordPattern'
		}	
		if(!$("#shippingInfo").hasClass('makeHidden')){
			var myShipObjt = {
				'ship_name':'minPattern',
				'ship_phone':'phonePattern',
				'ship_address':'minPattern',
				'ship_city':'minPattern',
				'ship_zip':'numeric'
			}
			$.extend(myObjt,myShipObjt);
		}
		if(!$("#deliveryInfo").hasClass('makeHidden')){
			var myShipObjt = {
				'deliv_name':'minPattern'
			}
			$.extend(myObjt,myShipObjt);
		}
		$("#enterMe").checkForms({
				'inputs' : myObjt,
				'compare':{'password_1':'password_2'},
				'blankPW':boleen
		});
	}
	
	$("#aboutus > li").hover(
		function() {
			var li = $(this);
			li.css({'padding-right':'36px'});
		},
		function() {
			var li = $(this);
			li.css({'padding-right':'0px'});
		}
	);
	if($(".shippingDetails").length) {
		showShipDetails();
	}
}); //close ready

function showShipDetails() {
	$(".shippingDetails").click(function() {
		var sd = $(this);
		var offset = sd.offset();
		var url = $(this).attr('href');
		if(!$("#newDetails").length) {
			$('<div>').addClass('shipdetails').attr('id','newDetails').css({'top':offset.top,'left':offset.left}).appendTo($('.container'));
		}
		var nd = $("#newDetails");
		nd.load('cgi-bin/s_getPage.php'+url,function() {
			var ow = $('div',this).outerWidth()+80;;
			nd.css('width',ow+'px');
			//create a close button
			var closeImg = $('<img src="images/close.png" alt="close" width="18px" hieght="18px" id="closeThis" />').css({'position':'absolute','right':'0','top':'0'});
			closeImg.appendTo(nd);
			closeImg.click(function() { nd.remove() });
		});
		return false;
	});
}

(function($) {
	
	$.fn.checkForms = function(options) {
		
		return this.each(function() {
								  
			var results1 = true;
			var results2 = true;
			var opts = {
				'inputs' : {'first_name':'minPattern','last_name':'minPattern','phone':'phonePattern','email':'emailPattern','password_1':'passwordPattern'},
				'emailPattern' :	/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/,
				'phonePattern' :  /^[0-9]{3,3}\S[0-9]{3,3}\S[0-9]{4,4}/,
				'minPattern' : /\S{2}/,
				'numeric': /\d/g,
				'passwordPattern': /\S{6}/,
				'compare': '',
				'blankPW': false,
				'emailMsg': 'Your Email addresss does not seem to be correct. Please correct it and submit the form again.',
				'phoneMsg': 'Please enter your phone number with the areacode: 000-000-0000',
				'minMsg': 'This field must have more than 2 character',
				'passwordMsg': 'Your password must have at least 6 characters.' ,
				'numericMsg': 'Must be a numeric value'
			}
			if ( options ) { 
				$.extend( opts, options );
			}
			
			//defining this
			var $this = $(this);
			
			//looking for submit
			$this.submit(function() {
			try {
				//looping through inputs				  
				$.each(opts['inputs'], function(index, value) {
					// find the element in the form
					var thisEl = $this.find("[name='"+index+"']");
					
					thisEl.css({"background-color": "#fff"});
					
					// if one of the this items is a compare item this it will have a length
					var findCompare = 0;
					if(opts['compare'][index]) {
					 	findCompare = opts['compare'][index].length;
					}
					
					// if form can have no pw then it checks that is in not in the compare var
					if(!opts['blankPW'] || findCompare < 1) {
						if(!thisEl.val().match(opts[value])) {
							var msg = value.replace('Pattern','')+"Msg";
							thisEl.css({"background-color": "#F96"});
							if(opts[msg]) {
								alert(opts[msg]);
								thisEl.focus();
							    results1 = false;
								return false
							}
							else {
								alert("This item ("+ index+") is not filled out correctly, please try agian");
								thisEl.focus();
							    results1 = false;
								return false
							}
							
						}
					else results1 = true;
					}
				});
				$.each(opts['compare'], function(compare1,compare2) {
					var comp1 = $this.find("[name='"+compare1+"']");
					var comp2 = $this.find("[name='"+compare2+"']"); 
					if(comp1.val() != comp2.val()) {
						comp1.css({"background-color": "#F96"});
						comp2.css({"background-color": "#F96"});
						alert("The highligthed fields do not match, please correct.")
						results2 = false;
						return false
					}
					else {
						comp1.css({"background-color": "#fff"});
						comp2.css({"background-color": "#fff"});
						results2 = true;
					}
				});
				if(results1 == false || results2 == false ) {
					return false;
				}
				else {
					return true;	
				}
			}
			catch(err) {
				alert(err);
				throw err;
			}
			});
		});
	}; //end checkForms
	
	$.fn.cookies = function(c_name) {
		return this.each(function() {
			var $this = $(this);
			if (document.cookie.length>0) {
				c_start=document.cookie.indexOf(c_name + "=");
				if (c_start!=-1) {
					c_start=c_start + c_name.length+1;
					c_end=document.cookie.indexOf(";",c_start);
					if (c_end==-1) c_end=document.cookie.length;
					var cookieString = unescape(document.cookie.substring(c_start,c_end));
					if(cookieString.length > 0) {
						$this.val(cookieString);
					}
				}
			}
		});
	}; // end cookies
})(jQuery);



/*
 * jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
 *
 * Uses the built in easing capabilities added In jQuery 1.1
 * to offer multiple easing options
 *
 * TERMS OF USE - jQuery Easing
 * 
 * Open source under the BSD License. 
 * 
 * Copyright © 2008 George McGinley Smith
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * Redistributions of source code must retain the above copyright notice, this list of 
 * conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list 
 * of conditions and the following disclaimer in the documentation and/or other materials 
 * provided with the distribution.
 * 
 * Neither the name of the author nor the names of contributors may be used to endorse 
 * or promote products derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 *  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE. 
 *
*/

// t: current time, b: begInnIng value, c: change In value, d: duration
jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend( jQuery.easing,
{
	def: 'easeOutQuad',
	swing: function (x, t, b, c, d) {
		//alert(jQuery.easing.default);
		return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
	},
	easeInQuad: function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeInOutQuad: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t + b;
		return -c/2 * ((--t)*(t-2) - 1) + b;
	},
	easeInCubic: function (x, t, b, c, d) {
		return c*(t/=d)*t*t + b;
	},
	easeOutCubic: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t + 1) + b;
	},
	easeInOutCubic: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t + b;
		return c/2*((t-=2)*t*t + 2) + b;
	},
	easeInQuart: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t + b;
	},
	easeOutQuart: function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	},
	easeInOutQuart: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
		return -c/2 * ((t-=2)*t*t*t - 2) + b;
	},
	easeInQuint: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t*t + b;
	},
	easeOutQuint: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t*t*t + 1) + b;
	},
	easeInOutQuint: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
		return c/2*((t-=2)*t*t*t*t + 2) + b;
	},
	easeInSine: function (x, t, b, c, d) {
		return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
	},
	easeOutSine: function (x, t, b, c, d) {
		return c * Math.sin(t/d * (Math.PI/2)) + b;
	},
	easeInOutSine: function (x, t, b, c, d) {
		return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
	},
	easeInExpo: function (x, t, b, c, d) {
		return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
	},
	easeOutExpo: function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	},
	easeInOutExpo: function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	},
	easeInCirc: function (x, t, b, c, d) {
		return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
	},
	easeOutCirc: function (x, t, b, c, d) {
		return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
	},
	easeInOutCirc: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
		return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
	},
	easeInElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
	},
	easeOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	},
	easeInOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
		return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
	},
	easeInBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*(t/=d)*t*((s+1)*t - s) + b;
	},
	easeOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
	},
	easeInOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158; 
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
	},
	easeInBounce: function (x, t, b, c, d) {
		return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
	},
	easeOutBounce: function (x, t, b, c, d) {
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
	},
	easeInOutBounce: function (x, t, b, c, d) {
		if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
		return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
	}
});

/*
 *
 * TERMS OF USE - EASING EQUATIONS
 * 
 * Open source under the BSD License. 
 * 
 * Copyright © 2001 Robert Penner
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * Redistributions of source code must retain the above copyright notice, this list of 
 * conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list 
 * of conditions and the following disclaimer in the documentation and/or other materials 
 * provided with the distribution.
 * 
 * Neither the name of the author nor the names of contributors may be used to endorse 
 * or promote products derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 *  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE. 
 *
 */
 
 /**
*
*   Floating / flying boxes with easing and motion-blur in jQuery
*   Author:      Marcell Jusztin
*   Date:        12th July, 2010
*   URL:         http://www.marcelljusztin.com
*   Version:     0.2
*
*/

jQuery.fn.randSize = function ( userOptions ) {
	colors = Array('#F30','#C03','#F90','#3F0','#06F','#009','#609','#C0F','#F0C','#3F0');
	 
	var rn = Math.random()
	rs = Math.round((rn * 1000) / 3);
	rs = (rs < 100) ? 100 : rs;
	cn = Math.round(rn * 10);
	$(this).css({'font-size':rs+'%','color':colors[cn]});
	
}
