var fade_interval = "";
var text_interval = "";
var slide_interval = "";
var text_array = new Array();
var counter = 0;
var start_text = false;

var intro_interval = "";
var intro = false;

$(document).ready(function(){
	if(object_exists("overlay")){
		//fade_interval = setInterval("fadeOut()", 2000);
	}
	else{
		//text_interval = setInterval("add_word()", 200);
	}
	if(intro){
		intro_interval = setInterval("logoFadeOut()", 2000);
		$("img.invisible").fadeIn(2000);
	}
});

function check_flash(){
	var playerVersion = swfobject.getFlashPlayerVersion();
	if(playerVersion.major == undefined || playerVersion.major == 0){
		return false;
	}
	else{
		return true;
	}
}

function logoFadeOut(){
	clearInterval(intro_interval);
	fadeOut();
}

function logoFadeIn(){
	intro = true;
}

function fadeOut(){
	//clearInterval(fade_interval);
	$("div#overlay").fadeOut("slow", function() { text_interval = setInterval("add_word()", 100); });
}

function object_exists(id){
	if(document.getElementById(id) != undefined){
		return true;
	}
	else{
		return false;
	}
}

function show_div(id){
	$("#" + id).css({'display':'block'});
}

function show_text(text, additional, div){
	text_array = text.split(" ");
	var text = "";
	for(var i = 0; i < text_array.length; i++){
		text += "<span class=\"w" + i + "\" >" + text_array[i] + "</span> ";
	}
	if(additional != undefined && additional != null){
		text += "<span id=\"flash-signature\" class=\"w" + text_array.length + "\">" + additional + "</span>";
	}
	if(div == undefined){
		div = "input";
	}
	$("div#" + div).html(text);
	/*var f_vars = {};
	show_flash('flash-signature', '186', '200', '/assets/flash/intro-small.swf', transparant, f_vars);*/
}

function add_word(div){
	if(div == undefined || div == null){
		div = "input";
	}
	if(counter <= text_array.length){
		$("div#" + div + " span.w"+counter).fadeIn("slow");
		counter++;
	}
	else{
		clearInterval(text_interval);
		if(div == "input"){
			slide_interval = setInterval("slide_input(0)", 2000);
		}
	}
}

function slide_input(side){
	clearInterval(slide_interval);
	if(side == 0){
		$("div#content").animate({"width" : "0px"}, 2000, "swing", function() { $("div#content").hide(); set_underlay(); } );
	}
	else{
		$("div#content").show();
		$("div#content").animate({"width" : "279px"}, 2000);
	}
}

function set_underlay(){
	//$("div#underlay").mouseover(function(){ slide_input(1) });
	//$("div#underlay").mouseout(function(){ slide_input(0) });
	$("div#content").css({"width" : "279px"});
	$("div#underlay").hover(function(){ $("div#content").show(); }, function(){ $("div#content").hide(); });
}

function show_flash(f_id, f_width, f_height, f_src, f_back, flashvars){	
	var params = {};
	params.quality = "high";
	params.menu = "false";
	params.bgcolor = f_back;
	params.wmode = "opaque";
	
	var attributes = {};
	attributes.id = "uniqueID";
	attributes.name = "uniqueID";

	swfobject.embedSWF(f_src, f_id, f_width, f_height, "8.0.0", "", flashvars, params, attributes);
}
var first = true;
function show_content(text, div){
	if(div == undefined || div == null){
		div = "slideshow_content";
	}
	if($("div#" + div + "").css("display") == "none"){
		if(div == "slideshow_content"){
			clearInterval(slideshow_interval);
		}
		show_text(text, undefined, div);
		if(first == true){
			$("div#" + div + "").fadeIn("slow", function() { text_interval = setInterval("add_word('" + div + "')", 100); });
		}
		else{
			$("div#" + div + "").html(text);
			$("div#" + div + "").fadeIn("slow");
		}
		first = false;
		$("a#projectinfo").attr({"class":"selected"});
	}
	else{
		if(div == "slideshow_content"){
			slideshow_interval = setInterval("slideshow_next()", 3000);
		}
		$("div#" + div + "").fadeOut("slow");
		$("a#projectinfo").attr({"class":"unselected"});
	}
}

var slideshow_count = 0;
var slideshow_images = new Array();
var slideshow_url = "";
var slideshow_interval = "";
var slideshow_on = 1;
var slideshow_off = 2;

function start_slideshow(images, url){
	slideshow_count = 0;
	slideshow_images = images;
	slideshow_url = url;
	$("img#slideshow_holder" + slideshow_off).attr({"src": slideshow_images[slideshow_count]});
	slideshow_interval = setInterval("slideshow_next()", 3000);
}

function slideshow_next(){
	slideshow_on = 2;
	slideshow_off = 1;
	if($("img#slideshow_holder2").css("display") == "none"){
		slideshow_on = 1;
		slideshow_off = 2;
	}
	
	if(slideshow_count == slideshow_images.length){
		if(slideshow_url == false){
			start_slideshow(slideshow_images, false);
		}
		else{
			document.location.href = slideshow_url;
		}
	}
	else{
		$("img#slideshow_holder" + slideshow_off).css({"z-index": "100"});
		$("img#slideshow_holder" + slideshow_on).css({"z-index": "50"});
		$("img#slideshow_holder" + slideshow_off).fadeIn(900, function() { $("img#slideshow_holder" + slideshow_on).hide(); $("img#slideshow_holder" + slideshow_on).attr({"src": slideshow_images[(slideshow_count+1)]}); slideshow_count++; } );
	}
}
