// Load a new project function
function loadProject(client) {
	document.title = document.originalTitle;
	if (client != "blog") {
		if (client == 'portfolio') client = 'home';
		if (client != 'home') {
			if ($.browser.msie) {
				client = encodeURIComponent(client);
			}
			$('#projectPane').load("portfolio/" + client + ".php", function(){ 
				if ($('#video').length > 0) createPlayer(client);
				$('#track').animate({left:'-960px'}, 800);
				$('#portfolioLink').fadeIn();
			});
		} else {
			$('#portfolioLink').fadeOut();
			$('#track').animate({left:'0'}, 800, function() {
				$('#projectPane').html('');
			});
		}
	}
}
// Create flash video player function
function createPlayer(name) {
	var flashvars = {
		image: "portfolio/" + name + ".jpg",
		file: "video/" + name + ".mov", 
		screencolor: "3A7FBB",
		skin: "swf/overlay.swf",
		controlbar: "none",
		repeat: "always"
	}

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

	var attributes = {
		id: "player",  
		name: "player"
	}

	swfobject.embedSWF("swf/player.swf", "video", "460", "288", "9.0.115", false, flashvars, params, attributes);
}
function interact() {
	document.originalTitle = document.title; 
	$('.readmore').css({display:'inline-block'});
	$('.hidden').hide();
	//Initialise history
	$.historyInit(loadProject);
	// Remove dotted line in IE
	$('a').click(function() {
  		this.blur();
	});
	// Client tabs click behaviour
	$('#projects li a').click(function() {
		var client = $(this).attr('class');
		$.historyLoad(client);
		return false;
	});
	$('#portfolioLink').click(function() {
		$.historyLoad('home');
		return false;
	});
	$(".input").focus(function(srcc) {   
		$(this).removeClass("inputActive");
        if ($(this).val() == $(this)[0].title) {
            $(this).val("");
        }
    });
    // Create default text in login boxes
    $(".input").blur(function() {
        if ($(this).val() == "") {
            $(this).addClass("inputActive");
            $(this).val($(this)[0].title);
        }
    });
	$(window).load(function () {
		$(".input").blur();
	});
	$("#login h2 a").click(function() {
		if ($('#login .holder').css('right') == "0px") {
			$('#login .holder').animate({right: "-410px"});		
		} else {
			$('#login .holder').animate({right: "0px"});
		}
		return false;
	});
	/* check for iPhone */
   	var agent=navigator.userAgent.toLowerCase();
	var is_iphone = ((agent.indexOf('iphone')!=-1));
	if (is_iphone) {
	
		/* iPhone telephone number formatting */
		/* adds 'tel:' schema formatted phone number to all microformatted telephone number on the page */
		$('.tel').each(function(){
			var telNo = $(this).text().replace(/\(.*\)/,'').replace(/\s+/g,'');
			var wrapLink = '<a href="tel:'+telNo+'" class="tel">'+telNo+'</a>';
			$(this).replaceWith(wrapLink);
		});
	
	}
	$('.readmore').click(function() {
		$(this).hide();
		$(this).next().fadeIn();
		return false;
	});
}
$(document).ready(function() {interact();});