function LightBox()
{
  var width = document.documentElement.clientWidth + document.documentElement.scrollLeft;

  var layer = document.createElement('div');
  layer.style.zIndex = 90;
  layer.id = 'layer';
  layer.style.position = 'absolute';
  layer.style.top = '0px';
  layer.style.left = '0px';
  layer.style.height = document.documentElement.scrollHeight + 'px';
  layer.style.width = width + 'px';
  layer.style.backgroundColor = 'black';
  layer.style.opacity = '.6';
  layer.style.filter += ("progid:DXImageTransform.Microsoft.Alpha(opacity=60)");
  document.body.appendChild(layer);

/*
  var div = document.createElement('div');
  div.style.zIndex = 3;
  div.id = 'box';
  div.style.position = (navigator.userAgent.indexOf('MSIE 6') > -1) ? 'absolute' : 'fixed';
  div.style.top = '200px';
  div.style.left = (width / 2) - (400 / 2) + 'px'; 
  div.style.height = '50px';
  div.style.width = '400px';
  div.style.backgroundColor = 'white';
  div.style.border = '2px solid silver';
  div.style.padding = '20px';
  document.body.appendChild(div);

  var p = document.createElement('p');
  p.innerHTML = '<span class="title">Sign In</span>';
  div.appendChild(p);

  var a = document.createElement('a');
  a.innerHTML = 'Sign In';
  a.href = 'javascript:void(0)';
  a.onclick = function()
  {
    document.body.removeChild(document.getElementById('layer'));
    document.body.removeChild(document.getElementById('box'));
  };
  div.appendChild(a);
  */
}

jQuery.fn.delay = function(time,func){
	this.each(function(){
		setTimeout(func,time);
	});
	
	return this;
};


 $(function() {
 	$("img").lazyload({ 
		placeholder : "images/grey.gif",
		effect : "fadeIn"
	});
});



function CloseLogin() {
	  if(document.getElementById('layer')){document.body.removeChild(document.getElementById('layer'))};
	  document.getElementById("LoginBox").style.display="none";
}

	/* THIS LOADS THE SLIDER */
	$(document).ready(function(){	
	
	$(".Photo").jqzoom({
		zoomWidth: 350,		//zoomed width default width
        zoomHeight: 300,		//zoomed div default width
		title : false,
		alwaysOn: false,
		showEffect: 'show',
		hideEffect: 'hide',
		fadeinSpeed: 'fast',
		fadeoutSpeed: 'slow'
	});
	
	
	LoadAutoExpandingTextArea();
	
	
	
	
});	
	
function AutoExpandFix() {
	
	$(this).delay(500,function(){
		LoadAutoExpandingTextArea();
  });

}

function LoadAutoExpandingTextArea() {
	// Expanding text areas
	$('textarea.expanding').autogrow({
		maxHeight: 100,
		minHeight: 10
	});
}

function SwitchThumb(newSrc) {
	var Photo = document.getElementById("ctl00_ContentPlaceHolder1_Photo");
	var PhotoLink = document.getElementById("ctl00_ContentPlaceHolder1_PhotoZoom");
	Photo.src=newSrc.replace(/width=90/, "width=240");
	PhotoLink.href=newSrc.replace(/width=90/, "width=800");
}

function ShowMiniCart() {
	$(".MiniCart").slideDown("slow");
	$(this).delay(3500,function(){
		//CloseMiniCart();
  });
	CloseWishBowl();
}

function DisplayMiniCart() {
	$(".MiniCart").slideDown("slow");
	CloseWishBowl();
}

function CloseMiniCart() {
	$(".MiniCart").fadeOut("fast");
}

function CloseWishBowl() {
	$(".WishBowl").fadeOut("fast");
}

function ShowWishBowl() {
	$(".WishBowl").slideDown("slow");
	$(this).delay(3500,function(){
		//CloseMiniCart();
		
	var productname = document.getElementById("ctl00_ContentPlaceHolder1_ProductTitle").innerHTML;
	var productlabel = document.getElementById("ctl00_WishBowl_ProductName");
	//productlabel.innerHTML = productname;
	document.getElementById("ctl00_requestbtn").style.visibility="visible";
  });
	CloseMiniCart();
}

function LoadPopup() {
	LightBox();
	document.getElementById("PopupPanel").style.display="block";
	$(this).delay(1000,function(){
		$("#popup_loader_img").fadeOut("fast");
			$(this).delay(500,function(){
				$("#mid").slideToggle(100);							
			});
  	});
}

function ClosePopup() {
	$("#layer").fadeOut("fast");
	$("#PopupPanel").fadeOut("slow");
	$(this).delay(1000,function(){
		if(document.getElementById('layer')){document.body.removeChild(document.getElementById('layer'))};
		$("#popup_loader_img").fadeIn("fast");
		$("#mid").slideToggle(100);
	});
}


/*** 
    Simple jQuery Slideshow Script
    Released by Jon Raasch (jonraasch.com) under FreeBSD license: free to use or modify, not responsible for anything, etc.  Please link out to me if you like it :)
***/

function slideSwitch() {
    var $active = $('#slideshow a.active');

    if ( $active.length == 0 ) $active = $('#slideshow a:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow a:first');

    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "slideSwitch()", 5000 );
});

function checkIt(evt) {
    evt = (evt) ? evt : window.event
    var charCode = (evt.which) ? evt.which : evt.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        status = "This field accepts numbers only."
        return false
    }
    status = ""
    return true
}

function ShowHideSearch() {
    $(".SiteSearch").toggleFade({ speedIn : "fast"});
	document.getElementById("ctl00_SearchBox").focus();
}

function ShowHide_VocherBox() {
	$('.VoucherPopup').toggle(400);
	 if(document.getElementById('layer')){
		 document.body.removeChild(document.getElementById('layer'));
	} else {
		LightBox();
	}
    return false;
}

function VoucherCheck() {
	$(this).delay(1000,function(){
		$('.VoucherPopup').toggle(400);
	});
}

