

/* extra */

$(document).ready(function() {

  var download_slider = jQuery.cookie.get('download_slider');
  
  if (download_slider == 1) {
	$('#slider_download_open').show();
	$('#slide_top_line').show();
	$('#slide_download').hide();
  } else {
	$('#slider_download_open').hide();
	$('#slide_top_line').hide();
  }
  
	$('.slide_close').click(function() {
		$('#slide_download').slideUp('slow', function() {
			$('#slide_top_line').show();
			$('#slider_download_open').show();
			jQuery.cookie.set('download_slider', 1);
		});
	});
	
	$('#slider_download_open').click(function() {
		$('#slider_download_open').hide();
		$('#slide_top_line').hide();
		$('#slide_download').slideDown('slow', function() {
			jQuery.cookie.set('download_slider', 0);
		});
	});
	
    $("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)  
  
    $("ul.topnav li").click(function() { //When trigger is clicked...  
  
        //Following events are applied to the subnav itself (moving subnav up and down)  
        $(this).find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click  
  
        $(this).hover(function() {  
        }, function(){  
            $(this).find("ul.subnav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up  
        });  
  
        //Following events are applied to the trigger (Hover events for the trigger)  
        }).hover(function() {  
            $(this).addClass("subhover"); //On hover over, add class "subhover"  
        }, function(){  //On Hover Out  
            $(this).removeClass("subhover"); //On hover out, remove class "subhover"  
    });  
	/*
  $(".rounded-img").load(function() {
    $(this).wrap(function(){
      return '<span class="span-pop ' + $(this).attr('class') + '" style="background:url(' + $(this).attr('src') + ') no-repeat center center; width: ' + $(this).width() + 'px; height: ' + $(this).height() + 'px;" />';
    });
    $(this).css("opacity","0");
  });
  */
	/*
  $(".rounded-img").load(function() {
    $(this).wrap(function(){
      return '<div class="icon"' + '" style="background:url(' + $(this).attr('src') + ') no-repeat center center; width: ' + $(this).width() + 'px; height: ' + $(this).height() + 'px;"><div class="shine"></div></div>';
    });
    $(this).css("opacity","0");
  });
*/
  /*
$(".tt_trigger").tooltip({

   // tweak the position
   offset: [10, 2],

   // use the "slide" effect
   effect: 'slide'

// add dynamic plugin with optional configuration for bottom edge
}).dynamic({ bottom: { direction: 'down', bounce: false } });

*/
/*
$('.span-pop').live('mouseover mouseout', function(event) {
  if (event.type == 'mouseover') {
            $(this).css('opacity', 0.7);

  } else {
            $(this).css('opacity', 1);

  }
});
*/

$('.tt_trigger').live('mouseover mouseleave', function(event) {
  if (event.type == 'mouseover') {
    
    /*
            $(this).find('.shine').stop(true, true).fadeOut(150, function(){
		$(this).parent().css({"box-shadow": "0px 2px 3px rgba(0, 0, 0, 0.7)"});
	    });
	 */
             $(this).find('.shine').stop(true, true).animate({opacity:0.5}, 150, function(){
		$(this).parent().css({"box-shadow": "0px 2px 3px rgba(0, 0, 0, 0.7)"});
	    });

  } else {
    /*
            $(this).find('.shine').stop(true, true).fadeIn(100, function(){
		$(this).parent().css({"box-shadow": "0px 4px 6px rgba(0, 0, 0, 0.5)"});
	    });
*/
            $(this).find('.shine').stop(true, true).animate({opacity:1}, 100, function(){
		$(this).parent().css({"box-shadow": "0px 4px 6px rgba(0, 0, 0, 0.5)"});
	    });
	     
  }
});
/*
$('.tt2').live('mouseover mouseout', function(event) {
  if (event.type == 'mouseover') {
            $(this).parent().find('.span-pop').css('opacity', 0.7);

  } else {
            $(this).parent().find('.span-pop').css('opacity', 1);

  }
});
*/
/*
$('html').click(function() {
	$('.pulldown').fadeOut(250);
	$('#categories, #locations').removeClass('open');
});

$('#categories, #locations').click(function(event){
		event.stopPropagation();
});
*/

$('#categories a').live('click', function(){
  
	$('#locations > .pulldown').fadeOut(250);
	$('#locations').removeClass('open');
  
  if ($('#categories > .pulldown').is(":visible")) {
	$('.pulldown').fadeOut(250);
	$('#categories').removeClass('open');
  } else {
	$('#categories > .pulldown').fadeIn(150);
	$('#categories').addClass('open');
  }
});

$('#locations a').live('click', function(){
	$('#categories > .pulldown').fadeOut(250);
	$('#categories').removeClass('open');
  
  if ($('#locations > .pulldown').is(":visible")) {
	$('.pulldown').fadeOut(250);
	$('#locations').removeClass('open');
  } else {
	$('#locations > .pulldown').fadeIn(150);
	$('#locations').addClass('open');
  }
});

$('#clear_search').live('click', function(){
	jQuery.ajaxRequest(fn_url('products.search?search_performed=Y'+'&cid='+ $('#scid').val() + '&sort_by='+ $('#ssort_by').val() + '&sort_order='+ $('#ssort_order').val()), {result_ids: 'pagination_contents'});
});

     var T = undefined, S = 0, D = 1000;
     
     $('#live_search').live("keypress", onKeyPress);
     
     function onKeyPress() {
        clearTimeout(T);
        if (S == 0) { S = new Date().getTime(); D = 1000; T = setTimeout(onTimeOut, 1000); return; }
        var t = new Date().getTime();
        D = (D + (t - S)) / 2; S = t; T = setTimeout(onTimeOut, D * 2);
     }
 
      function onTimeOut() {
           S = 0;
	  /* jQuery.ajaxRequest('{"products.search?search_performed=Y"+|fn_url:'C':'rel':'&'}', {result_ids: 'pagination_contents'});*/
	     
	   jQuery.ajaxRequest(fn_url('products.search?search_performed=Y'+'&cid='+ $('#scid').val() + '&q='+ $('#live_search').val() + '&sort_by='+ $('#ssort_by').val() + '&sort_order='+ $('#ssort_order').val()), {result_ids: 'pagination_contents', callback: q_string_focus});
      }

      function q_string_focus() {
	if ($('#live_search').val()) {
	 $('#live_search').focus();
	 $('#live_search').setCursorPosition($('#live_search').val().length);
	 $('#clear_search').show();
	}
      }

function run() {
  jQuery('.helper-container').css('min-height',(getClientHeight() - parseInt(jQuery('#footer').css('height')) - 109)+'px');
};

  run();
  
  
        $('.flexslider').flexslider({slideshowSpeed: 5000, slideshow: true, animationDuration: 1000, pauseOnHover: true, keyboardNav:false, controlNav:false, directionNav: false});
  
  
});



new function($) {
  $.fn.setCursorPosition = function(pos) {
    if ($(this).get(0).setSelectionRange) {
      $(this).get(0).setSelectionRange(pos, pos);
    } else if ($(this).get(0).createTextRange) {
      var range = $(this).get(0).createTextRange();
      range.collapse(true);
      range.moveEnd('character', pos);
      range.moveStart('character', pos);
      range.select();
    }
  }
}(jQuery);

function getClientHeight() {
 if (window.opera) {
  return (self.innerHeight || ( de && de.clientHeight ) || document.body.clientHeight);
 } else {
  return document.compatMode=='CSS1Compat'?document.documentElement.clientHeight:document.body.clientHeight;
 }
}


/* /extra */
