$(function(){
	if($("body").children("#slideshow")){
		var slide_pos = Math.round(($(window).width()-750)/2);
		$("#prankly_slide").css("left",slide_pos);
		startSlideShow();
	}
	$("#prankly_toggle, #busring_toggle, #dllfiles_toggle").click(function(e){
		var end_pos = $(window).width();
		var this_id;
		var active_id;
		var this_pos;
		var click_id;
		var slide_id;
		click_id = $(this).attr("id");
		slide_id = click_id.replace("toggle","slide");
		stopSlideShow();
		$("#slideshow > .viewport").children(".slide").each(function(i){
			this_id = $(this).attr("id");
			this_pos = parseInt($(this).css("left"));
			$(this).stop(true);
			if(this_pos > -750){
				active_id = this_id;
			}
		});
		if(active_id != slide_id){
			$("#"+active_id).animate({
				left: end_pos
			},500,'swing',function(){
				$(this).css("left",-750);
				$("#"+slide_id).animate({
					left: slide_pos
				},500,'swing');
			});
		}
		return false;
	});
	
	$("#send_email").click(function(){
		$.getJSON("/ajax.email.php?"+$("#contact_form").serialize(),function(data){
			alertDialog(data.html);
			if(data.success == true){
				$("#contact_email").val('Your e-mail...');
				$("#contact_subject").val('Subject...');
				$("#contact_msg").val('Drop a few lines...');
			}
		});
	});
	
	$("#contact_email").focus(function(){
		if($(this).val()=='Your e-mail...'){
			$(this).val('');
		}
	});
	$("#contact_email").blur(function(){
		if($(this).val()==''){
			$(this).val('Your e-mail...');
		}
	});
	
	$("#contact_subject").focus(function(){
		if($(this).val()=='Subject...'){
			$(this).val('');
		}
	});
	$("#contact_subject").blur(function(){
		if($(this).val()==''){
			$(this).val('Subject...');
		}
	});
	
	$("#contact_msg").focus(function(){
		if($(this).val()=='Drop a few lines...'){
			$(this).val('');
		}
	});
	$("#contact_msg").blur(function(){
		if($(this).val()==''){
			$(this).val('Drop a few lines...');
		}
	});
	
	setContentHeight();
	$(window).resize(function(){
		window.location.reload();
	});
});
var slide_nr = 0;
var slides = ["busring_toggle","dllfiles_toggle","prankly_toggle"];
var t;
function startSlideShow(){
	t = setTimeout("slideShow()",10000);
}
function stopSlideShow(){
	clearTimeout(t);
}
function slideShow(){
	$("#"+slides[slide_nr]).click();
	slide_nr=slide_nr+1;
	if(slide_nr > 2){
		slide_nr = 0;
	}
	t = setTimeout("slideShow()",10000);
}
function setContentHeight(){
	if($("body").height() < $(window).height()){
		var content_height = $(window).height() - $("#top").outerHeight() - $("#slideshow").outerHeight() - $("#slideshow_menu").outerHeight() - $("#foot").outerHeight();
		$("#body").height(content_height);
	}
}
function alertDialog(content){
	var z = 1000;
	$("body").append("<div class=overlay></div>");
	$("body").append("<div class=alert_dialog><div class=x_icon><a href='#'>close</a></div><div class=body>"+content+"</div><div class=button><a href='#'>OK</a></div></div>");
	$(".alert_dialog > .x_icon").children("a").click(function(){
		$(this).parent().parent().remove();
		$("body > .overlay").remove();
		return false;
	});
	$(".alert_dialog > .button").children("a").click(function(){
		$(this).parent().parent().remove();
		$("body > .overlay").remove();
		return false;
	});
	$(".overlay").css("z-index",z);
	$(".overlay").width(function(i,w){
		return $("body").width();
	});
	$(".overlay").height(function(i,h){
		return $("body").height();
	});
	$(".alert_dialog").css({"left":function(i,v){
		return ($(window).width() - $(this).outerWidth())/2;
	},"top":function(i,v){
		return (($(window).height() - $(this).outerHeight())/2) + $(window).scrollTop();
	},"z-index":function(i,v){
		return z+1;
	}});
}
