$(document).ready(function(){
  
      $("#zip").focusout(function() {
 
          var text = $(this).val();
          
        	if(text.substring(2,0).toLowerCase() == "je") {
            $("#country").val("JE").attr('selected',true);
          }

        	if(text.substring(2,0).toLowerCase() == "gy") {
            $("#country").val("GY").attr('selected',true);
          }

      });

      $("#ship_postcode").focusout(function() {
 
          var text = $(this).val();
          
        	if(text.substring(2,0).toLowerCase() == "je") {
            $("#shipcountry").val("JE").attr('selected',true);
          }

        	if(text.substring(2,0).toLowerCase() == "gy") {
            $("#shipcountry").val("GY").attr('selected',true);
          }

      });
      

      

      $("#country").change(function() {
 
          var text = $("#zip").val();
          
        	if(text.substring(2,0).toLowerCase() == "je") {
            if ($("#country").val != "JE") {
              alert("You have entered a Jersey postcode and must select Jersey as your shipping country.");
              $("#country").val("JE").attr('selected',true);              
            }
          }

        	if(text.substring(2,0).toLowerCase() == "gy") {
            if ($("#country").val != "GY") {
              alert("You have entered a Guernsey postcode and must select Guernsey as your shipping country.");
              $("#country").val("GY").attr('selected',true);              
            }
          }




      });      
     
      $("#shipcountry").change(function() {
 
          var text = $("#ship_postcode").val();
          
        	if(text.substring(2,0).toLowerCase() == "je") {
            if ($("#shipcountry").val != "JE") {
              alert("You have entered a Jersey postcode and must select Jersey as your shipping country.");
              $("#shipcountry").val("JE").attr('selected',true);              
            }
          }

        	if(text.substring(2,0).toLowerCase() == "gy") {
            if ($("#shipcountry").val != "GY") {
              alert("You have entered a Guernsey postcode and must select Guernsey as your shipping country.");
              $("#shipcountry").val("GY").attr('selected',true);              
            }
          }




      });      
  
      $("a.brochure_link").click(function() {
        
        sucess_URL = $(this).attr("href");
        
       if ($.cookie('byba_answered_question_01') != '1') {
          tb_show("<strong>How did you hear about us?</strong>", "#TB_inline?height=190&width=275&inlineId=mypopup","");
          $.cookie('byba_answered_question_01', '1', { expires: 20 });
       } else {
          $(window.location).attr('href', $(this).attr("href"));
       }           
        
      	return false;
    });

    $(".view_all img").lazyload({
       placeholder : "/wp-content/themes/ba_bella_03/img/grey.gif",
       effect      : "fadeIn"
    });

  $('#breadcrumb_navigation').superfish(); 

    $(".view_zurfiz").click(function() {
     $(".accessories").hide("slow");
    	return false;
    });

    $(".view_bella").click(function() {
     $(".accessories").show("slow");
    	return false;
    });

//
//$('.sf-js-enabled li').hover(
//  function () {
//    $(("a:first-child", this)).animate({ width: "150px" })
//  }, 
//  function () {
//    $(("a:first-child", this)).css({ width: "" })
//  }
//);

  

  // redefine Cycle's updateActivePagerLink function 
  $.fn.cycle.updateActivePagerLink = function(pager, currSlideIndex) { 
      $(pager).find('a').removeClass('activeSlide') 
          .filter('a:eq('+currSlideIndex+')').addClass('activeSlide'); 
  }; 

	$("#main_00").after('<div id="pager_nav">').cycle({
		fx: 'scrollRight',
		timeout: 10000,
		speed: 2000,
    pager: '#pager_nav',	
		cleartypeNoBg: true,
		cleartype: true,
    // callback fn that creates a thumbnail to use as pager anchor 
    pagerAnchorBuilder: function(idx, slide) { 
        return '<a href="#">' + slide.title + '</a>'; 
    } 
	});
		
	$("div.zuriz").after('<div id="zurfiz_range" class="ranges_container"><ul>').cycle({
		fx: 'fade',
		timeout: 5000,
		speed: 2000,
    pager: '#zurfiz_range ul',
    pagerEvent: 'mouseover',
		pauseOnPagerHover: true, 
		cleartypeNoBg: true,
    allowPagerClickBubble: true,		
		cleartype: true,
    // callback fn that creates a thumbnail to use as pager anchor 
    pagerAnchorBuilder: function(idx, slide) { 
        return '<li><a href="' + slide.alt + '">' + slide.title + '</a></li>'; 
    } 		
	});

	$("div.bella").after('<div id="bella_range" class="ranges_container"><ul>').cycle({
		fx: 'fade',
		timeout: 5000,
		speed: 2000,
    pager: '#bella_range ul',
    pagerEvent: 'mouseover',
		pauseOnPagerHover: true, 
		cleartypeNoBg: true,
    allowPagerClickBubble: true,		
		cleartype: true,
    // callback fn that creates a thumbnail to use as pager anchor 
    pagerAnchorBuilder: function(idx, slide) {
        var range_id=slide.title.split(" ");
        return '<li id="' + range_id[0].toLowerCase() + '"><a href="' + slide.alt + '">' + slide.title + '</a></li>'; 
    } 	
	});
	
	$(".avante").cycle({
		fx: 'fade',
		timeout: 5000,
		speed: 2000,
    delay: 500,
		pauseOnPagerHover: true,
		cleartypeNoBg: true,
		cleartype: true
	});	
	
	$(".replacement").cycle({
		fx: 'fade',
		timeout: 5000,
		speed: 2000,
    delay: 500,
		pauseOnPagerHover: true,
		cleartypeNoBg: true,
		cleartype: true
	});		

    var clientHidden = 1;

    $("#client_area").click(function(){
    	if (clientHidden == 1) {
    		$("#clients").slideDown("slow", function() {
    			if ($.browser.msie) {
    				$("#clients").hide();
    				$("#clients").fadeIn("slow");
    			}				
    		});
    		clientHidden = 0;
    	} else {
    		$("#clients").slideUp("slow");
    		clientHidden = 1;
    	}
    	
    	return false;
    	
    });

    $("#arrow_right img").click(function(){
      $("#thumb_container").scrollTo( '+=825px', 1000, {axis:'x'} )
    });
    
    $("#arrow_left img").click(function(){
      $("#thumb_container").scrollTo( '-=825px', 1000, {axis:'x'} )
    });
    
    $("a.ultragloss-solid-colours").hover(function(){
      $("#thumb_container").scrollTo( '0px', 1000, {axis:'x'} )
    });    
    
    $("a.ultragloss-woodgrains").hover(function(){
      $("#thumb_container").scrollTo( '1320px', 1000, {axis:'x'} )
    });       

    $("a.matt-colours").hover(function(){
      $("#thumb_container").scrollTo( '2310px', 1000, {axis:'x'} )
    });       

    $("a.fantasy-colours").hover(function(){
      $("#thumb_container").scrollTo( '3630px', 1000, {axis:'x'} )
    });   
    
		clientHidden = 1;

    $("#ship_link").click(function(){
      $("#shipping").show();
    });		
    
   
	
		$("#clients").hide();
		$("#clients").css("display","none");
		$("#client_area").addClass("client_down");


    $("#thumbs a").hover(function(){
  		var largeAlt = $(this).attr("title");
  		var largeSrc = "/wp-content/uploads/" + largeAlt + "-440x326.jpg";
  		var proLink  = $(this).attr("href");
  		$("#main_img_a").attr({ href: proLink });
  		$("#main_img").attr({ src: largeSrc, alt: largeAlt });  		
  		
      
      $(this).fadeTo(50, 0.5);
      $(this).fadeTo(300, 1);
      
    });
    
    $(".hover_e a").hover(function(){		
      $(this).fadeTo(50, 0.5);
      $(this).fadeTo(300, 1);
      
    });    
	
});


