$(document).ready(function(){

  	// Vimeo video for multiple devices
	var agent = navigator.userAgent.toLowerCase();
	var embed = '';
	var device = '';
	if (agent.indexOf('iphone')!=-1 || agent.indexOf('ipod')!=-1) {
		device = "iphone";
	} else if (agent.indexOf('ipad')!=-1) {
		device = "ipad";
	} 

	// show signup landing page 
	var screen_width = screen.width;
	var screen_height = screen.height;
	if (screen_width <= 700 || screen_height <= 500) {
		// skip mobile browsers
	} else {
		/*var COOKIE_NAME = 'gf_20';
		var cookie_options = { path:'/', expires: 1 };
	    if (!$.cookie(COOKIE_NAME)) {
	    	$.cookie(COOKIE_NAME, 'landing_email', cookie_options);
	    	// Cookie just set. Now display landing page
	    	$('body').append(

				// fast for freedom splash:
				'<div id="landing_container">'+
	    		'	<div id="landing_content">'+
	    		'		<div id="landing_links">'+
	    		'			<p><a href="/participate/"><img src="/wp-content/themes/fs2010/media/images/landing_button_gf20.png" alt="Register Today" /></a></p>'+
	    		'			<p class="landing_close_text"><a class="landing_close">No thanks</a></p>'+
	    		'		</div>'+
	    		'		<a id="landing_close" class="landing_close"></a>'+
	    		'	</div>'+
	    		'</div>'
	    	);
	    	$("a.landing_close").click(function(){
	    		$("#landing_container").remove();
	    	});
	    } else {
	    	// Cookie already set, skip landing page
	    }*/
	}

	$(".vimeo_video a").click(function(){
		var vimeo_id = $(this).parent().attr("id").replace(/vimeo_/,'');
		var vimeo_height = $(this).height();
		var vimeo_width = $(this).width();
		if (device == "iphone") {
			// let href work
		} else if (device == "ipad") {
			embed = '<video src="http://www.vimeo.com/play_redirect?clip_id='+vimeo_id+'&quality=hd" controls="controls" width="'+vimeo_width+'" height="'+vimeo_height+'" autoplay="autoplay"></video>';
			$("#vimeo_"+vimeo_id).html(embed);
			return false;	
		} else {
			embed = '<object width="'+vimeo_width+'" height="'+vimeo_height+'"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id='+vimeo_id+'&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=ffffff&amp;fullscreen=1&amp;autoplay=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id='+vimeo_id+'&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=ffffff&amp;fullscreen=1&amp;autoplay=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="'+vimeo_width+'" height="'+vimeo_height+'"></embed></object>';
			$("#vimeo_"+vimeo_id).html(embed);
			return false;
		}
		
	});
	
	/* Suckerfish dropdown menus by Myles Angell http://be.twixt.us/jquery/suckerFish.php */
	$("#nav-one li").hover(
        function(){ $("ul", this).fadeIn("fast"); }, 
        function() { } 
    );
    if (document.all) {
        $("#nav-one li").hoverClass ("sfHover");
    }

	// Vertical Slides
	$("#vertical_slides a").hover(
		function() {
			$(this).parent().css("background-color","#dcf8ff"); //#fdfae1");
		},
		function() {
			$(this).parent().css("background-color","#fff");
		}
	);
	$("#vertical_slides a").click(function(){
		var open_width = 412;
		var closed_width = 70;
		var speed = 200
		var key = $(this).parent().attr("id").replace(/slider_/,'');
		if ($(this).parent().hasClass('open')) {
			// go to link
		} else {
			// run transitions
			$("#vertical_slides div").animate({
				width: closed_width
				}, speed
			);
			$("#vertical_slides div a").animate({
				opacity: '0'
				}, speed
			);
			$("#vertical_slides div").removeClass("open");
			$(this).parent().animate({
				width: open_width
				}, speed
			);
			$(this).animate({
				opacity: '1'
				}, speed
			);
			$(this).parent().addClass("open");
			return false;
		}
	});
	
	// Show/Hide Content
	$("#content a.show_hide_link").click(function(){
		var key = $(this).attr("id").replace(/fs_link_/,'');
		if ($(this).hasClass("show_hide_link_active")) {
			// just close box
			var keep_closed = true;
		}
		$(".show_hide_content").slideUp("fast");
		$(".show_hide_link").removeClass("show_hide_link_active");
		if (keep_closed != true) {
			$("#content #fs_content_"+key).slideDown("fast");
			$("#content #fs_link_"+key).addClass("show_hide_link_active");		
		}
	});


	// Audio player 
	$('#audio_player').each(function(){
			var flashvars = {
				//playlist_url: "/media/audio/playlist.xspf",
				autostart: "yes",
				loop: "yes",
				soundFile: "http://www.freedomsunday.org/wp-content/themes/fs2010/media/audio/kingdom.mp3",
				playerID: "audioplayer1",
				titles: "Kingdom",
				rightbg: "0xa1e5ff&",
				leftbg: "0xa1e5ff&",
				loader: "0x93bfcd&"
				/*
				bg=0xf8f8f8&
				lefticon=0x666666&
				rightbghover=0x999999&
				righticon=0x666666&
				righticonhover=0xffffff&
				text=0x666666&
				slider=0x666666&
				track=0xFFFFFF&
				border=0x666666&
				*/
			};
			var params = {
				menu: "false",
				wmode: "transparent"
			};
			var attributes = '';
			swfobject.embedSWF("/wp-content/themes/fs2010/media/audio-player/player.swf", "audio_player", "290", "24", "7.0.0", null, flashvars, params, attributes);
	});

	$("body.page-id-6 form p").each(function(){
		if ($(this).text() == 'This post is password protected. To view it please enter your password below:') {
			$(this).html('Register for Freedom Shabbat to receive the password - <a href="/participate/">register here</a>.');
		}
	});

	$("form#signup").validate({
		rules: {
			sv_org_name: "required", 
			sv_creative_access: "required",
			
			sv_address1: {
				required: "#creative_access_no:checked"
			},
			sv_city: {
				required: "#creative_access_no:checked"
			},
			sv_state: {
				required: "#creative_access_no:checked"
			},
			sv_zip: {
				required: "#creative_access_no:checked"
			},
			sv_country: {
				required: "#creative_access_no:checked"
			},
			sv_phone: {
				required: "#creative_access_no:checked"
			},
			sv_email: {
				required: true,
				email: true
			}
		},
		messages: {
			comment: "Please enter a comment."
		}
	});

	$('input[name="sv_creative_access"]').change(function(){
		var radio_value = $('input[name="sv_creative_access"]:checked').val();
		if (radio_value == 1) {
			$('div.contact-info').slideUp("fast");
		} else {
			$('div.contact-info').slideDown("fast");
		}
	});

});


/* Suckerfish dropdown menus by Myles Angell http://be.twixt.us/jquery/suckerFish.php */
$.fn.hoverClass = function(c) {
    return this.each(function(){
        $(this).hover( 
            function() { $(this).addClass(c);  },
            function() { $(this).removeClass(c); }
        );
    });
};    
