/*
		if(this.title == 'Password'){
						$this = $(this);
						$this.hide();
						$('#'+$this.attr('rel')).show().focus();
					}
					else 
					
					
					
					if(this.type == "password")
					{
						$this = $(this);
						$('#'+$this.attr('rel')).show();
						$this.hide();
						//$this.attr('type','text');
					}
					
		*/
			$(document).ready(function(){
				$content = $('#content');
				if($content.height() > 1000)
				    $content.append('<a href="#toppanel" id="backToTop"><img src="/include/images/arrowUp.png" />Back to top</a>');
				$('#backToTop').click(function (e) {
					e.preventDefault();
		  		    e.stopPropagation();
					$('body,html').animate({scrollTop: 0},800);  
				}); 
				$('#customer_edit_form').live('submit',function(e){
					e.preventDefault();
		  		    e.stopPropagation();
		  		    $.post("/ajax/customer.php", $(this).serialize(),function(data){
		  		    	switch(data.status)
		  		    	{
		  		    		case 'success':
		  		    			$('#customer_edit_form input').each(function(){
								    this.disabled = 'disabled';
								});
								$('#customer_edit_form select').each(function(){
								    this.readonly = 'readonly';
								});
								$('#changeSubmit').remove();
								$('#changesPending').show();
								$('#messages').empty().append('<span class="message" style="color:green;">'+data.messages+'</span>');
								
		  		    			break;
		  		    		case 'invalid':
		  		    			break;
		  		    		case 'ERROR':
		  		    			$('#messages').empty().append('<span class="error" style="color:red;">'+data.fails+'</span>');
		  		    			break;
		  		    	}
		  		    }, "json");
		  		});
		  		$('#login').live('submit',function(e){
					e.preventDefault();
		  		    e.stopPropagation();
		  		    $.post("/customer-portal/login.php", $(this).serialize(),function(data){
		  		    	switch(data.status)
		  		    	{
		  		    		case 'success':
								$('#topPanelMiddle').empty().append(data.html.middle);
								$('#topPanelRight').empty().append(data.html.right);
								$('#open').html('Open Panel');
		  		    			break;
		  		    		case 'invalid':
		  		    			break;
		  		    		case 'failure':
		  		    			$('#loginErrors').empty().append('<span class="error" style="color:red;">'+data.errors+'</span>');
		  		    			break;
		  		    	}
		  		    }, "json");
		  		});
		  		$('#registration').live('submit',function(e){
					e.preventDefault();
		  		    e.stopPropagation();
		  		    $('#registerSubmit').hide();
		  		    $('#registerLoad').show();
		  		    $.post("/customer-portal/register.php", $(this).serialize(),function(data){
		  		    	switch(data.status)
		  		    	{
		  		    		case 'success':
								$('#topPanelMiddle').empty().append(data.html);
		  		    			break;
		  		    		case 'invalid':
		  		    			break;
		  		    		case 'failure':
   				  		    	$('#registerSubmit').show();
				  		    	$('#registerLoad').hide();
		  		    			$('#registrationErrors').empty().append('<span class="error" style="color:red;">'+data.errors+'</span>');
		  		    			break;
		  		    	}
		  		    }, "json");
		  		});
				$.stylesheetInit();
				var $inputs = $('input[title]');
				$inputs.each(function(e){
					if(this.value == "")
						this.value = this.title;
				});
				$inputs.focus(function(e){
					if (this.value == this.title)
						this.value = '';
				}).blur(function(e){
					if (this.value == '')
						this.value = this.title;
				});
				$passwords = $('input[type=password]').each(function(e){
					$(this).css({'background-image':'url(/include/images/password.jpg)','background-repeat':'no-repeat'});
				});
				$passwords.focus(function(e){
					$(this).css('background-image','none');
				}).blur(function(e){
					if (this.value == '')
						$(this).css('background-image','url(/include/images/password.jpg)');
				});
				// Expand Panel
				$("#open").click(function(){
					$("div#panel").slideDown("slow");
				
				});	
				
				// Collapse Panel
				$("#close").click(function(){
					$("div#panel").slideUp("slow");	
				});		
				
				// Switch buttons from "Log In | Register" to "Close Panel" on click
				$("#toggle a").click(function () {
					$("#toggle a").toggle();
				});
				$('#birthday').datepicker({
					beforeShow: function(input, inst)
				    {
				        inst.dpDiv.css({marginTop: -input.offsetHeight + 'px', marginLeft: (-inst.dpDiv.outerWidth()) + 'px',zIndex:1000});
				    },
					changeMonth: true,
					changeYear: true,
					maxDate: '-13Y',
					yearRange: '-100:0',
					dateFormat: 'yy-mm-dd'
				});
				$('#footerPopsContainer .popContainer').hover(
					function(){
						if(!$(this).is(':animated'))
							$(this).animate({top:-164,height:221},250);
					},
					function(){
							$(this).animate({top:0,height:53},250);
					}
				);
				$('#leftSideBarPopsContainer .popContainer').click(function(e){
					$this = $(this);
					if(!$this.hasClass('opened'))
					{
						$('#leftSideBarContent .popContainer.opened').animate({height:53},250).removeClass('opened');
						$this.animate({height:221},250).addClass('opened');
					}
				});
				$('.navLink').hover(
					function(){
						if(!$(this).is(':animated'))
							$(this).animate({marginTop:0},250);
					},
					function(){
							$(this).animate({marginTop:-7},250);
					}
				);
				$('#content .printCoupon').click(function(e){
					e.preventDefault();
				    e.stopPropagation();
				    $.stylesheetSwitch('coupon');
					window.print();
				});
				$('.couponOverlay .printCoupon').click(function(e){
					e.preventDefault();
				    e.stopPropagation();
					window.print();
					$.stylesheetSwitch('overlayCoupon');

				});
				$(".popContainer a[rel]").overlay();
			});