var tabs=["clients","contact","aboutus","web","print","music","code"];
var lasttab=0;

/*
var navArray:Object = {
clients: {_label:"clients", _fn:"clients",_col:0xadd631},
contact: {_label:"contact", _fn:"contact",_col:0x9a0015},
aboutus: {_label:"about us", _fn:"aboutus",_col:0xc02b29},
web: {_label:"web",_fn:"web",_col:0x312f30},
print: {_label:"print",_fn:"print",_col:0x90a836},
music: {_label:"music",_fn:"music",_col:0xCF3229},
code: {_label:"code",_fn:"code",_col:0xfd931f}
};
*/
if(!Array.indexOf){
	Array.prototype.indexOf = function(obj){
		for(var i=0; i<this.length; i++){
			if(this[i]==obj){
				return i;
			}
		}
		return -1;
	}
}

function getFlashMovieObject(movieName)
{
	if (window.document[movieName]) return window.document[movieName];
	if (navigator.appName.indexOf("Microsoft Internet")==-1)
	{
		if (document.embeds && document.embeds[movieName])
		return document.embeds[movieName];
	}
	else  return document.getElementById(movieName);
	}

	//$(window).resize(function() { getFlashMovieObject('mainInterfaceFlash').resized(document.body.clientWidth); });

	var flashvars = {};

	var api = null;
	var params = {wmode:"transparent",allowscriptaccess:"always"};
	var attributes = {};
	var goToPage = "false";
	var hv = "";
	var flobj;
	hv = window.location.hash;
	if(hv == "" && argv != "") { hv = "#"+argv; };
	if (hv != "") {
		goToPage=hv.replace("#","");
		params.goToPage = goToPage;
		attributes.goToPage = goToPage;
		flashvars.goToPage = goToPage;
	} else {
		swfobject.embedSWF("swf/home.swf", "mainInterfaceFlash", "100%", "100%", "9.0.0","",flashvars, params, attributes);
	}
	var docWidth = 1024;
	window.onload=function() {
		docWidth = document.body.clientWidth;
		flobj = getFlashMovieObject('mainInterfaceFlash');
		if(hv!="") {
			$(flobj).remove();
			//	setTimeout(handleClick,10,hv);
			handleClick(hv);
		}
		$('div.opt').click(function(){ handleClick("#"+$(this).attr("fn"));	});
		var s = $(".scrollable");
		if(s !=null) {
			s.scrollable({ vertical: true, mousewheel: false });
			try { api=s.tabs(); }
			catch(err){}
		}

		disableSelection(document.getElementById("menu"));
		disableSelection(document.body);
	};


	var lasth ="";
	lastIdx=-1;

	function showContent(fn,h,idx) {
		if (lastIdx == idx) return;
		flobj = getFlashMovieObject('mainInterfaceFlash');
		if(flobj!=null) {
			$(flobj).remove();
			$("div#mainInterface").remove();
		}

		var h2 = h.replace('#','');
		document.title = "taste studio - " + h2;
		$("#thou").css("visibility","visible");
		$("#thou").fadeIn(250);
		$("#topBarHold").fadeIn();
		try { animateSliderTo(h); } catch (err) {  setTimeout(animateSliderTo,20,h);}
		var curr = $("#sub_"+h2);
		var newLeft = (docWidth/2)-400;
		if(lastIdx>-1) if(idx>lastIdx) { newLeft=(docWidth/2)+400; } else { newLeft = -400; }
			curr.css({left:newLeft,position:"absolute"});
			curr.animate({left: (docWidth/2)-400, opacity:"show" }, { duration: 400, ease: "easeInQuart"});

			if(last!=null) {
				var nl2=0;
				if (idx>lastIdx) { newLenl2ft=(docWidth/2)-400; } else { nl2 =(docWidth/2)+400; }
					last.animate({left: nl2, opacity:"hide"}, { duration: 400, ease: "easeOutQuart"});
				}
				$(document).scrollTop(0);
				setTimeout(function(){ 			curr.css({position:"absolute"}); },300);
				last = curr;
				lastIdx = idx;
				window.location.hash = h;
			};

			var last = null;

			function handleClick(hv)
			{
				var u="";
				var idx=0;
				var sect = hv.replace("#","");

				if (hv != "")
				{
					switch(hv) {
						case "#print": 	u="sub_print";		idx=2; break;
						case "#web": 		u="sub_web"; 			idx=1; break;
						case "#music": 	u="sub_music"; 		idx=3; break;
						case "#code": 	u="sub_code"; 		idx=4; break;
						case "#contact":u="sub_contact"; 	idx=6; break;
						case "#aboutus":u="sub_aboutus"; 	idx=0; break;
						case "#clients":u="sub_clients"; 	idx=5; break;
						case "#home": 	goHome(); break;
					}
				}
				if (u!="") showContent(u,sect,idx);
			}

			function animateSliderTo(sectIn) {
				if(sectIn==null) return;
				var sect = sectIn.replace("#","");
				var t = $("div#opt_"+sect);
				var c = t.attr("uc");
				//var toffset = Math.abs(lasttab-tabs.indexOf(sect));
				var toffset = 1;
				lasttab = tabs.indexOf(sect);
				t.animate({color:"white"},300);
				$('div#sel').animate({opacity:1, left:t.position().left, backgroundColor: c},{duration:350*toffset,queue:true});
				t.siblings().animate({color:"#888"},250);

			}

			function goHome() { $("div#content").fadeOut(200,function() { document.location.href = "/"; }); }


			function disableSelection(target){
				if (typeof target.onselectstart!="undefined") //IE route
				target.onselectstart=function(){return false}
				else if (typeof target.style.MozUserSelect!="undefined") //Firefox route
					target.style.MozUserSelect="none"
					else //All other route (ie: Opera)
						target.onmousedown=function(){return false}
						target.style.cursor = "default"
					}

					var shrinkTimer = 0;

