/** PROMOS **/

  
// it's nice to work with 0 indexed counters
var totalSlides = -1; 
var currentSlide = 0;
var contentSlides = "";
var ready = true;

 $(document).ready(function(){
   $(".promo_prev").click(function(e) {
   	e.preventDefault();
   	auto=false;
   	if(ready) showPreviousSlide();
   });
   
   $(".promo_next").click(function(e) {
   	e.preventDefault();
   	auto=false;
   	if(ready) showNextSlide();
   });

   var totalWidth = 0;
   contentSlides = $(".slider_element");
   contentSlides.each(function(i){
     totalSlides++;
     //each element is hidden until needed
     $(this).css('marginLeft', -100000);  
   });

   //set the position of the first slide
   $(contentSlides[0]).css('marginLeft', 0);  

	showButtons();  		
	if(auto) startPromo(); 
	
	$(".lightbox").lightBox();
	
 });

function startPromo() {

if(auto){
	$.doTimeout( 2000, function(){
	  if((auto) && (totalSlides>0)){
	  	showNextSlide();  
	  	startPromo();
	  }
	});
}

}
	    
	    
function showPreviousSlide()
{
  updateSlides( -1 );
  currentSlide--;
  if (currentSlide < 0) currentSlide = totalSlides; 

 }

 function showNextSlide()
 {

   updateSlides( 1 );
   currentSlide++;
   if (currentSlide > totalSlides) currentSlide = 0;   

 }

 function updateSlides( direction )
 {

    var scrollAmount = 0;

    var currSlideObj = contentSlides[ currentSlide ];       
    var nextSlideObj = contentSlides[ getNextSlide( direction ) ];

    $( contentSlides ).each( function(){
        if ( this != currSlideObj && this != nextSlideObj ) {
            //each element is hidden until needed
            $(this).css('marginLeft', -100000);   
        }
    });

    if ( direction > 0 ) {
        //set the position of the next slide when 'next' pushed
        $( nextSlideObj ).css('marginLeft', parseInt($( currSlideObj ).css('marginLeft')) + $( currSlideObj ).width());
        
        
        //set the amount to animate
        scrollAmount = parseInt($( currSlideObj ).css('marginLeft')) - $( currSlideObj ).width();
    } else {
        //set the position of the next slide when 'previous' pushed
        $( nextSlideObj ).css('marginLeft', parseInt($( currSlideObj ).css('marginLeft')) - $( nextSlideObj ).width());
        //set the amount to animate
        scrollAmount = parseInt($( currSlideObj ).css('marginLeft')) + $( currSlideObj ).width();
    }

    // we'll animate the slide objects independently
	ready=false;
    $( currSlideObj ).animate({marginLeft: scrollAmount}, 1500);
    $( nextSlideObj ).animate({marginLeft: 0}, 1500, function() {
	ready=true;
	});
	
 }

 function getNextSlide( direction ) 
 {
    if ( ( currentSlide + direction ) > totalSlides ) {
        return 0;
    } else if ( ( currentSlide + direction ) < 0 ) {
        return totalSlides;     
    }

    return  currentSlide + direction;

 }

function showButtons() {
	 if(totalSlides <1) {
	   $(".promo_next").hide();
	   $(".promo_prev").hide();
	   }
 }
 





	    
	    
/***** STANDARD SLIDING CONTENT DIVS *******/
var num=1;
var old_num;

$(".area").hide();
$("#area_1").show();

$(".tab").click(function(e) {
								e.preventDefault();
								var arr = this.href.split("#");//.substr(1,1);
								old_num = num;
								num = arr[1];
								$("#user_interaction").fadeOut("fast", function() {
									$("#tab_"+old_num).addClass("tab_off");
									$("#tab_"+old_num).removeClass("tab_on");
									$("#tab_"+num).addClass("tab_on");
									$("#tab_"+num).removeClass("tab_off");
									$("#user_interaction").html($("#user_interaction_"+num).html());
									$("#user_interaction").fadeIn("fast");
									});
							});


$(".product_thumbnail").click(function() {
					   $("#product_image").attr("src", $(this).attr("src"));
					   });



/***** SET DELIVERY ADDRESS TO MAIN ADDRESS *****/

$(".set_address").click(function() {
	 
	 if(this.checked) {
		 if(this.value>0) prefix = "_"+this.value+"_"; else prefix = "";
		eval("document.registration_form."+prefix+"delivery_address_1.value = document.registration_form."+prefix+"address_1.value");
		eval("document.registration_form."+prefix+"delivery_address_2.value = document.registration_form."+prefix+"address_2.value");
		eval("document.registration_form."+prefix+"delivery_city.value = document.registration_form."+prefix+"city.value");
		eval("document.registration_form."+prefix+"delivery_county.value = document.registration_form."+prefix+"county.value");
		eval("document.registration_form."+prefix+"delivery_postcode.value = document.registration_form."+prefix+"postcode.value");
	 }
								 
});




