// JavaScript Document
	
// Font replace
	
		Cufon.replace('h1');
		Cufon.replace('h2');
		Cufon.replace('h4');
		Cufon.replace('fracka');
		
// Initialise Superfish  
 
    $(document).ready(function(){ 
        $("ul.sf-menu").superfish(); 
    });

// Carousel - Header portfolio

		function mycarousel_initCallback(carousel)
		{
		    // Disable autoscrolling if the user clicks the prev or next button.
		    carousel.buttonNext.bind('click', function() {
		        carousel.startAuto(0);
		    });
		
		    carousel.buttonPrev.bind('click', function() {
		        carousel.startAuto(0);
		    });
		
		    // Pause autoscrolling if the user moves with the cursor over the clip.
		    carousel.clip.hover(function() {
		        carousel.stopAuto();
		    }, function() {
		        carousel.startAuto();
		    });
		};

		jQuery(document).ready(function() {
		    jQuery('#portfolio').jcarousel({
		        vertical: true,
		        scroll:1,
		        auto: 4,
		        wrap: 'last',
		        initCallback: mycarousel_initCallback
		    });
		});
$(document).ready(function() {
	$('#usernameLoading').hide();
	
});
function startGift() {
	$('#gift').toggle(); 
	
}
function getGift() {
  
    $.post("/auto/allgift.php", {
       gift_code: $('#gift_codes').val() 
	         }, function(response){
      
	  
	  	 var answer =response;
	
			  
	   if (/yes/.test(answer)) {
		 //  $('#usernameLoading').hide();
		   $('#fullprice').fadeOut(); 
		   $('#giftcodePrice').fadeIn(); 
		   $('#giftBox').fadeOut(); 
 		 $('#Error').fadeOut(); 
	   }
	   else {
		  $('#Error').fadeIn('slow'); 
		  		   		   
	   }
	  
	 
	  	     
     }
	 
	 
	 );    
}

