$(document).ready(function() {
		$(".quickshop").fancybox({'autoScale': false, 'autoDimensions': false, 'width': 870, 'height': '85%', 'type': 'inline', 'titleShow': false, 'overlayColor': '#000', 'overlayOpacity': '0.4' });
		$("a.fancybox").fancybox({'titlePosition': 'inside', 'overlayColor': '#000', 'overlayOpacity': '0.4', 'autoScale': true, 'scrolling': 'auto', 'centerOnScroll': true });
		//Bind ajax global events
		$("#ajaxloader").bind("ajaxStart", function(){
		   $(this).show();
		 }).bind("ajaxStop", function(){
		   $(this).hide();
		   //Fancybox
		   $(".quickshop").fancybox({'autoScale': false, 'autoDimensions': false, 'width': 870, 'height': '85%', 'type': 'inline', 'titleShow': false, 'overlayColor': '#000', 'overlayOpacity': '0.4' });	
		   //Image mouseover tooltip
		   initTooltip();
		   
		 });
		
		$('.menuPT').ptMenu();
        $('#slider1').bxSlider({ mode: 'fade', controls: false, pager: true, autoHover: false, auto: true, speed: 1000, pause: 8000 });
        $('#slider2').bxSlider({ mode: 'fade', controls: false, pager: true, autoHover: false, auto: true, speed: 1000, pause: 8000 });
        $('#slider3').bxSlider({ mode: 'fade', controls: false, pager: true, autoHover: false, auto: true, speed: 1000, pause: 8000 });
		$('#related').bxSlider({ autoHover: true, auto: true, speed: 500, pause: 8000, displaySlideQty: 4, moveSlideQty: 1, prevText: '', nextText: '' });
		initTooltip();	
    
    countdown_number = 0;    
	$('.cart a').hover(
		function () {
			//show			
			if(countdown_number == 0)
			{
				$('.foldOut', this).slideDown();
			}
			startCountdown();
		}, 
		function () {
			//hide
			$('.foldOut', this).slideUp();
			$(".cart").click(function () { 
      		$('.foldOut',this).hide(); 
    		});	
		}
	);

		
	//slideshow on the homepage
	$('#slideshow').cycle({ fx: 'scrollVert', speed: 700, timeout: 11000, pager: '#ssItems', 
		pagerAnchorBuilder: function(idx, slide) { 
			return '<li><a href="#">' + slide.title + '</a></li>'; 
		}
	});
  	
});
function startCountdown()
{
	countdown_number = 1;
	countdown = setTimeout('resetCountdown()', 1000);
}
function resetCountdown()
{
	clearTimeout(countdown);	
	countdown_number = 0;	
}
function initTooltip()
{
	$("a.tt").tooltip({ offset: [0, 0], position: 'center left'});
}
function addProduct(productId, quantity)
{
	$('#ProductID').val(productId);
	$('#quantity').val(quantity);
	$('#prodform').submit();	

}
function UpdateCart(orderId) {
	var $theForm = $("#CartForm" + orderId);	 	
	$theForm.submit();
}
function increaseAmount(spanID, max, orderLineID)
{
	
	var $element;
	if(orderLineID == null)
	{$element = $('#' +spanID);}
	else
	{$element = $('#' + spanID + orderLineID)}
	
	var currentAmount = parseInt($element.text());
	if(currentAmount != max)
	{
		$element.text(currentAmount + 1);	
	}
}
function decreaseAmount(spanID,orderLineID)
{

	var $element;
	if(orderLineID == null)
	{$element = $('#' +spanID);}
	else
	{$element = $('#' + spanID + orderLineID)}
	 
	var currentAmount = parseInt($element.text());
	if(currentAmount != 1)
	{
		$element.text(currentAmount - 1);
	}
}

function SetCheck(id, val)
{
	if(val == 'yes')
		document.getElementById(id).checked = true;
	else
		document.getElementById(id).checked = false;
}
function closeFancy()
{	
	$.fancybox.close();
	
}
function getQuerystring(key, default_)
{
  if (default_==null) default_=""; 
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(window.location.href);
  if(qs == null)
    return default_;
  else
    return qs[1];
}
 
