$(document).ready(function(){
	
	/* PNGFIX start *******************************************************************/
	$(document).pngFix();
	/* PNGFIX end *********************************************************************/
	
	/* EXTERNAL LINKS start ***********************************************************/
	$('a[@rel$="external"]').click(function(){
		this.target = "_blank";
	});	
	/* EXTERNAL LINKS end *************************************************************/
	
	/*MEMBER LOGIN*/
	$('#member-login #member-username').focus(function(){	if(this.value=='Enter Username') {	$(this).val('');} });
	$('#member-login #member-username').blur(function(){ if(this.value =='') {	$(this).val('Enter Username');}	});
	$('#member-login #member-password').focus(function(){	if(this.value=='Enter Password') {	$(this).val('');} });
	$('#member-login #member-password').blur(function(){ if(this.value =='') {	$(this).val('Enter Password');}	});
	/*MEMBER LOGIN*/

	/* NAVIGATION start ***************************************************************/	
	$('#nav li:last').addClass('last');
	/* NAVIGATION end ****************************************************************/
	
	/* SIFR***************************************************************************/
	sifr('.font-01','font-palatino-linotype');
	sifr('.font-02','font-tw-cen-mt');
	/* SIFR**************************************************************************/
	
	/* SLIDESHOW start **************************************************************/
	setInterval( "slideSwitch()", 5000 );
	setInterval( "slideSwitchUl()", 5000 );
	$('#slideshow ul').css({opacity: 0.0})
	$('#slideshow ul:first').css({opacity: 1.0})
	$('#slideshow ul li:first-child').addClass('first');
	/* 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 *************************************************************/
	
	/*FORMS*/
	if(typeof toggleShowForm =='function'){ toggleShowForm(); }
	/*FORMS*/
		
}); //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));						
		}
	);
}
/* 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 img.active');

	if ( $active.length == 0 ) $active = $('#slideshow img:last');

	var $next =  $active.next('img').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');
	});
}
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 ***********************************************************/

function validateForm(required_fields_list){
	var errors_alert = "";
	var cssError = { border: "1px solid red", padding: "5px 0 2px 0", backgroundColor:"#fff3f3" };
	var cssOK = { border: "0px", padding: "0px", background:"none" };
	
	var required_fields_array = required_fields_list.split( "," );
				
	for( var i=0; i < required_fields_array.length; i++ ){ 
		if( $('#'+required_fields_array[i] ).val().length == 0 ){
			errors_alert += required_fields_array[i] + " is required.\n";
			$( "#label_"+required_fields_array[i] + " .error").animate( { left: "+=20px"},1 ).animate({opacity:".5",left: "-=20px"},250).animate({opacity:"1",left: "+=6px"},250).animate({left: "-=6px"},300);
			$( "#label_"+required_fields_array[i] ).css(cssError);
		} else {
			$( "#label_"+required_fields_array[i] ).css(cssOK);
			$( "#label_"+required_fields_array[i] + " .error").css("opacity","0");
		} 
	}
	
	/*
	//email validations
	var RegExp_email = new RegExp( /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9])+(\.[a-zA-Z0-9_-]+)+$/ );

	var email_fields_list = "affil_email";
	var email_fields_array = email_fields_list.split( "," );

	for( var i=0; i < email_fields_array.length; i++){
		if( !RegExp_email.test( $('##'+email_fields_array[i] ).val() ) ){
			$( "##label_"+email_fields_array[i]+" .error").animate( {opacity:"1", left: "+=10px"},200 ).animate({left: "-=10px"},200).animate({left: "+=10px"},200).animate({left: "-=10px"},200);
			$( "##label_"+email_fields_array[i] ).css(cssError);
		} else{
			$( "##label_"+email_fields_array[i] ).css(cssOK);
			$( "##label_"+email_fields_array[i] + " .error").css("opacity","0");
		}
	}
	*/
	
	if( errors_alert.length == 0 ){
		return true;
	} else {
		alert("There is a problem with your submission: \n\n" + errors_alert);
		return false;
	}
}