// JavaScript Document
// DOM READY FUNCTIONS

function callslider(defh){

    defh = defh-168;

	

	if(defh < 168)
	{
		$('.content-slider').hide();
	}
	else
	{


		$('.content-slider-inner').slider({
		orientation: "vertical",
		min: 0,
		max: defh,
		value: defh,
		handle: '.content-handle',
		stop : function (event, ui) {
			$('.description-content p').animate({
			'top' : ui.value - defh
			}, 500);
		},
		slide : function (event, ui) {
			$('.description-content p').css('top', ui.value - defh);
		}
		});
	}
}

basket_ajax = function(overlay_container) {
    overlay_container.css({
	'width': 695, 
	'height': 620,
	'left': '50%',
	'top': 28,
	'marginLeft': -78
    });

    $.ajax({
	type: 'GET',
	dataType: 'json',   
	url: '/basket/ajax',
	success: function(data){
		console.log(data);
	    overlay_container.append(data.html);
	    $('.quick_close').click(overlay_close);
	    $('#ajax_basket .select-items').selectbox();
	},
	error: function(data) {
	    console.log(data.statusText, data.responseText);
	}
    });

	
}

$(document).ready(function(){


    $('.btn_my_cart').live('click', function() {	
		overlay(basket_ajax);
		return false;
    });


    $('#s1').cycle({
	fx:     'scrollHorz',
	prev:   '.rack_arrow1',
	next:   '.rack_arrow2',
	timeout: 11000,
	pager:  '.rack_nav'
    });

    $('.rack_nav a').text('');


    $('#subcat').click(function(){
	$('.tool_type').find('div').hide();
	var cont1 = $('#imgcat').html();
	$('.tool_type').html(cont1);
	$('.tool_type ul').superfish();
		
    });
	
    $('.s2').cycle({
	fx:     'scrollHorz',
	prev:   '.corosel_arrow1',
	next:   '.corosel_arrow2',
	timeout: 0
    });
						   
    $('.tool_type').hide();
    $('#tool_type_menu').click(function(){
	$('.tool_type').slideDown();
	return false;
    });
    $('#tool_type_menu').mouseleave(function(){
	$('.tool_type').mouseleave(function(){
	    $('.tool_type').slideUp();
	});
    });
    //    $('#my-cart').click(function(){
    //	$('.shopping').fadeIn('slow');
    //	$(this).addClass('active');
    //    });
    //    $('.my-cart-close').click(function(){
    //	$('.shopping').fadeOut('slow');
    //	$('#my-cart').removeClass('active');
    //    });
    //select all the a tag with name equal to modal
    $('a[name=modal]').click(function(e) {
	//Cancel the link behavior
	e.preventDefault();
	//Get the A tag
	var id = $(this).attr('href');
     
	//Get the screen height and width
	var maskHeight = $(document).height();
	var maskWidth = $(window).width();
     
	//Set height and width to mask to fill up the whole screen
	$('#mask').css({
	    'width':maskWidth,
	    'height':maskHeight
	});
         
	//transition effect
	$('#mask').fadeIn(1000);
	$('#mask').fadeTo("slow",0.8);
     
	//Get the window height and width
	var winH = $(window).height();
	var winW = $(window).width();
               
	//Set the popup window to center
	$(id).css('top',  winH/2-$(id).height()/2);
	$(id).css('left', winW/2-$(id).width()/2);
     
	//transition effect
	$(id).fadeIn(2000,function(){
	    var pheight = $('.description-content p').height();
	    pheight -= 168;
	    callslider(pheight);
	});
     
    });
     
    //if close button is clicked
    $('.window .quick_close ,.window .quick_close2 ').click(function (e) {
	//Cancel the link behavior
	e.preventDefault();
	$('#mask, .window').hide();
    }); 
	
    if($('.select-items').length > 0)
    {

		$('.select-items').selectbox();
    }
	
    /*if($('.slider-handle').length > 0)
	{
	 $('.slider-handle').slider({
	  min: 0,
	  max: 2000,
	  value: 1000,
	  handle: '.handle',
	  stop : function (event, ui) {
		  //$('div.slideshow').animate({'left' : ui.value * -1}, 500);
	  },
	  slide : function (event, ui) {
		 // $('div.slideshow').css('left', ui.value * -1);
	  }
	 
  });	
	}*/
	 
	
    $(".CheckBoxClass").change(function(){
	if($(this).is(":checked")){
	    $(this).next("label").addClass("LabelSelected");
	}else{
	    $(this).next("label").removeClass("LabelSelected");
	}
    });


    $(".CheckBoxClass2").change(function(){
	if($(this).is(":checked")){
	    $(this).next("label").addClass("LabelSelected2");
	}else{
	    $(this).next("label").removeClass("LabelSelected2");
	}
    });
}); // DOM READY CLOSES



$(document).ready(function(){

	$('.btn_update_qty').live('click', function() {
		$(this).parents('form').submit();
		return false;
	});

    $('.tool_type_nav ul').superfish();

    if($('#impact_top').length > 0)
    {
	$('#tool_type_menu').parent().addClass('active');
    }

    $('.CheckBoxLabelClass').addClass('LabelSelected');

    $('.CheckBoxLabelClass2').click(function() {
	$('.utility').each(function() {
				
	    if($('.brand_id', this).text()==40)
		$(this).hide();

	});
    });

    $('._searchForm').submit(function() {
	location.href = '/categories/search/'+$('.searchQuery').val();
	return false;
    });
    $('._mainSearch').submit(function() {
	getProducts();
	return false;
    });
//    $('.checkbox').click(function() {
//	$(this).parent().find('.checkbox').removeClass('active');
//	$(this).addClass('active');
//    });
});
window.onunload= function() {};

var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-208287-5']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
