


/*
delay function
*/
jQuery.fn.delay = function(time,func){
    return this.each(function(){
        setTimeout(func,time);
    });
};



/*
Strip whitespace from the beginning and end of a string
Input : a string
*/
function trim(str)
{
	return str.replace(/^\s+|\s+$/g,'');
}

/*
Make sure that textBox only contain number
*/
function checkNumber(textBox)
{
	while (textBox.value.length > 0 && isNaN(textBox.value)) {
		textBox.value = textBox.value.substring(0, textBox.value.length - 1)
	}
	
	textBox.value = trim(textBox.value);
/*	if (textBox.value.length == 0) {
		textBox.value = 0;		
	} else {
		textBox.value = parseInt(textBox.value);
	}*/
}

/*
	Check if a form element is empty.
	If it is display an alert box and focus
	on the element
*/
function isEmpty(formElement, message) {
	formElement.value = trim(formElement.value);
	
	_isEmpty = false;
	if (formElement.value == '') {
		_isEmpty = true;
		alert(message);
		formElement.focus();
	}
	
	return _isEmpty;
}

/*
	Set one value in combo box as the selected value
*/
function setSelect(listElement, listValue)
{
	for (i=0; i < listElement.options.length; i++) {
		if (listElement.options[i].value == listValue)	{
			listElement.selectedIndex = i;
		}
	}	
}

/* Accordian Script */
	$(document).ready(function(){
		$(".accordion h3:first").addClass("active");
		$(".accordion h3:first").hide();
		$(".accordion div:not(:first)").hide();
	
		   $(".accordion h3").click(function(){
			   $(this).next("div").slideToggle("10")
			   .siblings("div:visible").slideUp("10"); 
			   $(this).animate({ opacity: "hide" }, "fast");
			   $(this).toggleClass("active");
			   $(this).siblings("h3").removeClass("active");
			   $(this).siblings("h3").show();
		});
		
		
		$("a.price").click(function(){
			$(this).animate({ backgroundColor: "#dafda5" }, "fast")
			.animate({ backgroundColor: "#ffffff" }, "slow")
			.removeClass("spam")
			return false;
		});
		
		
	});

/* Coda Slide */
	
		var theInt = null;
		var $crosslink, $navthumb;
		var curclicked = 0;
		
		theInterval = function(cur){
			clearInterval(theInt);
			
			if( typeof cur != 'undefined' )
				curclicked = cur;
			
			$crosslink.removeClass("active-thumb");
			$navthumb.eq(curclicked).parent().addClass("active-thumb");
				$(".stripNav ul li a").eq(curclicked).trigger('click');
			
			theInt = setInterval(function(){
				$crosslink.removeClass("active-thumb");
				$navthumb.eq(curclicked).parent().addClass("active-thumb");
				$(".stripNav ul li a").eq(curclicked).trigger('click');
				curclicked++;
				if( 2 == curclicked )
					curclicked = 0;
				
			}, 6000000);
		};
		
		$(function(){
			
			$("#main-photo-slider").codaSlider();
			
			$navthumb = $(".nav-thumb");
			$crosslink = $(".cross-link");
			
			$navthumb
			.click(function() {
				var $this = $(this);
				theInterval($this.parent().attr('href').slice(1) - 1);
				return false;
			});
			
			theInterval();
		});
	
	
/* splash script */
$(document).ready(function(){		
	$("#splash").click(function() {
    $(this).animate({opacity: "hide"}, "slow");
  });
$('#splash').delay(15000, function(){$('#splash').fadeOut()})

});

	
	
/* Dropdown menu script */

 $(document).ready(function()
    {
    $("ul.pane-list li.headlink").hoverIntent(function()
        {
        $(this).children("ul").css("display", "none");
        $(this).children("ul").slideDown("normal");
        },
     function()
     {
        $(this).children("ul").slideUp("fast");
     });
    })
    
    
/* Variation Price Query */
$(".varSel").live("change", function(){
	var formdata = $(this).parents('form').serialize();
	$this = $(this)
    $.ajax({
        type: "POST",
        url: "library/varPrice.php",
		beforeSend: function(html){
$this.parent().next("li.price").fadeOut();
      },
        data: formdata,
        success: function(html){
$this.parent().next("li.price").html(html).slideDown();
      }
    });
});





	
/* Tooltip hover */
$(document).ready(function(){

   $("#movers-row a").hoverIntent(
   function(over) {
     $(this).find("em.hover").animate({opacity: "show", top: "55"}, "slow");
   },
   function(out) {
     $(this).find("em.hover").animate({opacity: "hide", top: "55"}, "slow");
   });

}); 