function step_2(){
  $("#TB_window").animate({"top": "+=350px"}, "slow");
  $("#msg").html('<h3>Step 2</h3><p>Use the style slider to choose your door style, this will update the style to the door in the middle of the screen. <br /><strong>Please note: Not all colour and styles combinations are available.</strong></p><h4 style="text-align:right"><a id="step_2" style="font-weight:normal;" onclick="step_3();" href="#">Goto Step 3</a>');        
}	

function step_3(){
  $("#TB_window").animate({"left": "+=290px"}, "slow");
  $("#TB_window").animate({"top": "-=300px"}, "slow");  
  $("#msg").html('<h3>Step 3</h3><p>Use the images left and right to view kitchens in your style and colour.</p><p>You can also click on the door to order a sample in your choosen color and style.</p><h4 style="text-align:right"><a id="step_2" style="font-weight:normal;" onclick="tb_remove();" href="#">Close</a>');        
}	

function toggleit() {

	if (clientHidden == 1) {
		$("#clients").slideDown("slow", function() {
			if ($.browser.msie) {
				$("#clients").hide();
				$("#clients").fadeIn("slow");
			}				
		});
		clientHidden = 0;
	} else {
		$("#clients").slideUp("slow");
		clientHidden = 1;
	}

}

var item = 0;


function feedback(get_url) {
  
    item = get_url;
  

}

    

function feedback_dealer() {

   if ($.cookie('43626446464') != '1') {
    tb_show("<strong>How did you hear about us?</strong>", "#TB_inline?height=190&width=275&inlineId=mypopup","");
    $.cookie('43626446464', '1', { expires: 20 });
   } 
}

function cs_hellper() {

    tb_show("<strong>Colour and Styles helper</strong>", "http://www.byba.co.uk/cs_demo/demo_01.html?height=500&width=600","");
   
}


function getdata(list_item) {

 $.ajax({
   type: "POST",
   url: "/wp-content/plugins/ajax_calls_brochure.php",
   data: "selected="+list_item,
   success: function(results){
     tb_remove();
     window.location.href=sucess_URL;
   }
 });
  
  
  
}


function getdata_dealer(list_item) {

 $.ajax({
   type: "POST",
   url: "/wp-content/plugins/ajax_calls_brochure.php",
   data: "selected="+list_item,
   success: function(results){
     tb_remove();
   }
 });  
  
}
