/*
	Masked Input plugin for jQuery
	Copyright (c) 2007-2009 Josh Bush (digitalbush.com)
	Licensed under the MIT license (http://digitalbush.com/projects/masked-input-plugin/#license) 
	Version: 1.2.2 (03/09/2009 22:39:06)
*/
(function(a){var c=(a.browser.msie?"paste":"input")+".mask";var b=(window.orientation!=undefined);a.mask={definitions:{"9":"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"}};a.fn.extend({caret:function(e,f){if(this.length==0){return}if(typeof e=="number"){f=(typeof f=="number")?f:e;return this.each(function(){if(this.setSelectionRange){this.focus();this.setSelectionRange(e,f)}else{if(this.createTextRange){var g=this.createTextRange();g.collapse(true);g.moveEnd("character",f);g.moveStart("character",e);g.select()}}})}else{if(this[0].setSelectionRange){e=this[0].selectionStart;f=this[0].selectionEnd}else{if(document.selection&&document.selection.createRange){var d=document.selection.createRange();e=0-d.duplicate().moveStart("character",-100000);f=e+d.text.length}}return{begin:e,end:f}}},unmask:function(){return this.trigger("unmask")},mask:function(j,d){if(!j&&this.length>0){var f=a(this[0]);var g=f.data("tests");return a.map(f.data("buffer"),function(l,m){return g[m]?l:null}).join("")}d=a.extend({placeholder:"_",completed:null},d);var k=a.mask.definitions;var g=[];var e=j.length;var i=null;var h=j.length;a.each(j.split(""),function(m,l){if(l=="?"){h--;e=m}else{if(k[l]){g.push(new RegExp(k[l]));if(i==null){i=g.length-1}}else{g.push(null)}}});return this.each(function(){var r=a(this);var m=a.map(j.split(""),function(x,y){if(x!="?"){return k[x]?d.placeholder:x}});var n=false;var q=r.val();r.data("buffer",m).data("tests",g);function v(x){while(++x<=h&&!g[x]){}return x}function t(x){while(!g[x]&&--x>=0){}for(var y=x;y<h;y++){if(g[y]){m[y]=d.placeholder;var z=v(y);if(z<h&&g[y].test(m[z])){m[y]=m[z]}else{break}}}s();r.caret(Math.max(i,x))}function u(y){for(var A=y,z=d.placeholder;A<h;A++){if(g[A]){var B=v(A);var x=m[A];m[A]=z;if(B<h&&g[B].test(x)){z=x}else{break}}}}function l(y){var x=a(this).caret();var z=y.keyCode;n=(z<16||(z>16&&z<32)||(z>32&&z<41));if((x.begin-x.end)!=0&&(!n||z==8||z==46)){w(x.begin,x.end)}if(z==8||z==46||(b&&z==127)){t(x.begin+(z==46?0:-1));return false}else{if(z==27){r.val(q);r.caret(0,p());return false}}}function o(B){if(n){n=false;return(B.keyCode==8)?false:null}B=B||window.event;var C=B.charCode||B.keyCode||B.which;var z=a(this).caret();if(B.ctrlKey||B.altKey||B.metaKey){return true}else{if((C>=32&&C<=125)||C>186){var x=v(z.begin-1);if(x<h){var A=String.fromCharCode(C);if(g[x].test(A)){u(x);m[x]=A;s();var y=v(x);a(this).caret(y);if(d.completed&&y==h){d.completed.call(r)}}}}}return false}function w(x,y){for(var z=x;z<y&&z<h;z++){if(g[z]){m[z]=d.placeholder}}}function s(){return r.val(m.join("")).val()}function p(y){var z=r.val();var C=-1;for(var B=0,x=0;B<h;B++){if(g[B]){m[B]=d.placeholder;while(x++<z.length){var A=z.charAt(x-1);if(g[B].test(A)){m[B]=A;C=B;break}}if(x>z.length){break}}else{if(m[B]==z[x]&&B!=e){x++;C=B}}}if(!y&&C+1<e){r.val("");w(0,h)}else{if(y||C+1>=e){s();if(!y){r.val(r.val().substring(0,C+1))}}}return(e?B:i)}if(!r.attr("readonly")){r.one("unmask",function(){r.unbind(".mask").removeData("buffer").removeData("tests")}).bind("focus.mask",function(){q=r.val();var x=p();s();setTimeout(function(){if(x==j.length){r.caret(0,x)}else{r.caret(x)}},0)}).bind("blur.mask",function(){p();if(r.val()!=q){r.change()}}).bind("keydown.mask",l).bind("keypress.mask",o).bind(c,function(){setTimeout(function(){r.caret(p(true))},0)})}p()})}})})(jQuery);

