// JavaScript Document
function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}

function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function interactProject() {
			$('.slideshow').innerfade({
				speed: 'slow',
				timeout: 4000,
				containerheight: '100%'
			});
			$("#bigimage, .thumbnails li a").fancybox({
				'zoomSpeedIn': 600, 
				'zoomSpeedOut': 600,
				'overlayOpacity': .5
			});
}
function interactSection() {
			$('.tabs ul li a').click(function() {
				$('.project').html('<div class="throbber"></div>');
				$('.project').load($(this).attr("href"), {width: $(window).width(), height: $(window).height()}, function () {
					interactProject();
				});
				$('.tabs ul li a.active').removeClass('active');
				$(this).addClass('active');
				return false;
			});
			$('.slideshow li a').click(function() {
				$('.project').html('<div class="throbber"></div>').load($(this).attr("href"), {width: $(window).width(), height: $(window).height()}, function () {
					interactProject();
				});
				$('.tabs ul li a.active').removeClass('active');
				folder = $(this).attr("class");
				$('.tabs ul li a.'+folder).addClass('active');
				return false;
			});
			$('#film a').click(function() {
				flv = $(this).attr("href").split('?');
				
	var flashvars = {
		file: "../" + flv[0], 
		autostart: "true",
		screencolor: "000000",
		skin: "swf/overlay.swf",
		controlbar: "over"
	}

	var params = {
		allowfullscreen: "true", 
		allowscriptaccess: "always",
		bgcolor: "#000000"
	}

	var attributes = {
	}
	swfobject.embedSWF("swf/player.swf", "flash", flv[1], flv[2], "9.0.115", false, flashvars, params, attributes);

				return false;
			});
			interactProject();
}
function interactTabs() {
	// declare variables
	var panelOpen = 0;
	// Remove dotted line in IE
	$('a').click(function() {
  		this.blur();
	});
	
	function openPanel(t) {
			helpshown=getCookie('helpshown');
			if (helpshown==null || helpshown=="") {
				$('#help').fadeIn('slow');
    			setCookie('helpshown',"1",365);
  			} else {
				$('#help').fadeOut('slow');
			}
			$('.content .container').html("");
			$('.content .container',t).html('<div class="throbber"></div>').load("ajax/" + $(t).attr("id") + ".php", {width: $(window).width(), height: $(window).height()}, function () {interactSection();});
			if ($('.panel.active').length > 0) {
				$('.panel.active .content').animate({right: "-80%"}, 'normal');
			}
			$('.panel.active, #card.active').removeClass('active');
			$(t).addClass('active');
			$('.panel:not(.active)').animate({left: "100%", width: "0%"}, 'normal', function () {$(this).hide();} );
			$('.panel.active').show().animate({left: "0%", width: "100%"}, 'normal', function () {
				$('.panel .panelbg').animate({width: "600px", left: "-200px"}, 'slow');
				$('#panels').animate( {width: "73.1%", "min-width": "730px", left: "0%"}, 'slow' );
				$('.navigation div span').css('opacity',0);
				$('.navigation div').eq(0).addClass( $('.panel:not(.active)').eq(0).attr('id') );
				$('.navigation div').eq(1).addClass( $('.panel:not(.active)').eq(1).attr('id') );
				$('.navigation div').eq(2).addClass( $('.panel:not(.active)').eq(2).attr('id') );
				$('.navigation div').eq(3).addClass( $('.panel:not(.active)').eq(3).attr('id') );
				$('.navigation').animate( {width: "2.05%", "min-width": "20px"}, 'slow', function () {
					$('.panel.active .content').animate( {right: "0%"}, 'slow');
				});
			});
			//$('#card').animate({ width: "25%", "min-width": "250px"  }, 'normal' );
			//$('#panels').animate({ width: "75%", "min-width": "750px" }, 'normal' );
			return false;
	};
	
	$('#card').addClass('active');
	// Set Link Click Behaviour
	$('.panel').click(function() {
		if ( !($(this).is('.active')) ) { // If this link isn't active
				openPanel(this)
			}
		});
	
	$(".navigation").hoverIntent(
	  function () {
		$('#panels').animate( {left: "-3%"}, 'slow' );
		$('.navigation').animate( {width: "5.05%"}, 'slow');
		$('.navigation div span').fadeTo('normal', 1);
	}, 
      function () {
		$('#panels').animate( {left: "0%"}, 'slow' );
		$('.navigation').animate( {width: "2.05%"}, 'slow');
		$('.navigation div span').fadeTo('normal', 0);
	});
	
	$('.navigation div').click(function() {
		var currPanel = $(this).attr('class');
		$('#panels').animate( {left: "0%", width: "75%"}, 'slow' );
		$('.navigation').animate( {width: "0%"}, 'slow', function () {
			$('.navigation div').removeClass();												   
			openPanel($('#' + currPanel));
		});
	});
	
	$('#card').click(function() {
		if ( !($(this).is('.active')) ) { // If this link isn't active
			helpshown=getCookie('helpshown');
			if (helpshown!=null && helpshown!="") {
				$('#help').fadeOut('slow');
			}
			$('.navigation').animate( {width: "0%"}, 'slow' );
			$('#panels').animate( {width: "75%", "min-width": "750px"}, 'normal' );
			$('.panel.active .content').animate( {right: "-80%"}, 'slow' , function () {
			$('.panel .panelbg').animate({width: "100%", left: "0px"}, 'normal');
			$('#panel1').animate({left: "-2px", width: "20%"}, 'normal' );
			$('#panel2').animate({left: "20%", width: "20%"}, 'normal' );
			$('#panel3').animate({left: "40%", width: "20%"}, 'normal' );
			$('#panel4').animate({left: "60%", width: "20%"}, 'normal' );
			$('#panel5').animate({left: "80%", width: "20%"}, 'normal' );
			$('.navigation div').removeClass();
			});
			$('.panel.active').removeClass('active');
			$(this).addClass('active');
			//$('#card').animate({ width: "33%", "min-width": "330px" }, 'normal' );
			//$('#panels').animate({ width: "67%", "min-width": "670px" }, 'normal' );
		}
		});
	
}
$(document).ready(function() {interactTabs();});