$(document).ready(function() {



  // Filters



  $("#filters li a").not("#filters li ul li a").click(

    function() {

    $(this).siblings("ul").slideToggle("fast", function() {

      $(this).parent("li").toggleClass("open");

    });

    return false;

  });



  // Related Products



  $(".related-products .arrow-next").click(

    function() {

    var arrow = $(this);

    $(this).siblings(".loadin").fadeOut('fast', function() {

      var prodid = $(arrow).parent(".related-products").attr("id");

      var current = $(arrow).siblings(".loadin").children(".rel_next").attr('title');

      $(arrow).siblings(".loadin").load('/components/ajax/related-products.html?id='+prodid+';current='+current);

      $(arrow).siblings(".loadin").fadeIn('fast');

    });

    return false;

  });



  $(".related-products .arrow-prev").click(

    function() {

    var arrow = $(this);

    $(this).siblings(".loadin").fadeOut('fast', function() {

      var prodid = $(arrow).parent(".related-products").attr("id");

      var current = $(arrow).siblings(".loadin").children(".rel_prev").attr('title');

      $(arrow).siblings(".loadin").load('/components/ajax/related-products.html?id='+prodid+';current='+current);

      $(arrow).siblings(".loadin").fadeIn('fast');

    });

    return false;

  });



  // Left Column Popular & Offers



  $("#leftcol .tab-box div .arrow-next").click(

    function() {

    var arrow = $(this);

    $(this).siblings(".loadin").fadeOut('fast', function() {

      var type = $(arrow).parent("div").attr("class");

      var current = $(arrow).siblings(".loadin").children(".rel_next").attr('title');

      $(arrow).siblings(".loadin").load('/components/ajax/special-popular-products.html?type='+type+';current='+current);

      $(arrow).siblings(".loadin").fadeIn('fast');

    });

    return false;

  });



  $("#leftcol .tab-box div .arrow-prev").click(

    function() {

    var arrow = $(this);

    $(this).siblings(".loadin").fadeOut('fast', function() {

      var type = $(arrow).parent("div").attr("class");

      var current = $(arrow).siblings(".loadin").children(".rel_prev").attr('title');

      $(arrow).siblings(".loadin").load('/components/ajax/special-popular-products.html?type='+type+';current='+current);

      $(arrow).siblings(".loadin").fadeIn('fast');

    });

    return false;

  });



  // Homepage Popular & Offers



  $(".home-right .tab-box div .arrow-next").click(

    function() {

    var arrow = $(this);

    $(this).siblings(".loadin").fadeOut('fast', function() {

      var type = $(arrow).parent("div").attr("class");

      var current = $(arrow).siblings(".loadin").children(".rel_next").attr('title');

      $(arrow).siblings(".loadin").load('/components/ajax/special-popular-products.html?type='+type+';current='+current+';location=home');

      $(arrow).siblings(".loadin").fadeIn('fast');

    });

    return false;

  });



  $(".home-right .tab-box div .arrow-prev").click(

    function() {

    var arrow = $(this);

    $(this).siblings(".loadin").fadeOut('fast', function() {

      var type = $(arrow).parent("div").attr("class");

      var current = $(arrow).siblings(".loadin").children(".rel_prev").attr('title');

      $(arrow).siblings(".loadin").load('/components/ajax/special-popular-products.html?type='+type+';current='+current+';location=home');

      $(arrow).siblings(".loadin").fadeIn('fast');

    });

    return false;

  });



  // Popular & Offers Tabs



  $("dl.tabs dt").click(

    function() {

    $(this).siblings("dt").removeClass('selected');

    $(this).addClass('selected');

    var type = $(this).attr("title");

    $(this).parent("dl.tabs").siblings("div").hide();

    $(this).parent("dl.tabs").siblings("."+type).show();

  });



  // Homepage Promos



  $('#promo-img').after('<ul id="promo-nav">').cycle({

    fx:     'fade',

    speed:   1000,

    timeout: 7000,

    backwards: false,

    pager:  '#promo-nav',

    pagerAnchorBuilder: function(idx, slide) {

        return '<li><a href="#">' + $(slide).children('img').attr('alt') + '</a></li>'; 

    }

  });

  

   // official messages



  $('#official-img').after('').cycle({

    fx:     'fade',

    speed:   1000,

    timeout: 7000,

    backwards: true,

    pager:  '',

    pagerAnchorBuilder: function(idx, slide) {

        return '>' + $(slide).children('img').attr('') + ''; 

    }

  }); 



  // Basket Increment and Decrement on Quantity box



  $(".quantity .increment").click(

    function() {

    var target = $(this).parent(".quantity").children("input");

    if (target.attr('value') > 0) {

      target.attr('value', parseInt(target.attr('value')) - 1);

    }

  });



  $(".quantity .decrement").click(

    function() {

    var target = $(this).parent(".quantity").children("input");

    if (parseInt(target.attr('value')) * 1 != parseInt(target.attr('value'))) {

      target.attr('value', '1');

    } else {

      target.attr('value', parseInt(target.attr('value')) + 1);

    }

  });



  $("a#bigPicLink").fancybox();

  $(".thumbnails .boxed").fancybox();

  $(".fancybox").fancybox();





});