function startAjax() {
  
   $('#error').hide(); 
    $('#errorName').hide(); 
    $('#errorEmail').hide(); 
   $('#errorCode').hide(); 
    $('#errorEmailBad').hide(); 
   $('#myButtton').hide(); 
   
   
   $('#usernameLoading').show();
    
    $.post("http://hiddenwaystowealth.com/auto/check.php", {
        name: $('#name').val(), email: $('#email').val()  ,  gift_code: $('#gift_code').val() , auto: $('#auto').val()
      }, function(response){
      
	  
	  	 var answer =response;
		//alert (answer); 
			  
	   if (/http/.test(answer)) {
		 //  $('#usernameLoading').hide();
		 
		 
		   $('#gift').fadeOut(); 
		   $('#clickHere').fadeOut(); 
		//	$('#emailed').val($('#email').val());
		  
		  $('#success').fadeIn('slow');
		  		  
		  var link = '<a href="'+answer+'"><p class="center"> <img src="/images/download_blu.jpg" width="175" height="61" alt="download" border="0"/></p></a>'; 
	 	$(".myB").html(link); 
		$('#download').fadeIn('slow'); 
		
		  
		; 
	   }
	   else if (answer == 'name') {
		  $('#errorName').fadeIn('slow'); 
		    $('#usernameLoading').hide(); 		 		   		   
	   }
	      else if (answer == 'bademail') {
		  $('#errorEmailBad').fadeIn('slow'); 
		    $('#usernameLoading').hide(); 		 		   		   
	   }
	    else if (answer == 'email') {
		  $('#errorEmail').fadeIn('slow'); 
		    $('#usernameLoading').hide(); 		   				   
	   }
	     else if (answer == 'code') {
		  $('#errorCode').fadeIn('slow'); 
		    $('#usernameLoading').hide(); 		   				   
	   }
	   else{
		  $('#error').fadeIn('slow'); 
		    $('#usernameLoading').hide()
		
	   }
	   
	
	 
	  	     
     }
	 
	 
	 );    
}
function finishAjax(id, response) {
  $('#usernameLoading').hide();
  $('#'+id).html(unescape(response));
  $('#'+id).fadeIn();
} //finishAjax
function getGiftCodeNYSE() {
  
   
   $('#giftProcessing').fadeIn(); 
    $('#giftForm').fadeOut(); 
   

    $.post("inc/get_gift_code_nyse.php", {
        email: $('#email').val() 
      }, function(response){
      
	  
	  	 var answer =response;
		 
		//alert (answer); 
			  
	   if (/@/.test(answer)) {
		 //  $('#usernameLoading').hide();
		    $('#giftProcessing').fadeOut(); 
   
		  $('#giftSuccess').fadeIn('slow');
		  		  
		  var link = answer 
	 	$(".myB").html(link); 
		$('#download').fadeIn('slow'); 
		
		  
		; 
	   }
	
	   else{
	   	   $('#giftProcessing').fadeOut(); 
   		   $('#giftFailed').fadeIn('slow'); 		
		   $(".myB2").html(link);    
		
	   }
	   
	
	 
	  	     
     }
	 
	 
	 );    
}
function getSingleCode() {
  
   
   $('#giftProcessingRight').fadeIn(); 
    $('#Single').fadeOut(); 
  
    $.post("inc/get_single_code.php", {
        email: $('#email').val()
      }, function(response){
      
	  
	  	 var answer =response;
		 
		//alert (answer); 
			  
	   if (/@/.test(answer)) {
		 //  $('#usernameLoading').hide();
		    $('#giftProcessingRight').fadeOut(); 
   
		  $('#giftSuccessRight').fadeIn('slow');
		   $('#giftSuccessRightSmall').fadeIn('slow');
		  		  
		  var link = answer 
	 	$(".myB").html(link); 
		$('#download').fadeIn('slow'); 
		
		  
		; 
	   }
	
	   else{
	   	   $('#giftProcessingRight').fadeOut(); 
   		   $('#giftFailedRight').fadeIn('slow'); 		
		   $(".myB2").html(link);    
		
	   }
	   
	
	 
	  	     
     }
	 
	 
	 );    
}
function getGiftCode2() {
  
   
   $('#giftProcessing').fadeIn(); 
    $('#giftForm').fadeOut(); 
   

    $.post("/inc/get_gift_code.php", {
        email: $('#email').val(),nyse: $('#nyse').val() 
      }, function(response){
      
	  
	  	 var answer=response;
		 
	
	   if (/@/.test(answer)) {
		   var url = '/offer/thankyou.php?email=' + answer; 
		 
		   
		window.location.href = url; 
		
		
		
	   }
	
	   else{
	   	   $('#giftProcessing').fadeOut(); 
   		   $('#giftFailed').fadeIn('slow'); 		
		   $(".myB2").html(link);    
		
	   }
	   
	
	 
	  	     
     }
	 
	 
	 );    
}
function getGiftCodeAff() {
  
   
   $('#giftProcessingSmall').fadeIn(); 
    $('#giftForm').fadeOut(); 
   

    $.post("/inc/get_gift_code.php", {
        email: $('#email').val(),nyse: $('#nyse').val() 
      }, function(response){
      
	  
	  	 var answer=response;
		 
	
	   if (/@/.test(answer)) {
		   var url = '/offer/thankyou.php?email=' + answer; 
		 
		   
		window.location.href = url; 
		
		
		
	   }
	
	   else{
	   	   $('#giftProcessingSmall').fadeOut(); 
   		   $('#giftFailedSmall').fadeIn('slow'); 		
		      
		
	   }
	   
	
	 
	  	     
     }
	 
	 
	 );    
}

