$(document).ready(function(){
	
	/* PNGFIX start *******************************************************************/
		$(document).pngFix();
	/* PNGFIX end *********************************************************************/
	
	/*SEARCH*/
	$('#search input.text').focus(function(){	if(this.value=='Search') {	$(this).val('');} });
	$('#search input.text').blur(function(){ if(this.value =='') {	$(this).val('Search');}	});
	/*SEARCH*/
	
	/* EXTERNAL LINKS start ***********************************************************/
	$('a[@rel$="external"]').click(function(){
		this.target = "_blank";
	});	
	/* EXTERNAL LINKS end *************************************************************/
	
	/* NAVIGATION start ***************************************************************/
	$('#nav ul ul').prepend('<li class="top"></li>');
	$('#nav ul ul').append('<li class="bottom"></li>');
	$('#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 li.menu-cat:last').addClass('last');
	/* NAVIGATION end ****************************************************************/
	
	/* SIFR***************************************************************************/
	$('.font-franklin-gothic').flash(
		{ src: '/includes/media/font-franklin-gothic-itc-bk-bt.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**************************************************************************/
	
	/* SLIDESHOW start **************************************************************/
	setInterval( "slideSwitch()", 5000 );
	/* SLIDESHOW end ****************************************************************/	
		
}); //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 *************************************************/

/* SLIDESHOW function start *********************************************************/
function slideSwitch() {
	var $active = $('#slideshow img.active');

	if ( $active.length == 0 ) $active = $('#slideshow img:last');

	var $next =  $active.next().length ? $active.next()
			: $('#slideshow img:first');

	$active.addClass('last-active');
	
	$next.css({opacity: 0.0})
			.addClass('active')
			.animate({opacity: 1.0}, 500, function() {
			 $active.removeClass('active last-active');
	});
	
}
/* SLIDESHOW function end ***********************************************************/	