var homepage_banner_object;

(function ($) {$(document).ready(function() {

	//main navigation decoration
	$("ul.sf-menu").superfish({hoverClass:'sf-menu-hover',pathClass:'sf-menu-path',pathLevels:1,autoArrows:false});
	// $(".action-nav li:last").addClass("action-nav-last");
	$("#page-nav a:first").addClass("page-nav-first");
	
	//state select box
	var state_styles = {
		comboboxContainerClass: "state-select-container",
		comboboxValueContainerClass: "state-select-value-container",
		comboboxValueContentClass: "state-select-value-content",
		comboboxDropDownClass: "state-select-dropdown",
		comboboxDropDownButtonClass: "state-select-dropdown-button",
		comboboxDropDownItemClass: "state-select-item",
		comboboxDropDownItemHoverClass: "state-select-item-hover",
		comboboxDropDownGroupItemHeaderClass: "state-select-item-header",
		comboboxDropDownGroupItemContainerClass: "state-select-item-group-container",
		animationType: "",
		width: ""
	};
	$("#state_select").combobox(state_styles);
	$("#state_select").combobox.onChange = changeLocation;

	//text input default value switcher
	$("input[type='text']").focus ( function() { if ( this.value == this.defaultValue ) { this.value = ""; }; } );
	$("input[type='text']").blur ( function() { if ( $.trim ( this.value ) == "" ) { this.value = ( this.defaultValue ? this.defaultValue : "" ); }; } );

	//homepage flash
	var flashvars = {
		path: "wp-content/themes/repower/flash/data/RepowerHomepageBanner"+retrieveGeoIPLocationCode()+".xml"
	};

	var params = {
	wmode: "transparent"
	};

	var attributes = {
	};

	if($('#flash-holder').length) {
		var playerVersion = swfobject.getFlashPlayerVersion();
		if (playerVersion.major >= 9) {
			swfobject.embedSWF("wp-content/themes/repower/flash/RepowerHomepageBanner.swf", "flash-holder", "2000", "389", "9.0.28", "wp-content/themes/repower/js/expressInstall.swf", flashvars, params, attributes);
		}
		else {
			$('.flash-holder').css("visibility", "visible");
		}
	}
	
	homepage_banner_object = document.getElementById("flash-holder");

});
		   })(jQuery);

function reloadFlashXML(xmlPath) {
	homepage_banner_object.loadXMLIntoFlash(xmlPath);
}

function retrieveGeoIPLocationCode() {
	var location_cookie = jQuery.cookie('location');
	if (location_cookie != '' && location_cookie != null) {
		var loc_array = location_cookie.split('&');
		var loc = loc_array[3].split("=")[1];
		if (loc != '')
			loc = "_"+loc;
		return loc;
	}
	return '';
}

function changeLocation() {
	var choice = jQuery('#state_select option:selected').eq(0);
	var code = choice.val();
	var state = (code == '' ? '' : choice.text());
	jQuery.cookie('location', 'country=United+States&countrycode=US&region='+state.replace(' ','+')+'&regioncode='+code, {expires: 7, path: '/'});
	var link = jQuery('#state-select-link').eq(0).attr('href');
	location.href = link.replace('{STATE}', state.toLowerCase().replace(' ', '_'));
}

function validate_action_join(id) {
	
	var element = jQuery("#"+id);
	var filter = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
	if ( !filter.test ( element.val() ) )
	{
		element.addClass ( "text-error" );
		return false;
	}
	else
	{
		element.removeClass ( "text-error" );
		return true;
	}
}


