var RecaptchaOptions = {theme: 'custom'}

$(document).ready(function() {
	
function preload() {
growHover = new Image();
growHover.src = '/img/global_growit_rollover_01.png';
cookHover = new Image();
cookHover.src = '/img/global_cookit_rollover_01.png';
filmHover = new Image();
filmHover.src = '/img/global_filmit_rollover_01.png';
askHover = new Image();
askHover.src = '/img/global_askit_rollover_01.png';
busHover = new Image();
busHover.src = '/img/cookingbus_hilite.gif';
filmHover = new Image();
filmHover.src = '/img/filmit_login_hilite.gif';

logoHover = new Image();
logoHover.src = '/img/home_icon_hilite.gif';

homeH1Hover = new Image();
homeH1Hover.src = '/img/home/cooking_bus_heading_hilite.png';
homeH2Hover = new Image();
homeH2Hover.src = '/img/home/cooking_bus_heading_hilite.png';
homeH3Hover = new Image();
homeH3Hover.src = '/img/home/cooking_bus_heading_hilite.png';

sloganHover = new Image();
sloganHover.src = '/img/global_header_text_hilite.png';

pFrame = new Image();
pFrame.src = '/img/people-partners/people/pic_frame.gif';

acHover = new Image();
acHover.src = '/img/comments/add_comment_top_strip_hilite.png';

vcHover = new Image();
vcHover.src = '/img/comments/comments_top_strip_hilite.png';

ebHover = new Image();
ebHover.src = '/img/comments/expand_button_hilite.gif';

cbHover = new Image();
cbHover.src = '/img/comments/close_button_hilite.gif';

crHover = new Image();
crHover.src = '/img/comments/reply_button_hilite.png';

}

preload();

var url = window.location.href;

if ($("#block-menu-primary-links .open_futures_people ul li a").hasClass("active")) {
var active = $("#block-menu-primary-links .open_futures_people ul li a.active").text();
$("#right a:contains('" + active + "')").addClass("active");
}

if ($("#block-menu-primary-links .filmit ul li a").hasClass("active")) {
$("#block-menu-primary-links .filmit a").addClass("active");
}

$("#header #secondary li.first a").attr("href", "/");

$("#header #secondary li + li:not(.last)").prepend("<span>&#149;</span>");

if ($(".content .schools").is(":visible")){
	$("#secondary li:eq(3) a").addClass("active");
}

if ($(".content .cs").is(":visible")){
	$("#block-menu-primary-links .case_studies a").addClass("active");

var activeCS = $(".cs-org-name-short").html();

}

$("#secondary li a:contains('Become an Open Futures school')").html("Become an <i>Open Futures</i> school");

$("#block-menu-primary-links .about_open_futures > a").html("About <i>Open Futures</i>");
$("#block-menu-primary-links .about_open_futures .open_futures_schools > a").html("<i>Open Futures</i> schools");
$("#block-menu-primary-links .about_open_futures .the_open_futures_trust > a").html("<i>The Open Futures Trust</i>");
$("#block-menu-primary-links .people_and_partners .open_futures_people > a").html("<i>Open Futures</i> People");

$("#block-menu-primary-links .our_curriculum .askit > a").html("<i>askit</i>");
$("#block-menu-primary-links .our_curriculum .cookit > a").html("<i>cookit</i>");
$("#block-menu-primary-links .our_curriculum .filmit > a").html("<i>filmit</i>");
$("#block-menu-primary-links .our_curriculum .growit > a").html("<i>growit</i>");

$('.heading h2').ttfgen();
$('.heading h1').ttfgen();

if ($(".view-cs-teaser-list").is(":visible")){
	$(".view-cs-teaser-list .field-content").each(function(){
		$(this).find("p:last").append("&nbsp;");
	});
	$(".view-cs-teaser-list .views-field-view-node a").each(function(){
		$(this).closest(".views-row").find(".field-content p:last").append(this);
	});
}

if ($("#content .home").is(":visible")){
	$("#area-cookit").hover(function(){
		$("#map-cookit-hilite").show();
	},function(){
		$("#map-cookit-hilite").hide();		
	});
	$("#area-growit").hover(function(){
		$("#map-growit-hilite").show();
	},function(){
		$("#map-growit-hilite").hide();		
	});
	$("#area-filmit-login").hover(function(){
		$("#map-filmit-login-hilite").show();
	},function(){
		$("#map-filmit-login-hilite").hide();		
	});
	$("#area-people").hover(function(){
		$("#map-people-hilite").show();
	},function(){
		$("#map-people-hilite").hide();		
	});
	$("#area-register").hover(function(){
		$("#map-register-hilite").show();
	},function(){
		$("#map-register-hilite").hide();		
	});
	$("#area-evaluation").hover(function(){
		$("#map-evaluation-hilite").show();
	},function(){
		$("#map-evaluation-hilite").hide();		
	});
	$("#area-curriculum").hover(function(){
		$("#map-curriculum-hilite").show();
	},function(){
		$("#map-curriculum-hilite").hide();		
	});
	$("#area-resources").hover(function(){
		$("#map-resources-hilite").show();
	},function(){
		$("#map-resources-hilite").hide();		
	});
	$("#area-cooking-bus").hover(function(){
		$("#map-cooking-bus-hilite").show();
	},function(){
		$("#map-cooking-bus-hilite").hide();		
	});
	$("#area-filmit").hover(function(){
		$("#map-filmit-hilite").show();
	},function(){
		$("#map-filmit-hilite").hide();		
	});
	$("#area-case-studies").hover(function(){
		$("#map-case-studies-hilite").show();
	},function(){
		$("#map-case-studies-hilite").hide();	
	});
	$("#area-contact").hover(function(){
		$("#map-contact-hilite").show();
	},function(){
		$("#map-contact-hilite").hide();	
	});
	$("#area-about").hover(function(){
		$("#map-about-hilite").show();
	},function(){
		$("#map-about-hilite").hide();	
	});
	$("#area-askit").hover(function(){
		$("#map-askit-hilite").show();
	},function(){
		$("#map-askit-hilite").hide();	
	});
}

if ($('#content .people.index').is(':visible')) {
	$("#right.people a").hover(function(){
		$(".frames a span").removeClass("border");
		$("#right.people a").removeClass("blue");

		var index = $(this).attr('id');
		$(".frames a." + index + " span").addClass("border");
	});
	$("#right.people a").mouseout(function(){
		$(this).addClass("blue");
	});

	$("#content .people.index a").hover(function(){
		$(".frames a span").removeClass("border");
		$("#right.people a").removeClass("blue");
		$(this).children('span').addClass("border");

		var index2 = $(this).attr('class');
		$("#right.people a#" + index2).addClass("blue");
	});
}

$(".view-home-quotes-ticker .views-row").wrapAll('<ul id="scroll-ticker" class="marquee-scroller"></ul>');

$(".view-home-quotes-ticker .views-row").wrap("<li></li>");

$("marquee").hover(function(){
this.stop();
},
function(){
	this.start();
});

if ($('#right.curriculum').is(':visible')) {
	$('#right.curriculum img:eq(1)').css("margin-left", "10px");
	$('#right.curriculum img:eq(3)').css("margin-left", "10px");
}

$("#right.sub-cur .block-top:eq(1)").css("margin-top", "0");

if ($('#comments').is(":visible")) {
	/*$("#comments .links ul.links li:not(.first)").prepend("|");*/
	//$('#comments > a[id^=comment-], #comments > div.comment, #comments > div.indented, #comments #comment-controls').wrapAll('<div class="wrap l1"></div>');
	$('#comments #comments-header').click(function(){
		$('#comments .comments-body').slideToggle();
	});
}

if ($("body").is(".front")){
	

	$('map area').tooltip({
		track: true,
		fade: 200,
		delay: 0,
		showURL: false,
		bodyHandler: function(){
			var mapTitle = $(this).attr("class");
			var mapURI = $('img.tag[alt="' + mapTitle + '"]').attr("src");
			return '<img src="' +  mapURI + '" alt="" />';
		}
	});

$(".front .view-feat-film-fields .views-field-view-node span").prepend('<a class="feat-play">Play film</a>');

var ffPath = $(".views-field-field-filmit-path-value span").html();
var ffWidth = parseInt($(".views-field-field-filmit-width-value span").html());
var ffHeight = parseInt($(".views-field-field-filmit-height-value span").html());
var ffFrame = $(".views-field-field-filmit-frame-path-value span").html();

var ffHeight2 = ffHeight - 20;

var ffEmbed = '<embed src="http://openfutures.com/filmit/player/mediaplayer.swf" width="' + ffWidth + '" height="' + ffHeight + '" allowscriptaccess="always" allowfullscreen="true" flashvars="file=' + ffPath + '&amp;image=' + ffFrame + '&amp;autostart=true"></embed>';

var ffWebKit = '<embed width="' + ffWidth + '" height="' + ffHeight2 + '" autoplay="true" src="' + ffPath + '"></embed>';

if ($(".intro-video .video-featured").is(":not(.apple)")){
	$(".intro-video .video-featured").html(ffEmbed);
}

if ($(".intro-video .video-featured").is(".apple")){
	$(".intro-video .video-featured").html(ffWebKit);
}

var iVid1 = $(".intro-video > .video-1").html();
var iVid2 = $(".intro-video > .video-2").html();
var iVid3 = $(".intro-video > .video-3").html();

$(".intro-thumb img.video-1").click(function(){
	$(".intro-video > div").html('').hide();
	$(".intro-video > .video-1").html(iVid1).show();
	$(".intro-video").show();
	$(".home .modal").css('filter','alpha(opacity=70)').fadeIn();
});
$(".intro-thumb img.video-2").click(function(){
	$(".intro-video > div").html('').hide();
	$(".intro-video > .video-2").html(iVid2).show();
	$(".intro-video").show();
	$(".home .modal").css('filter','alpha(opacity=70)').fadeIn();
});
$(".intro-thumb img.video-3").click(function(){
	$(".intro-video > div").html('').hide();
	$(".intro-video > .video-3").html(iVid3).show();
	$(".intro-video").show();
	$(".home .modal").css('filter','alpha(opacity=70)').fadeIn();
});
$("a.feat-play, .front .views-field-field-filmit-thumbnail-fid img").click(function(){
	$(".intro-video > div").html('').hide();
	
	if ($(".intro-video .video-featured").is(":not(.apple)")){
		$(".intro-video .video-featured").html(ffEmbed).show();
	}

	if ($(".intro-video .video-featured").is(".apple")){
		$(".intro-video .video-featured").html(ffWebKit).show();
	}
	
	$(".intro-video").show();
	$(".home .modal").css('filter','alpha(opacity=70)').fadeIn(400);	
});

$(".intro-video .close").click(function(){
	$(".intro-video > div").hide();
	$(".intro-video").hide();
	$(".home .modal").fadeOut(400);
});	

$(".views-field-field-quotes-role-value .field-content").prepend("&nbsp;&ndash&nbsp;").append(",&nbsp;");;

$("#scroll-pane").scrollable({ circular: true, mousewheel: false }).navigator({
	//navi: "#flowtabs",
	naviItem: 'a',
	activeClass: 'current',
	history: false
});

var aVid = 0;
var sIndex;

$(".intro-play .video-show").click(function(){

sIndex = $("#scroll-pane").data("scrollable");

sIndex.onSeek(function(){
	aVid = this.getIndex();
});
	if (aVid == 0){
		$(".intro-thumb img.video-1").trigger("click");
	}	
	if (aVid == 1){
		$(".intro-thumb img.video-2").trigger("click");
	}	
	if (aVid == 2){
		$(".intro-thumb img.video-3").trigger("click");
	}	
});

// $ front
}

if ($("body").is(".admin")){

}

if ($('#comments').is(":visible")) {
	$('#comments input[type="radio"]').removeAttr("checked");
	$('#comments input#edit-format-4').attr("checked", "checked");
	$('#comments input#edit-format-4-1').attr("checked", "checked");
	$('textarea').val('');

$("#edit-notify, #edit-notify-1").attr("checked", "checked");
$("#edit-notify-type-1-1, #edit-notify-type-1").attr("checked", "checked");

$("#edit-notify, #edit-notify-1").click(function(){
	
	if ($(this).is(":not(:checked)")){
		$('#comments .form-radios input[type="radio"]').removeAttr("checked");
	}
	
	if ($(this).is(":checked")){
		$('#comments .form-radios input[type="radio"]').removeAttr("checked");
		$("#edit-notify-type-1-1, #edit-notify-type-1").attr("checked", "checked");
	}	
	
});


$('#comments .form-radios input[type="radio"]').click(function(){	
	
});


}

$('#comments .comments-body > .box').prependTo('#comments');

if ($("#comments > .comments-body > .box > .content").filter(":empty").length > 0){
	//$("#comments > .comments-body, #comments #comments-header, #comments #comments-footer").hide();
}

	$('#comments > .box > h2:not(.ajax-comments-processed)').click(function(){
		$('#comments > .box > .content').slideToggle();
	});
/*
$('#comments > .box > h2.ajax-comments-processed > a#comment-form-title').removeAttr("href");
*/
/*
$("#comments .links ul.links li a").removeAttr("href");
*/
	$('#comments .box h2 a').click(function(){
		//$('#comments .box h2 a').removeAttr("href");
		//return false;
	});
/*
$("#comments h2.ajax-comments-processed a").text('');
$("#comments > .box > h2:not(.ajax-comments-processed)").text('');
*/
$("#comments h2").append('<span class="close"></span>');
$("#comments #comments-header").append('<span class="close"></span>');

/* ------------------------------------------------------------------ */
if ($("#comments form:not(#comment-controls)").is(":visible")){
	$("#comments h2 .close").addClass("open");
}
if ($("#comment form:not(#comment-controls)").is(":not(:visible)")){
	$("#comments h2 .close").removeClass("open");
}
$("#comments h2 a").click(function(){//this <a>
		$("#comments h2 .close").toggleClass("open");
});
$("#comments h2 .close").click(function(){
	if ($("#comments h2 a").length > 0){
		$("#comments h2 a").trigger("click");
	}
	if ($("#comments h2 a").length == 0){
		//$("#comments h2").trigger("click");
	}
		//$("#comments h2").trigger("click");
		//$("#comments h2 .close").toggleClass("open");
});
/* ------------------------------------------------------------------ */
if ($(".comments-body").is(":visible")){
	$("#comments-header .close").addClass("open");
}
if ($(".comments-body").is(":not(:visible)")){
	$("#comments-header .close").removeClass("open");
}
$("#comments-header").click(function(){
		$("#comments-header .close").toggleClass("open");
});
/* ------------------------------------------------------------------ */

$(".ajax-comments-processed").click(function(){
	//return false;
});

if ($("#forum").is(":visible")) {

$("#content-area").prepend("<h3></h3>");
$("#content-header h1").prependTo("#content-area > h3");
$('#content-area > h3').ttfgen();

$("#forum td.title").each(function(){
	$(this).html($(this).find("a"));
});

$("#forum > table tr.sticky-topic:eq(0)").addClass("first").before('<tr class="head topic-1"><td colspan="4">Important topics</td></tr>');
$("#forum > table tr.first-not-sticky").before('<tr class="head topic-2"><td colspan="4">General topics</td></tr>');
//$("p").before("<b>Hello</b>");

}
if ($(".forum-topic-header").is(":visible")) {

$("#content-area").prepend("<h3></h3>");
$("#content-header h1").prependTo("#content-area > h3");
$('#content-area > h3').ttfgen();

}



// $ Document Ready
});
