$(document).ready(function(){
	
	/* PNGFIX start *******************************************************************/
		$(document).pngFix();
	/* PNGFIX end *********************************************************************/
	
	/* EXTERNAL LINKS start ***********************************************************/
	$('a[@rel$="external"]').click(function(){
		this.target = "_blank";
	});	
	/* EXTERNAL LINKS end *************************************************************/

	/* NAVIGATION start ***************************************************************/
	$('#nav ul ul').hide();
	//hover show next level
	$('#nav ul > li').hover(function() { 
		$('ul:first', this).show();
		
		if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){
		var ieversion=new Number(RegExp.$1)
		}
		if(ieversion !=6){
		$('ul:first li:first',this).css('background','url(/includes/images/bg-dropdown-li.png) no-repeat left top').css('padding-top','10px');
		}
	 },function() {$('ul:first', this).hide();});
	
	//add class for flyouts
	if ($('#nav ul ul ul').length > 0) { $('#nav ul ul ul ').parent().addClass('flyout'); }
	
	//nav-categories
	$('#nav-categories ul li:last').addClass('last');
	/* NAVIGATION end ****************************************************************/
	
	/*CONTENT IMAGES*/
	$('#home #content p:last').addClass('last');
	/*CONTENT IMAGES*/
	
	/* SIFR***************************************************************************/
	$('h1.title').flash(
		{ src: '/includes/media/font-tw-cen-mt.swf' },
		 { version: 8 },
			function(htmlOptions) {
				htmlOptions.flashvars.css = '*%20%7B%20color%3A%23'+RGBstring($(this).css('color'))+'%7D';
				htmlOptions.flashvars.txt = this.innerHTML;
				this.innerHTML = '<div>'+this.innerHTML+'</div>';
				var $alt = $(this.firstChild);
				htmlOptions.width = $(this).width(); //$alt.width()
				htmlOptions.height = $(this).height(); //$alt.height()
				$alt.addClass('sifr-alt');
				$(this).addClass('sifr-text-alt').prepend($.fn.flash.transform(htmlOptions));	
			}
		);
	/* SIFR**************************************************************************/

	/* COMMERCE:dropdown click replace****************************************************/
	$("#switch-item").change(function () {
						var price = "";
						var image = "";
						$("#switch-item option:selected").each(function () {
									price += "Regular: " + price_array[$(this).val()]; //grab price array item
									//if there is a sale...
									if (sale_price_array[$(this).val()] && sale_price_array[$(this).val()] != price_array[$(this).val()]) price += " Sale: " + sale_price_array[$(this).val()] + " ";
									image += image_array[$(this).val()] + " "; //grab image array item
									image = image.replace(/ /g,''); //replace image whitespace
								});
						$(".prod-price").text(price);
						$("div.prod-image a").attr('href',image);
						$("div.prod-image img").attr('src',image);
					})
					.change();
	/*COMMERCE:dropdown click replace****************************************************/
	
	$('#header').hover(function(){	clearInterval(intervalid);	},
																				function(){	intervalid = setInterval( "headerBackground()", 6000 ); 	});
	
	/* SLIDESHOW start **************************************************************/
		var intervalid = setInterval( "headerBackground()", 6000 ); 
	/* SLIDESHOW end ****************************************************************/
		

			/*CAROUSEL******************************************************************/
	    jQuery('#mycarousel').jcarousel({
        wrap: 'circular',
        itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback},
        itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback}
    });
			/*CAROUSEL******************************************************************/

}); //close document.ready

/* sIFR RGB conversion function start **********************************************/
function RGBstring(str) {
	str1 = str.replace("#","");
	str2 = str1.replace("rgb(","");
	str2 = str2.replace(")","");
	str2 = str2.split(",");
	if(navigator.appName == "Microsoft Internet Explorer"){ return str1; }
	else { return toHex(str2[0])+toHex(str2[1])+toHex(str2[2]); }
}
function toHex(N) {
 if (N==null) return "01";
 N=parseInt(N); if (N==0 || isNaN(N)) return "00";
 N=Math.max(0,N); N=Math.min(N,255); N=Math.round(N);
 return "0123456789ABCDEF".charAt((N-N%16)/16)
      + "0123456789ABCDEF".charAt(N%16);
}
/* sIFR RGB conversion function end *************************************************/

/* HEADER SLIDESHOW function start *********************************************************/
function headerBackground() {		
	var $active = $('#slideshow a.active');
	if ( $active.length == 0 ) $active = $('#slideshow a:last');

	var $next =  $active.next().length ? $active.next(): $('#slideshow a:first');

	$active.addClass('last-active');

	$next.css({opacity: 0.0})
			.addClass('active')
			.animate({opacity: 1.0}, 1000, function() {
			 $active.removeClass('active last-active');
	});	
}
/* HEADER SLIDESHOW function end ***********************************************************/	