$(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 li.menu-cat:last').addClass('last');
	/* NAVIGATION end ****************************************************************/
	
	/* SIFR***************************************************************************/
	sifr('.font-01','font-helveticaNeue-lt-45-light');
	/* SIFR**************************************************************************/
	
    /* SLIDESHOW start **************************************************************/
	var slideshow_init = setInterval( "slideSwitch()", 5000 );
	$('#slideshow a').click(function(){
    clearInterval(slideshow_init);
    $('#slideshow .display p').removeClass('active');
    $('#slideshow .display #'+$(this).attr('rel')).addClass('active');
	});
	/* SLIDESHOW end ****************************************************************/
    
	/*NOW SHOWING start *************************************************************/
	$('#internal #now-showing ul').hide();
	$('#internal #now-showing > h1').click(function() {
		if($(this).next('ul').is(':visible')){ $(this).css('background-position','left top'); }
		else{ $(this).css('background-position','left bottom'); }
		
		$(this).next('ul').slideToggle('fast')
			   .siblings('ul:visible').slideUp('fast')
			   .prev('h1').css('background-position','left top');
		
		return false
	});
	/*NOW SHOWING start *************************************************************/
	
	/* BECOME a CLIENT start ************************************************************/
	$('#business-info input.text').blur(function(){ checkBusinessPercentage(this); })	
	/* BECOME a CLIENT end **************************************************************/
	
	/*PRODUCT LISTING*/
	//$('.grid_cell a').hover(function(){ $(this).parent().css('background','#e7d6cf'); },function(){ $(this).parent().css('background','#fff'); });	
	/*PRODUCT LISTING*/
		
}); //close document.ready

/* SIFR function start **************************************************************/
function sifr(x,font){
$(x).flash(
	{ src: '/includes/media/'+font+'.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));						
		}
	).css('visibility','visible');
}
/* SIFR function end ****************************************************************/

/* 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 p.active');

	if ( $active.length == 0 ) $active = $('#slideshow p:last');

	var $next =  $active.next('p').length ? $active.next()
			: $('#slideshow p:first');

	$active.addClass('last-active');
	
	$next.css({opacity: 0.0})
			.addClass('active')
			.animate({opacity: 1.0}, 500, function() {
			 $active.removeClass('active last-active');
	});
}

function slideSwitchUl() {
	var $active = $('#slideshow ul.active');

	if ( $active.length == 0 ) $active = $('#slideshow ul:last');

	var $next =  $active.next('ul').length ? $active.next()
			: $('#slideshow ul:first');

	$active.addClass('last-active');	
	$active.removeClass('active last-active');
	$active.css({opacity:0.0});
	
	$next.css({opacity:1.0})
			.addClass('active')
			.siblings('ul:visible').css({opacity:0.0});
}
/* SLIDESHOW function end ***********************************************************/

/* BECOME a CLIENT start ************************************************************/
function checkBusinessPercentage(element){
	total = parseInt($('#Type1_volume').val())+
			parseInt($('#Type2_volume').val())+
			parseInt($('#Type3_volume').val())+
			parseInt($('#Type4_volume').val())+
			parseInt($('#Type5_volume').val())+
			parseInt($('#Type6_volume').val());
	if(total >100){
		alert('The percentage breakdown of sales volume for the business must not exceed 100%.');
		element.focus();
	}
}
/* BECOME a CLIENT end ***************************************************************/