var template_url = '/wp-content/themes/fs2010';

$(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 || window.location.pathname == '/broadcast' || window.location.pathname == '/broadcast/') {
		// skip mobile browsers
	} else {

		var current_date_time = new Date();
		//var free2rock_cookie_start_date = new Date("January 23, 2012 06:00:00");
		//$('body').append('<!-- today = '+current_date_time+' || target = '+free2rock_cookie_start_date+' -->');
		//if (current_date_time >= free2rock_cookie_start_date) {
			var COOKIE_NAME = 'fs_wilberforce';
		//} 
		var cookie_options = { path:'/', expires: 4 };
	    if (COOKIE_NAME) {
		    if (!$.cookie(COOKIE_NAME)) {
		    	$.cookie(COOKIE_NAME, 'landing_splash', cookie_options);
		    	// Cookie just set. Now display landing page
			    if (COOKIE_NAME == 'fs_wilberforce') {
			    	// year end splash:
			    	var splash_content ='<div id="landing_container" style="position:fixed;width:100%;height:100%;background:transparent url('+template_url+'/media/images/white_90.png) top left repeat;top:0;left:0;z-index:1000;">'+
							    		'	<div id="landing_content" style="background-image:url('+template_url+'/media/images/landing-wilberforce-bg.jpg);background-color:#fff;background-position:top left;background-repeat:no-repeat;height:500px;width:788px;margin:20px auto;border:1px solid #fff;box-shadow:0 2px 10px rgba(0,0,0,0.2);-moz-box-shadow:0 2px 10px rgba(0,0,0,0.2);-webkit-box-shadow:0 2px 10px rgba(0,0,0,0.2);position:relative;">'+
							    		'		<div id="landing_links" style="padding:0 0 0 1px;text-align:center;">'+
							    		'		<form name="signup-ss" method="post" action="/signup-ss/" style="display:block;position:absolute;width:367px;top:300px;left:395px;padding:0;font-size:1.4em;">'+
							    		'			<p>Email: <input type="text" name="email" method="get" /><input type="hidden" name="from-lightbox" value="1" /> <input type="submit" value="Submit"/></p>'+
							    		'		</form>'+
							    		//'			<a href="/signup-ss/" target="_blank" id="landing_store_button" style="display:block;position:absolute;top:429px;left:26px;width:339px;height:41px;"><img src="'+template_url+'/media/images/landing-f2r-tan-button.png" alt="Shop Now!" width="339" height="41" /></a>'+
							    		'			<p class="landing_close_text" style="position:absolute;width:367px;top:458px;left:395px;text-align:center;margin:0;font-size:1.2em;"><a class="landing_close" style="cursor:pointer;color:#c51230;padding:0">Skip and go to site</a></p>'+
							    		'		</div>'+
							    		'		<a id="landing_close" class="landing_close" style="cursor:pointer;font-size:1em;position:absolute;display:block;height:39px;width:39px;top:-14px;right:-14px;background:url('+template_url+'/media/images/landing_close.png) top left no-repeat;"></a>'+
							    		'	</div>'+
							    		'</div>';
			    } 
			    //if(!$('body').hasClass("postid-1411") && !$('body').hasClass("term-free2rock")) {
				    $('body').append(splash_content);
			    	$("#landing_links a img").hover(
			    		function(){
			    			$(this).animate({
								opacity: 0,
								}, 400, function() {
									// Animation complete.
								});
			    		},
			    		function(){
			    			$(this).animate({
								opacity: 1,
								}, 400, function() {
									// Animation complete.
								});
			    		}
			    	);
			    	$("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 Sunday to receive the password - <a href="/participate/">register here</a>.');
		}
	});

	$("form#signup").validate({
		rules: {
			sv_sv_contact_firstname: "required", 
			sv_sv_contact_lastname: "required", 
			sv_creative_access: "required",
			
			sv_org_name: { 
				required: "#creative_access_no:checked"
			}, 
			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 || radio_value==2) {
			$('div.contact-info').slideUp("fast");
			$('#org_name_label .required').hide();
		} else {
			$('div.contact-info').slideDown("fast");
			$('#org_name_label .required').show();
		}
	});


});


/* 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); }
        );
    });
};    