/* Alphanumeric */

(function($){$.fn.alphanumeric=function(p){p=$.extend({ichars:"!@#$%^&*()+=[]\\\';,/{}|\":<>?~`.- ",nchars:"",allow:""},p);return this.each
(function()
{if(p.nocaps)p.nchars+="ABCDEFGHIJKLMNOPQRSTUVWXYZ";if(p.allcaps)p.nchars+="abcdefghijklmnopqrstuvwxyz";s=p.allow.split('');for(i=0;i<s.length;i++)if(p.ichars.indexOf(s[i])!=-1)s[i]="\\"+s[i];p.allow=s.join('|');var reg=new RegExp(p.allow,'gi');var ch=p.ichars+p.nchars;ch=ch.replace(reg,'');$(this).keypress
(function(e)
{if(!e.charCode)k=String.fromCharCode(e.which);else k=String.fromCharCode(e.charCode);if(ch.indexOf(k)!=-1)e.preventDefault();if(e.ctrlKey&&k=='v')e.preventDefault();});$(this).bind('contextmenu',function(){return false});});};$.fn.numeric=function(p){var az="abcdefghijklmnopqrstuvwxyz";az+=az.toUpperCase();p=$.extend({nchars:az},p);return this.each(function()
{$(this).alphanumeric(p);});};$.fn.alpha=function(p){var nm="1234567890";p=$.extend({nchars:nm},p);return this.each(function()
{$(this).alphanumeric(p);});};})(jQuery);




