$(document).ready(function() {
	// Header Image Swap
	$(".swap").hover(function() {
		$(this).attr("src", $(this).attr("src").replace(".gif", "_on.gif"));
	}, function () {
		$(this).attr("src", $(this).attr("src").replace("_on.gif", ".gif"));
	});
	
	// Preload Image Swaps
	(function($) {
		var cache = [];
		$.preLoadImages = function() {
			var args_len = arguments.length;

			for (var i = args_len; i--;) {
				var cacheImage = document.createElement('img');
				cacheImage.src = arguments[i];
				cache.push(cacheImage);
			}
		}
	})(jQuery)
	
	jQuery.preLoadImages("/images/about_on.gif","/images/press_on.gif","/images/contact_on.gif","/images/s2_on.gif",
	"/images/video_games_on.gif","/images/commercials_on.gif","/images/films_on.gif","/images/internet_on.gif","/images/reel_on.gif",
	"/images/play_on.gif");
	
	/*
	// Home Grid Swap
	var projects_array = [ "video_games", "commercials", "films", "internet" ];
	jQuery.each(projects_array, function(){
		$("#" + this).hide();
		$("#video_games").show();
	});
	*/
	
	// projects menu magic
	$("#project_menu a").not(".hideProjects").click(function() {
		// make .lit ==> .waslit
		if (!$(".waslit").size())
			$(".lit").addClass("waslit");
		$(".lit").removeClass("lit");
		
		// make whoever we clicked on lit
		$(this).addClass("lit");
		
		// if not the homepage, fade in the backgrounds
		if (!$("#index").size()) {
			$("#white_overlay").show();
			$("#white_page_overlay").show();
			$("#white_overlay").animate({ opacity: .9 }, 500);
			$("#white_page_overlay").animate({ opacity: .9 }, 500);
			$(".hideProjects:hidden").fadeIn("slow");
			$("#projects_wrapper:hidden").fadeIn("slow");
		}
		
		// fade in the right section
		var trgt = this.id.replace('pg_','');
		
		if ($(".projects:visible").size()) {
			$(".projects:visible").fadeOut("fast",function(){
				$("#"+trgt+".projects").fadeIn("slow");
			});
		} else {
			$("#"+trgt+".projects").fadeIn("slow");
		}
		
		$("#movie_player:visible, #movie_player2:visible").addClass("notVisible");
		$(".notVisible").hide(0,function(){ $("#movie_click").show(); });
		
		return false;
	});
	
	$(".hideProjects").click(function(){
		// fix lit stuff
		$(".lit").removeClass("lit");
		$(".waslit").addClass("lit");
		$(".waslit").removeClass("waslit");
		
		//$("#white_overlay").animate({ opacity: 0 }, 500,'linear',function(){ $("#white_overlay").hide(); });
		//$("#white_page_overlay").animate({ opacity: 0 }, 500, 'linear',function(){ $("#white_page_overlay").hide(); });
		$("#white_overlay").animate({ opacity: 0 }, 500);
		$("#white_overlay").hide();
		$("#white_page_overlay").animate({ opacity: 0 }, 500);
		$("#white_page_overlay").hide();
		$("#projects_wrapper:visible").fadeOut("fast");
		$(".hideProjects:visible").fadeOut("fast");
		$(".notVisible").show(0,function(){ $("#movie_click:visible").hide(); });
		$(".notVisible").removeClass("notVisible");
		return false;
	});
	//*/
	
	// Video Button
	$(".click_to_play a").hover(function() {
		$(".click_to_play span").css({backgroundImage: "url(/images/play_on.gif)"});
	}, function() {
		$(".click_to_play span").css({backgroundImage: "url(/images/play.gif)"});
	});
	
	// JQWidont Removes Widows
	$('p').widont();
	
	// Twitter
    $(".tweet").tweet({
        username: "sekretagent",
        join_text: "auto",
        avatar_size: 0,
        count: 3,
        auto_join_text_default: "", 
        auto_join_text_ed: "",
        auto_join_text_ing: "",
        auto_join_text_reply: "",
        auto_join_text_url: "",
        loading_text: "Loading tweets"
    });
});
