function resetFilter() {
	$("div#container").scrollTo(900);
	$("div#indexcard a").removeClass('current');
	$("div#indexcard a:first").addClass('current');
	$("div#artist_list a").animate({ opacity: 1 }, 300);
	$("li#reset_filter").remove();
	return false;
}

//request review
function requestReview(reviewstring) {
	$("textarea#comment").text("Why is there no review for " + reviewstring + " yet? I demand it!");
	$("textarea#comment").scrollTo(900);
	return false;
}

//close directory single overlay
function closeDirOverlay(){
	$("div#dir_overlay").fadeOut(300,function(){$("div#dir_overlay").remove();});
	$("div#dir_single").fadeOut(300,function(){$("div#dir_single").remove();});
}

$(document).ready(function(){
	var baseurl = "http://www.sixtyfive.sg/";
	$("#glowhider input.text").focus();
	$('.phantomtext').text('');

	/*
	 * ScrollToElement 1.0
	 * Copyright (c) 2009 Lauri Huovila, Neovica Oy
	 *  lauri.huovila@neovica.fi
	 *  http://www.neovica.fi
	 *  
	 * Dual licensed under the MIT and GPL licenses.
	 */

	(function($) {
	    $.scrollToElement = function( $element, speed ) {

	        speed = speed || 750;

	        $("html, body").animate({
	            scrollTop: $element.offset().top,
	            scrollLeft: $element.offset().left
	        }, speed);
	        return $element;
	    };

	    $.fn.scrollTo = function( speed ) {
	        speed = speed || "normal";
	        return $.scrollToElement( this, speed );
	    };
	})(jQuery);
	/*end scrolltoelement*/

	/*launch amp65 from homepage graphic*/
	$("a#launchamp65").click(function(){
		window.open("http://sixtyfive.sg/amp65/amp_sixtyfive.html","amp65","menubar=0,status=0,resizable=0,location=0,width=300,height=100");
		return false;
	});

	
	//header search bar 
	$("#nav_search").focus(function(){
		if($("#nav_search").attr("value") == "hit enter to search"){
			$("#nav_search").attr("value","");
		}
	});
	
	$("#nav_search").blur(function(){
		if($("#nav_search").attr("value") == ""){
			$("#nav_search").attr("value","hit enter to search")
		}
	});
	
	//homepage search bar interface
	$('#giant_search_bar input.submit').attr('value','');
	$('#giant_search_bar input.submit').hover(function(){
		$(this).css({'background-position':'center'});
	},function(){
		$(this).css({'background-position':'center bottom'});
	});
	$('#giant_search_bar input.submit').mousedown(function(){
		$(this).css({'background-position':'top'});	
	});
	
	
	//more reviews box
	$("div#more_reviews a").hover(function(){
		$(this).addClass('selected_album');
		var selected_album_name = $("a.selected_album img").attr("alt");
		var selected_artist_name = $("a.selected_album").attr("title");
		$("p#selected_album").fadeTo(40,.05,function(){
			$("p#selected_album span#selected_album_name").text(selected_album_name);
			$("p#selected_album span#selected_artist_name").text('by ' + selected_artist_name);
		});
		$("p#selected_album").fadeTo(40,1);
	}, function(){
		$(this).removeClass('selected_album');
		$("p#selected_album").fadeTo(40,.05,function(){
			$("p#selected_album span#selected_album_name").text('');
			$("p#selected_album span#selected_artist_name").text('');
		});
		$("p#selected_album").fadeTo(40,1);
	});
	
	//artist alphanumeric filter
	$("div#indexcard a:first").addClass('current');

	$("div#indexcard a").click(function(){
		$("li#reset_filter").remove();
		$("div#indexcard a").removeClass('current');
		$(this).addClass('current');
		var filterby = $(this).text();
		if(filterby == "All") {
			$("div#artist_list a").animate({ opacity: 1 }, 300);
		} else {
			if(filterby == "#") {
				filterby = 0;
			}
			$("div#artist_list a.initial_" + filterby + ":first").scrollTo(900);
			$("div#artist_list a.initial_" + filterby + ":last").parent().after("<li id='reset_filter'><a href='#' class='initial_" + filterby + "' onclick='resetFilter();return false;'> ← Back</a></li>");
			$("div#artist_list a.initial_" + filterby).animate({ opacity: 1 }, 300);
			$("div#artist_list a:not(.initial_" + filterby + ")").animate({ opacity: 0.3 }, 300);
		}
		return false;
	});
	
	$("div#artist_list a").click( function() {
		$("div#artist_list a").removeClass('current');
		$(this).addClass('current');
		$("#container").scrollTo(900);
		$("div#artist_detail").fadeTo("fast",.1, function(){
			$("div#artist_detail").html("<p id='loading_stuff'><img src='"+ baseurl +"wp-content/themes/sixtyfive_betasquare/images/loading_drawer.jpg' width='157' height='80' /><br />looking through our drawers...</p>").fadeTo("slow",.3);
		});
		var artistid = $(this).attr('id');
		artistid = artistid.substr(7);
		var artistdetail = baseurl + "artist-details/?ID=" + artistid;
		$("div#artist_detail").load(artistdetail,function(){
			$("div#artist_detail").fadeTo("slow",1);
			$("a.req_review").bind("click", function(){
				requestReview($(this).attr('title'));
				return false;
			});
		});
	});
	
	//video list over effect
	$("div#video_list a").hover( function() {
		$(this).find('img').fadeTo(100,.02);
	}, function(){
		$(this).find('img').fadeTo(100,1);
	});
	
	//load video when click 
	$("div#video_list a").click( function(){
		$("div#video_list a").removeClass('current');
		$(this).addClass('current');
		$("#container").scrollTo(900);
		$("div#playing_video").fadeTo("fast",.3, function(){
			$("div#playing_video #video_container").html("<p id='loading_stuff'><img src='"+ baseurl +"wp-content/themes/sixtyfive_betasquare/images/loading_drawer.jpg' width='157' height='80' /><br />looking through our drawers...</p>");
		});
		var videoid = $(this).attr('title');
		var postid = $(this).attr('href');
		videoid = videoid.substr(6);
		postid = postid.substr(1);
		var playingvid = baseurl + "playing-video/?ID=" + videoid + "&pid=" + postid;
		$("div#playing_video #video_container").load(playingvid,function(){
			$("div#playing_video").fadeTo("slow",1);
		});
	});
	
	//focus directory namecard when clicked
	$("a.directory_bookmark").click(function(){
		$("body").prepend('<div id="dir_overlay" style="position: absolute; width: 100%; height: 100%; z-index: 199; top:0px; background: transparent url(' + baseurl + 'wp-content/themes/sixtyfive_betasquare/images/directory/bg_overlay.png);"> &nbsp; </div>');
		$("body").prepend('<div id="dir_single" style="position: absolute; width: 360px; height: 260px; z-index: 200; left:50%; background: transparent url(' + baseurl + 'wp-content/themes/sixtyfive_betasquare/images/directory/bg_card.png) center no-repeat; padding: 20px; margin: 50px 0 0 -200px; display: none">abc</div>');
		$("#dir_single").load('http://www.sixtyfive.sg/directory-detail/?pid=' + $(this).attr('href').substr(1), function(){
			$("#dir_single").fadeIn(300);
			$("a#close_dir_over").bind("click", function(){
				closeDirOverlay();
				return false;
			});
		});
	});
	
	//this checks for links to direct artist/video through the url hash (#)

	$("div#artist_detail").ready(function(){
		if(location.hash) {
			var initartist = "div#artist_list a#artist_" + location.hash.substr(1);
			$(initartist).click();
		}
	});
	$("div#video").ready(function(){
		if(location.hash) {
			var initvideo = "a#video_" + location.hash.substr(1);
			$(initvideo).click();
		} else {
			$("div#video_list a:first").click();
		}
	});
	
	$("div#directory").ready(function(){
		if(location.hash) {
			var selperson = "#directory_entry_" + location.hash.substr(1) + " a.directory_bookmark";
			$(selperson).click();
		}
	});
	
	//the directory
	
})