function getGiftCodeNormal() {
  
   
   $('#giftProcessingBlack').fadeIn(); 
    $('#giftForm').fadeOut(); 
   

    $.post("/inc/get_gift_code.php", {
        email: $('#email').val(),nyse: $('#nyse').val() 
      }, function(response){
      
	  
	  	 var answer=response;
		 
	
	   if (/@/.test(answer)) {
		   var url = '/offer/thankyou.php?email=' + answer; 
		 
		   
		window.location.href = url; 
		
		
		
	   }
	
	   else{
	   	   $('#giftProcessingBlack').fadeOut(); 
   		   $('#giftFailedNormal').fadeIn('slow'); 		
		      
		
	   }
	   
	
	 
	  	     
     }
	 
	 
	 );    
}

function getGiftCode() {
  
   
   $('#giftProcessing').fadeIn(); 
    $('#giftForm').fadeOut(); 
   

    $.post("inc/get_gift_code.php", {
        email: $('#email').val(),nyse: $('#nyse').val() 
      }, function(response){
      
	  
	  	 var answer=response;
		 
		//alert (answer); 
			  
	   if (/@/.test(answer)) {
		 //  $('#usernameLoading').hide();
		    $('#giftProcessing').fadeOut(); 
   
		  $('#giftSuccess').fadeIn('slow');
		  		  
		  var link = answer 
	 	$(".myB").html(link); 
		$('#download').fadeIn('slow'); 
		
		  
		; 
	   }
	
	   else{
	   	   $('#giftProcessing').fadeOut(); 
   		   $('#giftFailed').fadeIn('slow'); 		
		   $(".myB2").html(link);    
		
	   }
	   
	
	 
	  	     
     }
	 
	 
	 );    
}
function startGiftCheck() {
  
   
   $('#giftProcessing').fadeIn(); 
    $('#giftForm').fadeOut(); 
   

    $.post("giftcode-check.php", {
        name: $('#name').val(), email: $('#email').val()  
      }, function(response){
      
	  
	  	 var answer =response;
		 
	//	alert (answer); 
			  
	   if (/@/.test(answer)) {
		 //  $('#usernameLoading').hide();
		    $('#giftProcessing').fadeOut(); 
   
		  $('#giftSuccess').fadeIn('slow');
		  		  
		  var link = answer 
	 	$(".myB").html(link); 
		$('#download').fadeIn('slow'); 
		
		  
		; 
	   }
	
	   else{
	   	   $('#giftProcessing').fadeOut(); 
   		   $('#giftFailed').fadeIn('slow'); 		
		   $(".myB2").html(link);    
		
	   }
	   
	
	 
	  	     
     }
	 
	 
	 );    
}
function finishGiftCheck(id, response) {
  $('#usernameLoading').hide();
  $('#'+id).html(unescape(response));
  $('#'+id).fadeIn();
} //finishAjax

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
function validateonsubmit(value){
	var myForm=document.getElementById(value);
	var SS= Spry.Widget.Form.validate(myForm);
	if(SS==true){
	myForm.submit();
	}
}
function validateonsubmitSingleGift(value){
	var myForm=document.getElementById(value);
	var SS= Spry.Widget.Form.validate(myForm);
	
	
	if(SS==true){
		
		getSingleCode();
	}
}
function validateonsubmitGift2(value){
	var myForm=document.getElementById(value);
	var SS= Spry.Widget.Form.validate(myForm);
	
	if(SS==true){
		getGiftCode2();
	}
}
function validateonsubmitGiftAff(value){
	var myForm=document.getElementById(value);
	var SS= Spry.Widget.Form.validate(myForm);
	
	if(SS==true){
		getGiftCodeAff();
	}
}
function validateonsubmitGiftNormal(value){
	var myForm=document.getElementById(value);
	var SS= Spry.Widget.Form.validate(myForm);
	
	if(SS==true){
		getGiftCodeNormal();
	}
}
function validateonsubmitGift(value){
	var myForm=document.getElementById(value);
	var SS= Spry.Widget.Form.validate(myForm);
	
	if(SS==true){
		getGiftCode();
	}
}
function validateonsubmitNyseGift(value){
	var myForm=document.getElementById(value);
	var SS= Spry.Widget.Form.validate(myForm);
	
	if(SS==true){
		getGiftCodeNYSE();
	}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
