$(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(); },function() {$('ul:first', this).hide();});
	//add class for flyouts
	if ($('#nav ul ul ul').length > 0) { $('#nav ul ul ul ').parent().addClass('flyout'); }
	$('#nav-mid li:last').addClass('last');
	/* NAVIGATION end ****************************************************************/
	
	/* SIFR***************************************************************************/
	$('h1.title').flash(
		{ src: '/includes/media/font-helveticaNeue-lt-45-light.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:img click replace****************************************************/	
	$('.prod-sub-img').click(function() {	$('.prod-image').html($(this).html());	 return false	});
	$('#details div.prod-image .thumb').click(function() {	$('#main-image').html($(this).html());	 return false	});
	
	$('#content .commerce > div').addClass('cms').parent().prepend('<span style="font-size:0;">&nbsp;</span>'); //fix for commerce ...good ol jquery
	/*COMMERCE:img click replace****************************************************/
	
	$('#main .right').css('height',$('#main').height());
	
	/* START Catalog Resource Page */
	$('#page-catalogs .download-category ul').hide();
	$('#page-catalogs .download-category .handle').click(function(){
		var dropdown_shell = $($(this).attr('rel'));
		var dropdown_handle = $(this);
		var dropdown = $($(this).attr('rel')+' ul');
		
		if(dropdown_handle.hasClass('active')){
			dropdown_handle.removeClass('active');
			dropdown.hide();
		}else{
			dropdown_handle.addClass('active');
			dropdown.show().css({ 'visibility':'visible'});
			dropdown_shell.bind("mouseleave",function(){ 
			   dropdown.hide();
			   dropdown_handle.removeClass('active');
			})
		}
	});
	/* END Catalog Resource Page */

	/* CAROUSEL ITEMS */
	 if($("#ad-rotator .carousel .display").length >0){
    	$("#ad-rotator .carousel .display").jCarouselLite({ btnNext: ".down", btnPrev: ".up", vertical:true,auto:true,mouseWheel: true,speed: 2500,circular: true,visible: 3,scroll: 1,
			afterStart: function() {
				if ( $('#ad-rotator .carousel .display li.active').length == 0 ){
					$active = $('#ad-rotator .carousel .display li:first').addClass('active');
				}else{
					$current = $('#ad-rotator .carousel .display li.active').removeClass('active');
					$active = $current.next().addClass('active');
				}
				$('#ad-rotator .ad div.active').removeClass('active');
				$display = $($active.children('a').attr('href'));
				$display.addClass('active');
					/*
					.animate({opacity: 1.0}, 1, function() {
					$('#ad-rotator .ad div').removeClass('last-active');
				});*/
			}
		});
	 }
	$('#ad-rotator .carousel .display a').click(function(){
		$('#ad-rotator .carousel .display li').removeClass('active');
		$('#ad-rotator .ad div.active').addClass('last-active').removeClass('active');
		
		$display = $($(this).attr('href'));
		$display.css({opacity: 1.0})
			.addClass('active')
			.animate({opacity: 1.0}, 400, function() {
			$('#ad-rotator .ad div').removeClass('last-active');
		});
		$(this).parent().addClass('active');
		return false;
	});
	/* CAROUSEL ITEMS */
	
	if($('#testing').length > 0){
		//alert('');
			$('#ad-rotator .carousel .displayed').jcarousel({
				//itemLoadCallback: itemLoadCallbackFunction
				vertical:true,
				wrap:'circular',
				auto:1,
				scroll:1
			});
	}
	
	
	
	
}); //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 *************************************************/