$( document ).ready(function() {

       if ($('#ct_breadcrumbs').length > 0) {

      var breadcrumb = $("#ct_breadcrumbs").html();
      $("#ct_breadcrumbs").remove();
      $("#ct_template_content_main").prepend('<div id="ct_breadcrumbs">'+breadcrumb+'</div>');

      $('#ct_breadcrumbs').prepend('<a href="/homepage">Home</a> >');

      var myArray = new Array();
      var i = 0;
      $('#ct_breadcrumbs > a').each( function() {
         val = $(this).text();
         myArray[i] = val;
         i++;
   
      });
      var page = myArray[1];
  }

     var pathname = window.location.pathname;
   
   if ($('.ct_searchType_category').length > 0) {  
       if (pathname.indexOf('/c/') > -1) {
          if ($('#ct_breadcrumbs').length == 0) {
             $('#ct_template_content_main').prepend('<div id="ct_breadcrumbs"><a href="/homepage">Home</a> > <span id="ct_breadcrumbs_curent">' + $('#ct_sh_title').text() + '</span></div>');
          }
      }
   }

     if ($('#ct_checkoutTrail').length > 0) {   
       $('#ct_template_content_left').css('display', 'none');
       
     }

     if ($('#ct_accountDetails').length > 0) { 
     $( "#ct_accountDetails a" ).first().remove();
     $('#ct_accountDetails h1').after('<p class="ct_oh_backLink"><a href="/account">« Account Options</a></p>');
   }

    if ($('#ct_addressOptions').length > 0) { 
     $('#ct_addressOptions h1').after('<p class="ct_oh_backLink"><a href="/account">« Account Options</a></p>');
   }

     if ($('#ct_accountCredit').length > 0) { 
     $('#ct_accountCredit h1').after('<p class="ct_oh_backLink"><a href="/account">« Account Options</a></p>');
   }

   if ($('#ct_wishlist').length > 0) { 
     $('#ct_wishlist h1').after('<p class="ct_oh_backLink"><a href="/account">« Account Options</a></p>');
   }

       

  
    

    


    if($("#ct_contact").length){
       $("#ct_c_message").html("Please enter your contact details (* required fields).");
        
    }

$('#ct_pd_product_description').before('<div class="sharing_container"></div>');
$('.sharing_container').append('<!-- Go to www.addthis.com/dashboard to customize your tools --><div class="addthis_sharing_toolbox"></div>');

$('#ct_wishlist h1').before('<div class="wishlist_container"></div>');
$('.wishlist_container').append('<!-- Go to www.addthis.com/dashboard to customize your tools --><div class="addthis_sharing_toolbox"></div>');


var str = $('#ct_l_guest p').text().replace(/Don't require an account: Guest Checkout/g, '');
$('#ct_l_guest').text(str);

 $('#ct_l_new_submit').after('<div id="ct_l_guest"><a href="/guest_checkout">Guest Checkout</a></div>');
 $('#ct_l_forgotten').insertAfter('#password');
$('head').append('<link rel="shortcut icon" type="image/icon" href="/layout/favicon.png">');
$('head').append('<link rel="icon" type="image/icon" href="/layout/favicon.png">');

$( '.my-signin' ).prepend( $( '#ct_template_header .ct_loginLink' ) );
if ($('.ct_loginLink a:contains(Logout)').length > 0) {
  $('.header-login').css("display", "none");
  $('#top-links .ct_loginLink').css("display", "block");
  $('.my-account').css("display", "block");
} 

//if ($('#ct_search').length > 0) { 
      //$('.ct_pl_product_price .ct_pl_product_link').text(function(index,text){
      //return text.replace('£','£');
      //});
      //if ($('.ct_pl_product_offPrice').length > 0) {
        //$('.ct_pl_product_offPrice .ct_pl_product_op_diff').text(function(index,text){
        //return text.replace('£','£');
        //});
        //$('.ct_pl_product_op_rrpDiff .ct_pl_product_op_rrp').text(function(index,text){
        //return text.replace('£','£');
        //});

      //} 

   //}
if ($('.ct_searchType_category').length > 0) {}
if ($('#ct_template_content_right .ct_smallBasket').length > 0) {
  $('#ct_template_content_right .ct_smallBasket').append('<div class="right-basket-links"><a href="/basket">View and Checkout</a><a href="/currency">Change Currency</a></div>');
}
//if ($('#ct_pd_product').length > 0) {

      //$('.ct_currencySymbol').text(function(index,text){
      //return text.replace('£','£'); });

      //if ($('.ct_pd_item_saving').length > 0) {
        //$('.ct_pd_item_saving').text(function(index,text){
      //return text.replace('£','£'); });
                //$('.ct_pd_item_saving').text(function(index,text){
      //return text.replace('£','£'); });

   //}
  //}


if ($('#ct_subCategories').length > 0) {
  if ($('.ct_sc_listing_cat_img').length > 0) {
    $('#ct_template_content_main').addClass('sub-img');
      $('.ct_sc_listing_cat').each(function() {
          if($('.ct_sc_listing_cat_img', this).length > 0) {
              console.log('Has Image');
          }
          else{
            var la = $(this).find('.ct_sc_listing_cat_name a').attr('href');
            $(this).prepend(' <div class="ct_sc_listing_cat_img"><a href="'+la+'"><img border="0" src="/layout/fmr.png" alt="" title="No Image Available"></a></div>');
          }
      });  
    }
  }
});$(document).ready(function(){

  var id="";
  if ($(".ct_pd_item_availability_in").length) {

    /* Preselect first available item */
    var styles = '';

    if($(".ct_pd_item_availability_in:first").parent().is('[id]')){
      id = $(".ct_pd_item_availability_in:first").parent().attr("id");
  
      var styles = id.split("_");
      
      for (i = 0; i < styles.length; ++i) {
        $('#ct_pd_optionsList .ct_pd_options_style option[value=' + styles[i] + ']').attr('selected','selected'); 
      }
    }

  } else {
    
    /* Preselect first item */

    $('#ct_pd_optionsList .ct_pd_options_style select').each(function(index) {

      if( $(this).children("option").length > 2 ){

        /* if less than 2 options (inc. 'select' text), RS preselect first option already */
        /* first option is the 'Select' text, :eq(1) to select 2nd option */
        $(this).children("option:eq(1)").attr('selected','selected'); 
        id += "_" + $(this).children("option:eq(1)").attr('value');

      } else {
        id += "_" + $(this).children("option:eq(0)").attr('value');
      }

    });

    id = id.substring(1);

  }

  /* Show item */
  if ( $("#ct_pd_itemList .ct_pd_item#"+id).length ) {
    $("#ct_pd_itemList .ct_pd_item#"+id).show();
  } else {
    $("#ct_pd_noStyle").show();
  }
  
if ($('#ct_pd_product').length > 0) {
  $('#ct_pd_bybrand,.sharing_container,#ct_pd_optionsList, #ct_pd_allItems,#ct_pd_itemList').wrapAll( '<div id="pd_wrap" />');
}

$('#ct_pd_product_description').wrapInner("<div id='productdetails_content' class='prodcontent on' />");

        $('#ct_pd_product_description').prepend('<div id="productdetails_tab" class="prodtab on">Description</div><div id="delivery_tab" class="prodtab off">Delivery</div>');
  
   $('#productdetails_content').after('<div class="prodcontent off" id="delivery_content"></div>');

   $('#delivery_content').load('/pg/40/Delivery-Message #ct_template_content_main #delivery-info ');

   $('.prodtab').click( function() {
      console.log($(this).attr('id'));
      $('.prodcontent').removeClass('on');
      $('.prodcontent').addClass('off');
      $('.prodtab').removeClass('on');
      $('.prodtab').addClass('off');

      var tab_id = $(this).attr('id');
      tab_id = tab_id.replace('tab', '');
      console.log(tab_id);

      $(this).removeClass('off');
      $(this).addClass('on');
      $('#' + tab_id + 'content').removeClass('off');
      $('#' + tab_id + 'content').addClass('on');
   });

});$( document ).ready(function() {

if ($('#ct_accountOptions').length > 0) { 
     $('#ct_template_content_main').addClass('account-page');
}
if ($('#ct_basket').length > 0) { 
     $('#ct_template_content_main').addClass('basket-page');
}
if ($('#ct_search').length > 0) { 
     $('#ct_template_content_main').addClass('category-page');
}
if ($('#ct_changeCurrency').length > 0) { 
     $('#ct_template_content_main').addClass('currency-page');
}
if ($('#ct_login').length > 0) { 
     $('#ct_template_content_main').addClass('login-page');
}
if ($('#ct_pd_product').length > 0) {
  $('#ct_template_content_main').addClass('product-page');
}
if ($('#ct_register').length > 0) { 
     $('#ct_template_content_main').addClass('register-page');
}
if ($('#ct_registerSuccess').length > 0) { 
     $('#ct_template_content_main').addClass('n-page');
}
if ($('#ct_orderHistory').length > 0) { 
     $('#ct_template_content_main').addClass('n-page');
}
if ($('#ct_reorder').length > 0) { 
     $('#ct_template_content_main').addClass('n-page');
}
if ($('#ct_accountDetails').length > 0) { 
     $('#ct_template_content_main').addClass('n-page');
}
if ($('#ct_addressOptions').length > 0) { 
     $('#ct_template_content_main').addClass('n-page');
}
if ($('#ct_accountCredit').length > 0) { 
     $('#ct_template_content_main').addClass('n-page');
}
if ($('#ct_delivery').length > 0) { 
     $('#ct_template_content_main').addClass('delivery-address-page');
}
if ($('#ct_courierServices').length > 0) { 
     $('#ct_template_content_main').addClass('courier-services-page');
}
if ($('#ct_basketSummary').length > 0) { 
     $('#ct_template_content_main').addClass('basket-summary-page');
}
});$( document ).ready(function() {
if ($('#ct_pd_product').length > 0) {
  console.log('Product Page');

      $('.ct_pd_item').each(function() {
          if($('.ct_pd_item_availability_out', this).length > 0) {
              $(this).find('.qtywrap').css('display', 'none');
              console.log('Out Stock');
          }
          else{
            console.log('In Stock');
          }
      });  

  }
});$( document ).ready(function() {
	if ($('#ct_template_header .ct_loginLink.ct_link_module').length > 0) {
		console.log('sign in yes');
		$('#nav-links li:nth-child(3)').append('<a href="../../../../account">Account/Logout</a>');
		if ($('.ct_loginLink a:contains("Logout")').length > 0) {
			console.log('contains logout');
			$('#nav-links li:nth-child(3) a:first-child').css('display', 'none');
		}
		else{
			$('#nav-links li:nth-child(3) a:last-child').css('display', 'none');
		} 
	}
});$(document).ready(function(){



    if ($('#ct_pd_product').length > 0) {

      $('.ct_currencySymbol').text(function(index,text){
      return text.replace('£','£'); });

      if ($('.ct_pd_item_saving').length > 0) {
        $('.ct_pd_item_saving').text(function(index,text){
      return text.replace('£','£'); });
        $('.ct_pd_item_saving').text(function(index,text){
      return text.replace('£','£');}

   }
 
}


});