jQuery(function(){
  jQuery('#navigation ul').superfish();
});


Cufon.set('selector', jQuery);
Cufon.replace('#nav_14623 a, h3, #customers, .mback, h1', { fontFamily: 'gourdy', hover: true});
Cufon.replace('#navigation #enquire, .smhead, #customers, #home-content h1, #home-content h2, #pages h2, #pages h3, #pages #article-inner h5', { fontFamily: 'gourdy-bold', hover: true});

$(document).ready(function() {
  
  $('#nav_14623 li:first-child a').css('border-left', 'none');
  $('#nav_14623 li:last-child a').css('border-right', 'none');
  $('.productList li.productItemLast, .catalogueList li.catalogueItemLast').addClass('catalogueItem');
  $('.productList li.productItem:nth-child(4n), .catalogueList li.catalogueItem:nth-child(4n), #related td:nth-child(4n)').addClass('last');

  $('#cta-cycle').cycle({
    pager: '#cyclenav',
    fx: 'none',
    pagerEvent: 'mouseover',
    timeout: 0,
    pagerAnchorBuilder: function(idx, slide) 
      { 
        // var text = $(slide).eq(0).attr("title");
        if(idx == 0) {   
          return '<li><span class="name">DIAMOND RINGS</span><a href="/rings/"><span class="inner-span">Start Shopping</span></a><img src="/images/diamond-ring-cycle.png" alt="diamond ring" width="151" height="118" /></li>';
        }
       
        if(idx == 1) {   
          return '<li><span class="name">DIAMOND EARRINGS</span><a href="/earrings/"><span class="inner-span">Start Shopping</span></a><img src="/images/diamond-earring.png" alt="diamond earring" width="151" height="118" /></li>';
        }
         
        if(idx == 2) {   
          return '<li style="margin:0;"><span class="name">DIAMOND PENDANTS</span><a href="/pendants/"><span class="inner-span">Start Shopping</span></a><img src="/images/diamond-pendant.png" alt="diamond pendant" width="151" height="118" /></li>';
        }
      }
  });
  
  // reset margin for the last LI. Needs to be after the cycle function 
  // This does not work in webkit due to a bug.
  //  $('#cyclenav li:last-child').css('margin', 0);
    
 /* $('#cycle-wrapper-new .productfeaturelist tbody').cycle({
        fx:    'none',
        timeout:  0,
        pager:   '#featurecyclenav'
        
  });
  
  $('#cycle-wrapper-best .productfeaturelist tbody').cycle({
        fx:    'none',
        timeout:  0,
        pager:   '#featurecyclenav-best'
        
  }); */
  
  $('.hinput input[type="text"]').focus(function() {
    $(this).css({'background-color' : '#F0F3F7', 'color' : '#5A6368'});
    myVal = $(this).val();
    // Value of the fields we wish to transition.
    if($(this).val() == "Name" || $(this).val() == "Enter your email" || $(this).val() == "Email") {  
      $(this).val("");
    }
  });
   //if value is empty replace with global var set in above function
   $('.hinput input[type="text"]').blur(function() {
    $(this).css({'background-color' : '#fff', 'color' : '#b7b7b7'});
    if($(this).val() == "") {  
      $(this).val(myVal);
    }
   });

  
  $('#cyclenav li a').click(function() {
    var thisLink = $(this).attr('href');
    //window.location.replace(thisLink);
    window.location.href = thisLink;

  });
  
  
  
  $('.small-details a').text('View Details');
  
  $('.description table').clone().appendTo('#tableDescription');
  $('#addToBag').click(function() {
    $('.description table').clone().appendTo('#tableDescription');
    $('.small-details a').text('View Details');
    
    $('#tableDescription table tbody tr:nth-child(even)').css('background', '#e1e5ea');
    $('#tableDescription table tbody tr:first-child').css({'background' : '#abbfd8', 'color' : '#fff', 'font-weight' : 'bold'});
	 $('.productList li.productItem:nth-child(4n), .catalogueList li.catalogueItem:nth-child(4n), #related td:nth-child(4n)').addClass('last');
    
  });
  
  
  
  
  $('#tableDescription table tbody tr:nth-child(even)').css('background', '#e1e5ea');
  $('#tableDescription table tbody tr:first-child').css({'background' : '#abbfd8', 'color' : '#fff', 'font-weight' : 'bold'});
  $('#pages #article-inner table tr:first-child').css({'background' : 'rgb(31, 73, 125)', 'color' : '#fff'});
  $('.catalogueitemdump li:last-child').addClass('last');
  
  // remove last 3 characters of price class. 
  //$(function(){
  
  $('.price, .retail-price p, .saving-price p').each(function() {  
    
    //var $elem = $('.price');
    var $str = $(this).html();
    var $strtemp = $str.substr(0,$str.length -3);
    $(this).html($strtemp);
  });
  
  $('#myproductSearch2level li a').click(function(event) {
    event.preventDefault();
  });
  
  $('#myproductSearch2level li').click(function() {
    var priceRange = ($('#myproductSearch2level li').index(this));
    var currentPrice = $(this).text();
    $('#current-price span').text(currentPrice);
    $('.product-form #CAT_ProductPrice option').eq(priceRange).attr('selected', 'selected'); 

  });
  
  $(".sale_noclearance").css('display', 'none');
  
});


