$(document).ready(function(){


if(location.hash == "#wpcf7-f3-p26-o1"){
	$("#email_form").fadeIn("slow");
}
if(location.hash == "#wpcf7-f1-p26-o2"){
	$("#event_form").fadeIn("slow");
}
if(location.hash == "#wpcf7-f4-p26-o3"){
	$("#school_form").fadeIn("slow");
}
if(location.hash == "#wpcf7-f5-p26-o4"){
	$("#team_form").fadeIn("slow");
}

$('a.show_email').click(function(){
	$(".rollout_form").fadeOut("fast");
	$("#email_form").fadeIn("slow");
	$("#vid_link").fadeOut("fast");
	return false;
});

$('a.show_event').click(function(){
	$(".rollout_form").fadeOut("fast");
	$("#event_form").fadeIn("slow");
	$("#vid_link").fadeOut("fast");
	return false;
});

$('a.show_school').click(function(){
	$(".rollout_form").fadeOut("fast");
	$("#school_form").fadeIn("slow");
	$("#vid_link").fadeOut("fast");
	return false;
});

$('a.show_team').click(function(){
	$(".rollout_form").fadeOut("fast");
	$("#team_form").fadeIn("slow");
	$("#vid_link").fadeOut("fast");
	return false;
});


$('a.show_video').click(function(){
	$("#vid_link").fadeIn("slow");
	$(".rollout_form").fadeOut("fast");
	return false;
});



$('.rollout_form div.closer').click(function(){
	$(".rollout_form").fadeOut("fast");
	return false;
});


$('#vid_link div.closer').click(function(){
	$("#vid_link").fadeOut("fast");
	return false;
});


$('a.show_arrows').hover(
	function(){
		$("#social_arrows").fadeIn("fast");
	},
	function(){
		$("#social_arrows").fadeOut("fast");
	}
);

$('a.show_arrows').click(function(){
	return false;
});

$('a.show_more_arrows').hover(
	function(){
		$("#another_arrow").fadeIn("fast");
	},
	function(){
		$("#another_arrow").fadeOut("fast");
	}
);


$('a#help-us-reach').hover(
	function(){
		$(".specialThing3").css('backgroundPosition', '0 0');
	},
	function(){
		$(".specialThing3").css('backgroundPosition', '0 -71px');
	}
);


	if(document.getElementById("slideshow")){
		$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?id=37238694@N06&lang=en-us&tags=polaroid&format=json&jsoncallback=?", function(data){
			$.each(data.items, function(i,item){
				$("<img/>").attr("src", item.media.m).appendTo("#frame").wrap("<li id=\"pick-"+i+"\" class=\"item-"+i+"\"><a href='" + item.link + "'></a></li>");
				//var clearNum = String(i + 1);
				//var chooser = "<li class=\"picker\" id=\"pick-"+i+"\" rel=\""+i+"\">"+clearNum+"</li>";
				//$('ul#overlay').append(chooser);
				if ( i == 14 ) return false;
			});
		});

		displayStory = 1;
		details = document.getElementById('frame');
		stories = details.getElementsByTagName('li');

		$('#pick-0').addClass('active');
		rotateNext = setInterval('rotateStory(displayStory)', 5000);
		$("li#next").click(function () {
			clearInterval(rotateNext);
			rotateStory(displayStory);
		});
		$("li#previous").click(function () {
			clearInterval(rotateNext);
			rewindStory(displayStory);
		});
	}

	if(document.getElementById("scrolly_menu")){
		$("#scrolly_menu ul").css('height', '175px');
		$("#scrolly_menu ul").css('overflow', 'hidden');
		$("#scrolly_menu ul").jScrollPane({
			showArrows: true,
			verticalArrowPositions: 'after',
			horizontalArrowPositions: 'after',
			bottomCapHeight:'30',
			scrollbarWidth:40
		});

		

	}

});


function rotateStory(currentStory){
	currentStory = currentStory % stories.length;
	for (i = 0; i < stories.length; i++) {
		if (i == currentStory) {
			$('#frame li').fadeOut(1200);
			$(stories[i]).fadeIn(800);
			$('#frame li').removeClass('active');
			$('#pick-'+i).addClass('active');
		} 
	}
	displayStory++;
}
function rewindStory(currentStory){
	currentStory = currentStory % stories.length;
	for (i = stories.length; i > 0; i--){
		if (i == currentStory -2) {
			currentStory = currentStory -2;
			$('#frame li').fadeOut(1200);
			$(stories[i]).fadeIn(800);
			$('#frame li').removeClass('active');
			$('#pick-'+i).addClass('active');
		} 
	}
	displayStory++;
}



function funkyOldScrollyThing() {
	$('div.content div.entry').jScrollPane({showArrows:true, scrollbarWidth:21, dragMinHeight:54, dragMaxHeight:54});
	$('div.comment_wrap ol.commentlist').jScrollPane({showArrows:true, scrollbarWidth:21, dragMinHeight:54, dragMaxHeight:54});
	$('div.content div.entryReg #links').jScrollPane({showArrows:true, scrollbarWidth:21, dragMinHeight:54, dragMaxHeight:54});
	$('div.content div.entryReg #downloads').jScrollPane({showArrows:true, scrollbarWidth:21, dragMinHeight:54, dragMaxHeight:54});
}


/*
addEvent function from http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html
*/
function addEvent( obj, type, fn )
{
	if (obj.addEventListener)
		obj.addEventListener( type, fn, false );
	else if (obj.attachEvent)
	{
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
}

function removeEvent( obj, type, fn )
{
	if (obj.removeEventListener)
		obj.removeEventListener( type, fn, false );
	else if (obj.detachEvent)
	{
		obj.detachEvent( "on"+type, obj[type+fn] );
		obj[type+fn] = null;
		obj["e"+type+fn] = null;
	}
}

/*
Create the new window
*/
function openInNewWindow() {
	// Change "_blank" to something like "newWindow" to load all links in the same new window
    var newWindow = window.open(this.getAttribute('href'), '_blank');
    newWindow.focus();
    return false;
}

/*
Add the openInNewWindow function to the onclick event of links with a class name of "new-window"
*/
function getNewWindowLinks() {
	// Check that the browser is DOM compliant
	if (document.getElementById && document.createElement && document.appendChild) {
		// Change this to the text you want to use to alert the user that a new window will be opened
		var strNewWindowAlert = " (opens in a new window)";
		// Find all links
		var links = document.getElementsByTagName('a');
		var objWarningText;
		var strWarningText;
		var link;
		for (var i = 0; i < links.length; i++) {
			link = links[i];
			// Find all links with a class name of "non-html"
			if (/\bnon\-html\b/.exec(link.className)) {
				// Create an em element containing the new window warning text and insert it after the link text
				objWarningText = document.createElement("em");
				strWarningText = document.createTextNode(strNewWindowAlert);
				objWarningText.appendChild(strWarningText);
				link.appendChild(objWarningText);
				link.onclick = openInNewWindow;
			}
		}
		objWarningText = null;
	}
}

addEvent(window, 'load', getNewWindowLinks);

