$(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";
	} 

	$(".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","#fdfae1");
		},
		function() {
			$(this).parent().css("background-color","#fff");
		}
	);
	$("#vertical_slides a").click(function(){
		var open_width = 412;
		var closed_width = 97;
		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);
	});

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


});


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