$(document).ready(function(){
						   
	jQuery.fn.exists = function(){return jQuery(this).length>0;}

	
	if ($('.scroll-images').exists()) {
		$('.scroll-images').cycle({
			cleartype:1,
			timeout:4000,
			prev: '.slider-prev',
			next: '.slider-next',
			pager: '#slider-nav',
			pagerEvent: 'mouseover',
			pauseOnPagerHover: true
		});
	}	

	$('#shw-date').datepicker({
		inline: true
	});
	
	$('#shw-date-picker').click(function(event){
		$('#shw-date').focus();
	});
	
	if ($('#range-slider').exists()) {

		$('#range-slider').jcarousel({
			wrap: 'circular',
			scroll:1,
			visible:3,
			auto: 4,
			itemFirstInCallback:  mycarousel_itemFirstInCallback		
		});
	} 
	/*carousel functions */
	/**
	 * This is the callback function which receives notification
	 * when an item becomes the first one in the visible range.
	 */
	function mycarousel_itemFirstInCallback(carousel, item, idx, state) {
		var currImage = idx+1;
		var currItem = '.jcarousel-item-' + currImage;
		var imgUrl = $(currItem).find('.range-main-image img').attr("src");
		$("#range-image-description").html($(currItem + " .range-description").html());
		$('.range-image').css('background-image', 'url(' + imgUrl + ')');
	};
	/*end of carousel functions */
	
	
	if($('a.gallery-image').exists())
	{
		$("a.gallery-image").colorbox();
	}

/*
	$('ul.sf-menu').superfish({
            delay:       1000,                            // one second delay on mouseout 
            animation:   {opacity:'show',height:'show'},  // fade-in and slide-down animation 
            speed:       'fast',                          // faster animation speed 
            autoArrows:  false,                           // disable generation of arrow mark-up 
            dropShadows: false,
			hoverClass:  'sfHover'	
	})
*/
	if($('.swatch-link').exists())
	{
		$('.swatch-link').hover(handlerIn, handlerOut)
	}
	
	function handlerIn(){
		var id = $(this).attr("id").substr(13);
		$('#swatch-image-lrg-' + id).show();
	}
	function  handlerOut(){
		var id = $(this).attr("id").substr(13);
		$('#swatch-image-lrg-' + id).hide();
	}
	
	$('.thumb-link').click(function() {
		var id = $(this).attr("id").substr(12);
		$('#large-images-wrapper').children('div').hide();
		$('#image-' + id).show();
	});
	
	if($('#trade-assets .tablesorter').exists())
	{
	    $("#trade-assets .tablesorter") 
			.tablesorter({widthFixed: true, widgets: ['zebra']}) 
			.tablesorterPager({container: $("#pager"),size: 10,positionFixed: false})
	}
	
}); 
