﻿jQuery.fn.addPlaceholder=function(B){if(B!=undefined&&$(this).val()===""){$(this).val(B)
}var A=$(this).attr("value");
$(this).focus(function(){if(this.value===A){this.value=""
}$(this).toggleClass("focus")
}).blur(function(){if(this.value===""){this.value=A
}$(this).toggleClass("focus")
})
};

var graphArr = [];
graphArr[0] = {'graph':'images/graph_1.png','header':'images/h1_birthpalce.png','text':'Also known as The Theory Of Creativity, our top-tier talent is genetically blessed with the ability to transform a brief into a fully-fledged Big Idea; divine inspiration striking anytime, anywhere.','flash':'/swf/big_idea'}
graphArr[1] = {'graph':'images/graph_2.png','header':'images/h1_intro2.png','text':'When the going gets tough, the tough get going. Covering traffic and studio management, production and more, our experienced candidates will keep your timeline on track and outlaw Murphy.','flash':'/swf/crisis'}
graphArr[2] = {'graph':'images/graph_3.png','header':'images/h1_intro3.png','text':"Whether it's a finger-pointing client or internal bungle, The Blame Game can rear its ugly head. Our top-tier candidates run the gamut of production services, successfully putting an end to errors to achieve win-win results.",'flash':'/swf/blame_game'}
graphArr[3] = {'graph':'images/graph_4.png','header':'images/h1_intro4.png','text':"That quick jot on a paper napkin may be the key to winning gold, and it takes a special talent to visualise. From blotted doodle to exceptional design, our creatives never get it lost in translation.",'flash':'/swf/doodle'}
graphArr[4] = {'graph':'images/graph_5.png','header':'images/h1_intro5.png','text':"It's time to get a life. For real. Enter our award-winning talent, on hand to reward you with outstanding creative and ensure that 6pm becomes your new (adhered-to) out-the-door policy.",'flash':'/swf/reward'}
graphArr[5] = {'graph':'images/graph_6.png','header':'images/h1_intro6.png','text':"When under-staffing becomes over-the-top, stress runs high. Here’s where our talent steps in, counteracting the lack-of with positive results, helping to restore a happy workplace.",'flash':'/swf/understaffed'}

 
 function validate(formObj){
	if (formObj.firstname.value == ""){
		alert('Please enter your First Name.');
		formObj.firstname.focus();
		return false;
	}
	if (formObj.lastname.value == ""){
		alert('Please enter your Surname.');
		formObj.lastname.focus();
		return false;
	}
	if (formObj.telephone.value == ""){
		alert('Please enter your contact number.');
		formObj.telephone.focus();
		return false;
	}
	if (formObj.email.value == ""){
		alert('Please enter your email.');
		formObj.email.focus();
		return false;
	}
	if(!checkemail(formObj.email.value.toLowerCase())){
		formObj.email.focus();
		return false;
	}
//	if (formObj.PortfolioOriginal.value == "" && formObj.CVOriginal.value == ""){
 //       alert("Please upload a CV or Portfolio.")
	//	return false;
	//}
}

function validateShareEmail(formObj){
	if (formObj.fromemail.value == ""){
		alert('Please enter your email.');
		formObj.fromemail.focus();
		return false;
	}
	if(!checkemail(formObj.fromemail.value.toLowerCase())){
		formObj.fromemail.focus();
		return false;
	}
	if (formObj.toemail.value == ""){
		alert('Please enter your friend\'s email.');
		formObj.toemail.focus();
		return false;
	}
	if(!checkemail(formObj.toemail.value.toLowerCase())){
		formObj.toemail.focus();
		return false;
	}
	formObj.submit();
	return true;
}

function checkemail(strEmail){
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(strEmail)){
		return true;
	}else{
		alert("Please enter a valid email address");
		return false;
	}
}

function newPopup(theURL,width,height,scrollbars) {
    x = (640 - width)/2, y = (480 - height)/2;

    if (screen) {
        y = (screen.availHeight - height)/2;
        x = (screen.availWidth - width)/2;
    }

    popwin = window.open(theURL,'newWin','width='+width+',height='+height+',screenX='+x+',screenY='+y+',top='+y+',left='+x+',scrollbars='+scrollbars+',status=no,resizable=no');
}

function setUploadedFileStatus(id, filename){
	$('#' + id + 'Link').val(filename);
	$('#' + id + 'Status').html('('+filename.substring(filename.indexOf("_")+1)+')');
}
var rnd;
function startAnimation(){
	$('#intro-img').animate({opacity: 0},1, function(){loadGraph()});
	$('#intro-text').animate({opacity: 0},1);
}

function startAnimationFlash(){
	var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
if(hasRightVersion) {  // if we've detected an acceptable version
	var flashObj = $('<div id="hero-flash">'+obj+'</div>');
	$('#leftbar').remove();
	$('#primary').remove();
	$('#main').append(flashObj);
	$('body').addClass('flash')
	// embed the flash movie
	var obj = AC_FL_RunContent(
		'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,2,0',
		'width', '700',
		'height', '500',
		'src', graphArr[rnd].flash,
		'quality', 'high',
		'pluginspage', 'http://www.adobe.com/go/getflashplayer',
		'align', 'middle',
		'play', 'true',
		'loop', 'true',
		'scale', 'showall',
		'wmode', 'window',
		'devicefont', 'false',
		'id', 'big_idea',
		'bgcolor', '#ffffff',
		'name', 'big_idea',
		'menu', 'true',
		'allowFullScreen', 'false',
		'allowScriptAccess','sameDomain',
		'movie', graphArr[rnd].flash,
		'salign', ''
		); //end AC code
	
} else {  // flash is too old or we can't detect the plugin
	$('#intro-img').animate({opacity: 0},1, function(){loadGraph()});
	$('#intro-text').animate({opacity: 0},1);
}
	
}

function loadGraph(){
	$('#intro-img').attr('src',graphArr[rnd].header);
	$('#intro-img').load(function(){
		showGraph();
	});
}

 function showGraph(){
 $('#graph-main').attr('src',graphArr[rnd].graph).load(function(){
		$(this).fadeIn(1000);
		$('#intro-img').animate({opacity: 1},500);
		$('#intro-text').html(graphArr[rnd].text).animate({opacity: 1},500);
	});
	
}

function highlightNav(){
	$('#secondarynav li').each(function(){
		var navurl = $(this).find('a');
		if(window.location.toString().indexOf(navurl.attr('href'))>-1){
			$(this).addClass('selected');
		}
	})
}

$(document).ready(function(){
	/* This is basic - uses default settings */
	
	$("a.share-email").fancybox({titleShow:false,autoScale:false,autoDimensions: false,width: 760,height: 340});

	$('.panel-register #firstname').addPlaceholder('FIRST NAME');
	$('.panel-register #lastname').addPlaceholder('LAST NAME');
	$('.panel-feedback #yourname').addPlaceholder('YOUR NAME');
	$('.panel-feedback #email').addPlaceholder('YOUR EMAIL');
	$('.panel-feedback #companyname').addPlaceholder('COMPANY NAME');
	$('.panel-feedback #freelancername').addPlaceholder('FREELANCER NAME');
	rnd = Math.floor(Math.random()*graphArr.length);
	if($('.home').length>0){ startAnimationFlash();}
	//var timeoutID = window.setTimeout(startAnimation, 1500);

	highlightNav();
})
