/**
 * Javascript for ggfx.org Custom Theme ggfx2010 by Cornelius Rittner
 */

function set_cookie(args) {
	switch(args) {
	case "sound_off":
		$.cookie("flashsound","off",{ expires:30,path:"/"});
		break;
	case "sound_on":
		$.cookie("flashsound",null,{ path:"/" });
		break;
	case "flash_played":
		$.cookie("flashplayed","true",{ expires:1,path:"/"});
		break;
	}
}

function slide_commentform() {
	$("#postcomment span").css("background-position","right -36px");
	$("#commentform").slideDown("slow");
}

/**
 * Start Javascript, when page is loaded
 */
$(document).ready(function(){
// scroll all local anchors
	$.localScroll();
	$("#top-link .link_top").hover(function(){
		$(this).css("background-position","left -206px").animate({'background-position':'left -221px'},200,'linear');
	},function(){
		$(this).stop().animate({'background-position':'left -206px'},100,'linear');
	});
// load Flash Videos
	if (typeof(ggfxFlashLogo) != "undefined") {
		$('#logo').html(ggfxFlashLogo);
	}
	if (typeof(deathStarFlash) != "undefined") {
		$('#deathstar').html(deathStarFlash);
	}
// Set some Opacity Stuff
	$('#sidebar, .blackback, #commentlist').css('opacity',.7);
	$('#loginout .link_loginout a').css('opacity',.7).hover(function(){$(this).css('opacity',1);},function(){$(this).css('opacity',.7);});
	$('.share_img').css('opacity',.4).hover(function(){$(this).css('opacity',1);},function(){$(this).css('opacity',.4);});
	$('.addthis_button').css('opacity',.6).hover(function(){$(this).css('opacity',1);},function(){$(this).css('opacity',.6);});
	$('#commentform, #searchform').find('.btn1').css('opacity',.6);
	$('#commentform, #searchform').find('input.btn').hover(function(){
		$(this).parent().css('opacity',1).css('background-position','left -175px');
		$(this).css('background-position','right -145px');
	},function(){
		$(this).parent().css('opacity',.6).css('background-position','left -115px');
		$(this).css('background-position','right -85px');
	});
	$("#searchform input[type='text'], #commentform input[type='text'], #commentform textarea, #recaptcha_widget_div").css('opacity',.7);
	$("#s").focus(function(){ mysearchterm = $(this).val(); $(this).val(""); }).blur(function(){ if ($(this).val() == "") $(this).val(mysearchterm); });

// hide Commentform
	$("#commentform").hide();
	$("#postcomment").mouseover(function(){
		slide_commentform();
	});
	$(".link_postcomment").click(function(){
		slide_commentform();
	});

// load Colorbox
	$(".load_colorbox").colorbox();
	$(".load_colorbox_iframe").colorbox({iframe:true, innerWidth:640, innerHeight:384});

// find external Links, add target blank
	$("a[rel*=external], #bookmarks a").attr("target","_blank");
	$("a[rel*=external]").addClass('link_external');
	
// animate hal9000 search
	$("#searchform").submit(function(){
		if (typeof(halclicked) == "undefined") {
			var src = $("#hal9000").attr("src")
			$("#hal9000").attr("src",src.substr(0,src.length-4)+'ani.gif');
			halclicked = true;
			window.setTimeout(function(){ $("#searchform").submit(); },1000);
			return false;
		} else {
			return true;
		}
	});
});
