/* ------------------------------------------------------------------------
	portfolio
	
	Basic javascript functionality for erikacrossdesign.com
	
	Developped by: Antonis Matakos
	
	sliderFun function based on s3Slider
	
	Developped By: Boban Karišik -> http://www.serie3.info/
        CSS Help: Mészáros Róbert -> http://www.perspectived.com/
	Version: 1.0
	
	Copyright: Feel free to redistribute the script/modify it, as
			   long as you leave my infos at the top.
------------------------------------------------------------------------- */

var faderStat = new Array(true,true,true,true,true,true,true,true,true,
							true,true,true,true,true,true,true,true,true);
var bioClick = true;
var awardsClick = false;
var exhibitionsClick = false;

$(document).ready(function(){	
	
	var sliderFun = function(event){
		var timeOut = 700;
		var slide = $(this).parent().prev().children().get(0);
		var span = $(slide).children().get(0);
		var id = $(span).attr("id");
		var current = this;
			
		if(faderStat[id] == true) {
			
			current.className = "font_reg col_pink";
			$(slide).fadeIn((timeOut), function() {
				$(span).slideDown((timeOut), function() {
					faderStat[id] = false;
					
					current.className = "font_reg col_white";
					current.innerHTML = "HIDE INFO"
				});
			});
		} else {
			var test1 = $(current).parent().next().next().children(":first")
						.attr("class");
			var test2 = $(current).parent().next().next().next()
						.children(":first").attr("class");
			
			if (test1 == "black" || test2 == "black")
			{
				current.className = "font_reg col_white";
			}
			else
			{
				current.className = "font_reg col_gray";
			}
			current.innerHTML = "SHOW INFO"
			
			
			
			$(span).slideUp((timeOut), function() {
				$(slide).fadeOut((timeOut), function() {
					faderStat[id] = true;
				});
			});
		}
	};
	
	var bioFun = function(event) {
	
		var id = $(this).parent().attr("id");
		
		var textSpan = $(this).parent().parent().children(":first").next()
				.children(":first");
						
		if (bioClick == true && id == "about-bio") // do nothing
		{
			
		}
		
	};
	
	var doc = window.location.pathname;
	var path = doc.substring(0, doc.lastIndexOf('/') + 1);
	var fname = doc.substring(path.length, doc.length - 5);
	var image = $("#navgraph img");
	
	if (fname == "index")
	{
		$("#logo a").replaceWith("<span><img alt=\"image\" " + 
					"src=\"./_images/logo.png\" width=\"172px\" " +
					"height=\"38px\"/></span>");
	}
	else if (fname == "about" || fname == "awards" || fname == "exhibitions")
	{
		$("#l1").replaceWith($(document.createElement("span"))
			.attr("class","col_pink").html("ABOUT&nbsp; &nbsp; &nbsp; &nbsp;"));
			
		$("#about-bio span").click(bioFun);
		$("#about-awards span").click(bioFun);
		$("#about-exhibitions span").click(bioFun);
	}
	else if (fname == "press")
	{
		$("#l2").replaceWith($(document.createElement("span"))
			.attr("class","col_pink").html("NEWS&nbsp; &nbsp; &nbsp; &nbsp;"));
	}
	else if (fname == "contact")
	{
		$("#l3").replaceWith($(document.createElement("span"))
			.attr("class","col_pink").html("CONTACT"));
	}
	else if (fname == "furniture")
	{
		$("#nav1 a").replaceWith($(document.createElement("span"))
			.attr("class","col_pink").html("FURNITURE"));
		image.attr("src","./_images/navbar_furniture.png");
	}
	else if (fname == "product")
	{
		$("#nav2 a").replaceWith($(document.createElement("span"))
			.attr("class","col_pink").html("OBJECT"));
		image.attr("src","./_images/navbar_product.png");
	}
	else if (fname == "graphic")
	{
		$("#nav3 a").replaceWith($(document.createElement("span"))
			.attr("class","col_pink").html("MEDIA"));
		image.attr("src","./_images/navbar_graphic.png");
	}
	else if (fname == "interiors")
	{
		$("#nav4 a").replaceWith($(document.createElement("span"))
			.attr("class","col_pink").html("SPACE"));
		image.attr("src","./_images/navbar_interiors.png");
	}
	else if (fname == "other")
	{
		$("#nav5 a").replaceWith($(document.createElement("span"))
			.attr("class","col_pink").html("ART"));
		image.attr("src","./_images/navbar_other.png");
	}
	else if (fname == "projects")
	{
		$("#nav6 a").replaceWith($(document.createElement("span"))
			.attr("class","col_pink").html("THESIS"));
		image.attr("src","./_images/navbar_projects.png");
	}
	
	if (fname == "furniture" || fname == "product" || fname == "graphic" ||
		fname == "projects" || fname == "other" || fname == "interiors")
	{
		var contLast = $("#container").children(":last");
		var cName = contLast.attr("class");
		
		if (cName == "contentbox")
		{
			contLast.attr("class","contentbox-last");
		}
		else if (cName == "contentbox-long")
		{
			contLast.attr("class","contentbox-long-last");
		}

		$(".iframe-bottom:last").remove();
		
		$(".sliderContent li span").each(function(i) {
			$(this).attr("id",i);
		});
		
		$(".black").each(function(index) {
			$(this).parent().prev().attr("class","iframe-top automargin blackbg");
			$(this).parent().next().attr("class","iframe-nav automargin blackbg");
			if ($(this).parent().attr("class") == "slider")
			{
				$(this).parent().prev().prev().children(":first")
					.attr("class","font_reg col_white");
				$(this).parent().prev().prev().prev().children(":first")
					.attr("class","font_reg col_white")
			}
			else
			{
				$(this).parent().prev().prev().children(":first")
					.attr("class","font_reg col_white");
			}
		});
		
		$(".iframe-info span").click(sliderFun);

		$(".iframe-info2 span").click(sliderFun);

		$(".iframe-info3 span").click(sliderFun);

		$(".iframe-info4 span").click(sliderFun);
		
		$(".slider").easySlider({
			speed: 500,
			numericId: 'numrg',
			className: 'controls'
		});
	
		$(".slider-long").easySlider({
			speed: 500,
			numericId: 'numlg',
			className: 'controls2'
		});
	}
	
 });