$(document).ready(function() {
						   
	// ################## Basic Jquery operations ##################
	
	$(document).bind("contextmenu",function(e){
        return false;
    });

	
	$('a.current, a.tab').click(function(){
		return false;							  
	});

    // external links
    $("a[rel='external']").click(function() {
        window.open($(this).attr('href'));
        return false;
    });

    // Add first and end class to lists and tables
    $('li:last','ul, ol').addClass('last');
    $('tr:last','table').addClass('last');
	$('li:first','ul, ol').addClass('first');
    $('tr:first','table').addClass('first');
	
	// CSS zoom fix for IE6 hasLayout bugs
	if($.browser.msie && parseInt($.browser.version) == 6 && !window["XMLHttpRequest"]){
		$('body').append('<style type="text/css">* {zoom: 1;}</style>');	
	}
	
	
	// ################## Site Specific operations ##################

	if($('#homeSlideshow').length){
		$('#homeSlideshow').cycle({ 
    		delay:  5000, 
    		speed:  1200
		});
	}	
	
	$('#nav ul').children('li').hover(function(){
		$(this).addClass('hover');							  
	},function(){
		$(this).removeClass('hover');	
	});
	$('ul.links li').hover(function(){
		$(this).addClass('hover');								
	},function(){
		$(this).removeClass('hover');
	});
	$('ul.links li').click( function(){
		window.location=$(this).find('a').attr('href'); return false;
	});
	
	
	// Get latest Tweet
	$('#tweet').html('tweet, tweet, tweet&hellip;');
	$.jTwitter('PatricBradley', 1, function(latestTweet){
		$('#tweet').html('&ldquo;' + latestTweet[0].text + '&rdquo;');								  
	});
	
	// Feature Product Box
	$('#featuredProduct').hover(function(){
		$(this).addClass('hover');								 
	},function(){
		$(this).removeClass('hover');
	});
	$('#featuredProduct').click(function(){
		 window.location=$(this).find('a').attr('href'); return false;
	});
	
	// Events List
	if($('.homeRcol ul').length){
		$('.homeRcol ul').everyTime(5000, "listTimer", function(){
			$(this).find('li:first').clone().appendTo($(this));
			$(this).find('li:first').animate({opacity : 0, marginTop : '-82px'},700,function(){$(this).remove();});
		});
		$('.homeRcol ul').hover(function(){
			$('.homeRcol ul').stopTime('listTimer');				
		},function(){
			$('.homeRcol ul').find('li:first').clone().appendTo($(this));
			$(this).find('li:first').animate({opacity : 0, marginTop : '-82px'},700,function(){$(this).remove();});
			$(this).everyTime(5000, "listTimer", function(){
				$('.homeRcol ul').find('li:first').clone().appendTo($(this));
				$(this).find('li:first').animate({opacity : 0, marginTop : '-82px'},700,function(){$(this).remove();});
			});
		});
	}
	
	$('#portfolioLandingPage ul li').hover(function(){
		$(this).addClass('hover');									  
	},function(){
		$(this).removeClass('hover');
	});
	
	// Store Items
	$('#storeFront ul li').hover(function(){
		$(this).addClass('hover');									  
	},function(){
		$(this).removeClass('hover');
	});
	$('#storeFront ul li').click(function(){
		window.location=$(this).find('a').attr('href'); return false;									  
	});
	$('#addToBagButton').hover(function(){
		$(this).addClass('hover');								 
	},function(){
		$(this).removeClass('hover');
	});
	
	
	// Cart info
	$('#cart').hover(function(){
		$(this).addClass('hover');					  
	},function(){
		$(this).removeClass('hover');
	});
	$('#cart').click(function(){
		window.location=$(this).find('a').attr('href'); return false;					  
	});
	
	//Cart Forms
	$('.removeButton').hover(function(){
		$(this).addClass('hover');								  
	},function(){
		$(this).removeClass('hover');
	});
	$('#placeOrderButton').hover(function(){
		$(this).addClass('hover');					  
	},function(){
		$(this).removeClass('hover');
	});
	
	$('.clickToRegister').hover(function(){
		$(this).addClass('hover');					  
	},function(){
		$(this).removeClass('hover');
	});
	$('#jamSubmitButton').hover(function(){
		$(this).addClass('hover');					  
	},function(){
		$(this).removeClass('hover');
	});
	
	$('#receiptPage span.print').click(function(){
		window.print();
		return false;										 
	});
	
	$("#jamSessionOrderForm").validate({
		rules: {
    		styliststudent: "required",
			pkg : "required"			
  		}
								   
	});
	$('#pkg2options, #pkg3options, #pkg4options, #pkg5options, #pkg6options').hide();
	$('input:radio:unchecked').click(function(){																						  
		$('#pkg2options, #pkg3options, #pkg4options, #pkg5options, #pkg6options').hide();
		$('input:checkbox').removeAttr('checked');
		$(this).attr({checked : true});
		$(this).parent().parent().next().find('div').show();
	});
	$.fn.limit = function(n) {
 		var self = this;
 		this.click(function(){ return (self.filter(":checked").length<=n); });
	}
	
	$('input:checkbox','#pkg2options').limit(1);
	$('input:checkbox','#pkg3options').limit(1);
	$('input:checkbox','#pkg4options').limit(2);
	$('input:checkbox','#pkg5options').limit(2);
	$('input:checkbox','#pkg6options').limit(1);
	
	
	$("#askTeamHollywoodForm").validate();
	$('#askTeamHollywoodButton, #askTeamHollywoodQA ul li').hover(function(){
		$(this).addClass('hover');					  
	},function(){
		$(this).removeClass('hover');
	});
	$('#customerPrimaryPhone').mask("(999) 999-9999");
	$('#customerAlternatePhone').mask("(999) 999-9999");
});
