// Global vars

$(document).ready(function(){
	
	loadCountdown();

	/////////////////////////////////////////////////////////////////
	// Initialize jScrollPane
	$('#pane').jScrollPane();

	/////////////////////////////////////////////////////////////////
	// FAQ sliders
	$(".faq_a").hide();
	$('#pane').jScrollPane();
	$(".faq_a[alt=1]").slideDown();
	$(".faq_item[alt=1]").addClass("faq_open");

	$('.faq_q').click(function(){

		var q_alt = $(this).attr("alt");

		if ( $(".faq_item[alt="+q_alt+"]").hasClass("faq_open") ){
			$(".faq_item[alt="+q_alt+"]").removeClass("faq_open");
			$(".faq_a[alt="+q_alt+"]").slideUp();
		} else {
			$(".faq_item").removeClass("faq_open");		
			$(".faq_a").slideUp();
			$(".faq_item[alt="+q_alt+"]").addClass("faq_open");
			$(".faq_a[alt="+q_alt+"]").slideDown();
		}
	});

	/////////////////////////////////////////////////////////////////
	// Tacori case preview
	/*$("#tacori_case_link").click(function(){		
		$("#tacori_case_img").show(400);
	});

	$(".close_tacori_case").live('click', function(){
		$("#tacori_case_img").fadeOut(400);
	});
	*/
	/////////////////////////////////////////////////////////////////
	// Sharebox open
	$('#s3 a').click(function(){
		$('#close_signup').click();
		$("#sharebox").fadeIn(500);
	});

	// Sharebox close
	$('.close_share').click(function(){
		$("#sharebox").fadeOut(500);
	});

	// Sharebox email
	$("form#sendform").submit(function(){

		 $.post($(this).attr("action"),{
			   fromemail: $("#fromemail").val(),
			   toemail: $("#toemail").val(),
			   message: $("#message").val()
			 }, function(xml) {
					messageSent(xml); });
		 return false;
	});

	/////////////////////////////////////////////////////////////////
	// Sign up open
	$('#s4 a').click(function(){
		$('.close_share').click();
		$("#signupbox").fadeIn(500);
	});

	// Sign up close
	$('#close_signup').click(function(){
		$("#signupbox").fadeOut(500);
		$("#w_shopwstyle_entries").clearForm();
		$("#signup_thankyou").html("");
	});

	/////////////////////////////////////////////////////////////////
	// Sign up submit

	$('#w_shopwstyle_entries').validate(profileValNewsletter);

}); // End (document).ready

/////////////////////////////////////////////////////////////////

function loadCountdown(){

	var params = {	menu: "false",
					bgcolor: "#1D1D1C",
					allowFullScreen: "false"
				 };

	var flashvars = {
					};			
	
	 swfobject.embedSWF("flash/w_countdown.swf", "countdown_flash", "610", "32", "9.0.0", "expressInstall.swf", flashvars, params);
}

/////////////////////////////////////////////////////////////////

(function($) {
	$.fn.customFadeIn = function(speed, callback) {
		$(this).fadeIn(speed, function() {
			if(jQuery.browser.msie)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
	$.fn.customFadeOut = function(speed, callback) {
		$(this).fadeOut(speed, function() {
			if(jQuery.browser.msie)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
})(jQuery);

/////////////////////////////////////////////////////////////////

function loadMap(){

	var params = {	menu: "false",
					wmode: "transparent",
					bgcolor: "#1D1D1C",
					allowFullScreen: "false"
				 };

	var flashvars = {
					};			
	
	 swfobject.embedSWF("MapLauncher.swf", "w_flash_map", "635", "408", "9.0.0", "expressInstall.swf", flashvars, params);
}

/////////////////////////////////////////////////////////////////
// Send Sharebox email

function messageSent(str) {
	$("#theform").hide();
	$("#fromemail").val("");
	$("#toemail").val("");
	$("#message").val("");
	$("#sendresult").show();
}

function showForm(str) {
	$("#theform").show();
	$("#sendresult").hide();
}

/////////////////////////////////////////////////////////////////

// Sign Up

function thankYouSignup(response){
	
	if ( response == "Thank you for entering!" ){

		$("#signup_thankyou").html(response);
		
	} else if ( response == "Sorry, only one entry per person is allowed." ){

		alert(response);
	}
}

	//Make your validation rules into an object:
	profileValNewsletter = {};
	
	//The rules to validate against
	profileValNewsletter.rules = {
		email : {
			required: true,
			email: true
		}
	};	
	
	//Optional - if you want a custom message
	profileValNewsletter.messages = {
		email: {
			required: "Please enter your email address",
			email: "Please enter a valid email address"
		}
	};	
	
	//Optional - if you want the error message to appear in a separate div
	profileValNewsletter.errorLabelContainer = '#errorbox_signup';
	profileValNewsletter.wrapper= 'div';

	profileValNewsletter.submitHandler = 
		function(form) {
			jQuery(form).ajaxSubmit({
			success: function(data) {

				thankYouSignup(data);
			}
		});
	};