﻿/***************************/
//@Author: Hanno van der Merwe				
/***************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;
var relativeX = 0;
var relativeY = 0;
var currentButton;
var yOffset = 20;
var xOffset = 20;
var timer;
var popupTime = 500;
var closeTime = 50000;
var killTime = 1000;
var rollOutKillTime = 500;
var fadeTime = 200;
var largePopup = true;
var hoveringPopup = false;
var hoveringButton = false;
var moving = false;

function antiSpam()
{
	if(document.hgmailer.recipient.value != "info@conceptinteractive.net")
	{
		return false;
	}
	
	if(/<*>/i.test(document.hgmailer.commentInput.value) == true)
	{
		formPopup('Message not sent!', 'This form cannot be used to send HTML content.');
		return false;
	}
	
	return true;	
}

function hgsubmit()
{
	if(antiSpam())
	{
		var validPhone = Boolean(false);
		var validEmail = Boolean(false);
		
		if (/^(\()?([0-9]{3})(\))?( )?([0-9]{3})( )?(\-)?( )?([0-9]{4})$/i.test(document.hgmailer.Phone.value) == true)  
		{
			validPhone = true;			
		}
		
		if(/[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i.test(document.hgmailer.Mail.value) == true)
		{
			validEmail = true;	
		}
		
		if(validEmail || validPhone) {
			formPopup('Thank you for submitting your query', 'We will reply to your question via telephone as soon as possible');
			
		document.hgmailer.submit();			
		}
		else{
			formPopup("Invalid contact details","A valid email address or phone number is required.");	
		}
		
	}
}

function randomQuote(){
	var randomnumber=Math.floor(Math.random()*39);
	switch (randomnumber){
		case 1: {
					$('#quote').text("....going to Concept Interactive was more than just an eye opener for me.");
					$('#quoteName').text("Nandipha Nombuthuma, 2-year Digital Design course graduate - 2006");
		}	
		break;
	
		case 2: {
					$('#quote').text("From the first day I learnt more than I had ever imagined");
					$('#quoteName').text("Nandipha Nombuthuma, 2-year Digital Design course graduate - 2006");
		}
		break;
		case 3: {
					$('#quote').text("Concept not only gives you learning tools but also has lots of opportunities");
					$('#quoteName').text("Nandipha Nombuthuma, 2-year Digital Design course graduate - 2006");
		}
		break;
		case 4: {
					$('#quote').text("...it’s a place to learn and gain real world experience");
					$('#quoteName').text("Nandipha Nombuthuma, 2-year Digital Design course graduate - 2006");
		}
		break;
		case 5: {
					$('#quote').text("...it is a privilege to have encountered the passion and professionalism shown at Concept Interactive.");
					$('#quoteName').text("Matthew Scher - 2000 graduate (Currently Director / New Media Developer, Monzamedia)");
		}
		break;
		case 6: {
					$('#quote').text("Concept Interactive helped launch me into the dynamic New Media industry");
					$('#quoteName').text("Matthew Scher - 2000 graduate (Currently Director / New Media Developer, Monzamedia)");
		}
		break;
		case 7: {
					$('#quote').text("...certainly helped prepare me for the demanding nature of the business");
					$('#quoteName').text("Matthew Scher - 2000 graduate (Currently Director / New Media Developer, Monzamedia)");
		}
		break;
		case 8: {
					$('#quote').text("I credit and thank Concept Interactive for their professionalism and enthusiasm");
					$('#quoteName').text("Matthew Scher - 2000 graduate (Currently Director / New Media Developer, Monzamedia)");
		}
		break;
		case 9: {
					$('#quote').text("...which lead to a strong portfolio, ensured I was marketable from the outset");
					$('#quoteName').text("Steven Macbeth - 2000 graduate (Currently Creative Director, Highbury Safika Media)");
		}
		break;
		case 10: {
					$('#quote').text("...lecturers were very patient, encouraging and knowledgeable...");
					$('#quoteName').text("Gina Ross (nee Purcock) - 2005 graduate (Currently Head Designer, SiConsulting)");
		}
		break;
		case 11: {
					$('#quote').text("The projects were well thought out and geared towards maximum learning");
					$('#quoteName').text("Gina Ross (nee Purcock) - 2005 graduate (Currently Head Designer, SiConsulting)");
		}
		break;
		case 12: {
					$('#quote').text("Concept allowed learners to develop their own strengths");
					$('#quoteName').text("Gina Ross (nee Purcock) - 2005 graduate (Currently Head Designer, SiConsulting)");
		}
		break;
		case 13: {
					$('#quote').text("relevant skills to move into a broad range of employment opportunities.");
					$('#quoteName').text("Gina Ross (nee Purcock) - 2005 graduate (Currently Head Designer, SiConsulting)");
		}
		break;
		case 14: {
					$('#quote').text("I left the college with valuable skills");
					$('#quoteName').text("Francois van der Elst - 2002 graduate (Currently New Media Designer - Haygarth, London)");
		}
		break;
		case 15: {
					$('#quote').text("...and claiming that I was trained at Concept always made a big difference at interviews.");
					$('#quoteName').text("Francois van der Elst - 2002 graduate (Currently New Media Designer - Haygarth, London)");
		}
		break;
		case 16: {
					$('#quote').text("I’ve always been able to find work since graduation");
					$('#quoteName').text("Francois van der Elst - 2002 graduate (Currently New Media Designer - Haygarth, London)");
		}
		break;
		case 17: {
					$('#quote').text("...recommend an excellent private college, Concept would definitely be it!");
					$('#quoteName').text("Darren Croxford, 2-year Digital Design course graduate - 2006");
		}
		break;
		case 18: {
					$('#quote').text("The lecturers took the web plus design to the next level");
					$('#quoteName').text("Darren Croxford, 2-year Digital Design course graduate - 2006");
		}
		break;
		case 19: {
					$('#quote').text("I received more than adequate personal attention...");
					$('#quoteName').text("Niel Joubert - 1999 graduate");
		}
		break;
		case 20: {
					$('#quote').text("...equipped to enter the industry.");
					$('#quoteName').text("Niel Joubert - 1999 graduate");
		}
		break;
		case 21: {
					$('#quote').text("working on some of South Africa’s top brands and winning various awards - I would highly recommend Anne Centner and her team");
					$('#quoteName').text("Niel Joubert - 1999 graduate");
		}
		break;
		case 22: {
					$('#quote').text("Concept Interactive is the base of my career!");
					$('#quoteName').text("Chris Beech - 2004 graduate (Currently the owner and development director, Air Flow Interactive)");
		}
		break;
		case 23: {
					$('#quote').text("...they expose you to so much the industry has to offer.");
					$('#quoteName').text("Chris Beech - 2004 graduate (Currently the owner and development director, Air Flow Interactive)");
		}
		break;
		case 24: {
					$('#quote').text("The most valuable part of the college is that they helped organise both my first and second jobs");
					$('#quoteName').text("Chris Beech - 2004 graduate (Currently the owner and development director, Air Flow Interactive)");
		}
		break;
		case 25: {
					$('#quote').text("My career after college has been an awesome one!");
					$('#quoteName').text("Chris Beech - 2004 graduate (Currently the owner and development director, Air Flow Interactive)");
		}
		break;
		case 26: {
					$('#quote').text("..which included developing an instant messenger for 24.com");
					$('#quoteName').text("Chris Beech - 2004 graduate (Currently the owner and development director, Air Flow Interactive)");
		}
		break;
		case 27: {
					$('#quote').text("..professional and qualified team was invaluable");
					$('#quoteName').text("Raquel de Castro Maia - 2001 graduate (Creative Director, and founder CREATE DESIGN)");
		}
		break;
		case 28: {
					$('#quote').text("Every project and exercise was outlined with the utmost care and detail.");
					$('#quoteName').text("Raquel de Castro Maia - 2001 graduate (Creative Director, and founder CREATE DESIGN)");
		}
		break;
		case 29: {
					$('#quote').text("Every project and exercise was outlined with the utmost care and detail.");
					$('#quoteName').text("Raquel de Castro Maia - 2001 graduate (Creative Director, and founder CREATE DESIGN)");
		}		
		break;
		case 30: {
					$('#quote').text("I can only thank Concept Interactive for the fundamental knowledge");
					$('#quoteName').text("Raquel de Castro Maia - 2001 graduate (Creative Director, and founder CREATE DESIGN)");
		}
		break;
		case 31: {
					$('#quote').text("...achieve my dream in 2001, which was to win a Gold Construction Award at the Design Indaba.");
					$('#quoteName').text("Raquel de Castro Maia - 2001 graduate (Creative Director, and founder CREATE DESIGN)");
		}
		break;break;
		case 32: {
					$('#quote').text("I was able to travel and work abroad in some of the top UK based design and new media agencies");
					$('#quoteName').text("Raquel de Castro Maia - 2001 graduate (Creative Director, and founder CREATE DESIGN)");
		}
		break;
		case 33: {
					$('#quote').text("All this experience would not have been possible without the best technical foundation.");
					$('#quoteName').text("Raquel de Castro Maia - 2001 graduate (Creative Director, and founder CREATE DESIGN)");
		}
		break;break;
		case 34: {
					$('#quote').text("Thank you Concept Interactive for the highest standards and an excellent industry leading course.");
					$('#quoteName').text("Raquel de Castro Maia - 2001 graduate (Creative Director, and founder CREATE DESIGN)");
		}
		break;
		case 36: {
					$('#quote').text("I now run my own design studio");
					$('#quoteName').text("Raquel de Castro Maia - 2001 graduate (Creative Director, and founder CREATE DESIGN)");
		}
		break;break;
		case 37: {
					$('#quote').text(".and have grown into the shoes that you initially placed on my feet.");
					$('#quoteName').text("Raquel de Castro Maia - 2001 graduate (Creative Director, and founder CREATE DESIGN)");
		}
		break;
		case 38: {
					$('#quote').text("..the best training session of CS5 I have been to so far.");
					$('#quoteName').text("Cathy Terry - 2010 graduate (EVERGREEN DESIGN)");
		}
		break;
	}
}

//loading popup with jQuery
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		/*$("#backgroundPopup").css({
			"opacity": "0.7"
		});*/
		/*$("#backgroundPopup").fadeIn("fast");*/
		$(".popupContact").fadeIn("fadeTime");
		popupStatus = 1;
	}
}

//disabling popup with jQuery
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		//$("#backgroundPopup").fadeOut("fast");
		$(".popupContact").fadeOut("fadeTime", function() {
			popupStatus = 0;
			$("#popupImage").attr({ 
			  src: ""
			});
		});
		
		/*$('#book').fadeOut('slow', function() {
    // Animation complete.
  		});*/
	}
}

//moves popup to desired locatin
function positionPopup(){
	var xPos=relativeY+yOffset;
	var yPos=relativeX+xOffset;
	if(largePopup)
	{
		var topOfScreen;
		
		//test for multiple browsers
		if( typeof( window.pageYOffset ) == 'number' ) {
			//Netscape compliant
			topOfScreen =  window.pageYOffset;
		  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
			//DOM compliant
			topOfScreen = document.body.scrollTop;
		  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
			//IE6 standards compliant mode
			topOfScreen = document.documentElement.scrollTop;
		}
		
		yPos = topOfScreen+yOffset+20;
		
		if(relativeX < (screen.width/2)){
			xPos = relativeX+xOffset;
		} else{
			var popupWidth = $(".popupContact").css("width");
			var numLenght = popupWidth.length - 2;
			popupWidth = Number(popupWidth.substr(0,numLenght));
			xPos = relativeX - popupWidth - xOffset - 20;
		}
	}
	else
	{
		yPos = relativeY+yOffset;
		xPos = relativeX+xOffset;
	}
	
	$(".popupContact").css({
		"position": "absolute"/*,
		"left": xPos*/
	});
		
	if(!popupStatus){
		$(".popupContact").css({		
			"top": yPos,
			"left": xPos
		});		
		
	} else{
		if(!moving){
			moving = true;
			$(".popupContact").animate({
				"top": yPos,
				"left" : xPos
			  }, 500, function() {
				moving = false;
			});
		}
	}
	
	if(largePopup)
	{
		$(".popupContact").css({
			"-khtml-opacity": "95",
			"-moz-opacity": ".95",
			"-ms-filter": "alpha(opacity=95)",
			"filter": "alpha(opacity=95)",
			"opacity": ".95",
			"width": "650px",
			"max-width": "650px",
			"height": "570px"
		});
		$(".popupContact img").css("display","block");
		$("#popupHeading").css({
			"position":"absolute",
			"bottom":"25px",
			"margin-left":"306px"
		});
		$("#popupContent").css({
			"position":"absolute",
			"bottom":"10px",
			"margin-left":"300px"
		});
	}
	else{
		$(".popupContact").css({
			"max-width": "300px",
			"height": "auto"	
		});
		$(".popupContact img").css("display","inline");
		$("#popupHeading").css({
			"position":"static",
			"bottom":"0",
			"margin-left":"0"
		});
		$("#popupContent").css({
			"position":"static",
			"bottom":"0",
			"margin-left":"0"
		});
	}
}

//changes the content of the popup
function ChangeText() {   
   var head = document.getElementById("popupHeading");
   var newTitle;
   var content = document.getElementById("popupContent");
   var newContent;
   var newImage;   
   
   switch(currentButton)
   {
		case "student1":   {
			newTitle = "Click";
			newContent = "to view";
			newImage = "image/studentWork/student1_i.jpg";
		}
		break;
		case "student2":	{
			newTitle = "Click";
			newContent = "to view";
			newImage = "image/studentWork/student1.jpg";
		}
		break;
		case "student3":	{
			newTitle = "Click";
			newContent = "to view";
			newImage = "image/studentWork/student2.jpg";
		}
		break;
		case "student4":	{
			newTitle = "Click";
			newContent = "to view";
			newImage = "image/studentWork/student3.jpg";
		}
		break;
		case "student5":	{
			newTitle = "Click";
			newContent = "to view";
			newImage = "image/studentWork/student4.jpg";
		}
		break;
		case "student6":	{
			newTitle = "Click";
			newContent = "to view";
			newImage = "image/studentWork/student6_i.jpg";
		}
		break;
		case "student7":	{
			newTitle = "Click";
			newContent = "to view";
			newImage = "image/studentWork/student7_i.jpg";
		}
		break;
		case "student8":	{
			newTitle = "Click";
			newContent = "to view";
			newImage = "image/studentWork/student7.jpg";
		}
		break;
		case "student9":	{
			newTitle = "Click";
			newContent = "to view";
			newImage = "image/studentWork/student8.jpg";
		}
		break;
		case "student10":	{
			newTitle = "Click";
			newContent = "to view";
			newImage = "image/studentWork/student9.jpg";
		}
		break;
		case "student11":	{
			newTitle = "Click";
			newContent = "to view";
			newImage = "image/studentWork/student10.jpg";
		}
		break;
		case "student12":	{
			newTitle = "Click";
			newContent = "to view";
			newImage = "image/studentWork/student11.jpg";
		}
		break;
		case "student13":	{
			newTitle = "Click";
			newContent = "to view";
			newImage = "image/studentWork/student12.jpg";
		}
		break;
		case "student14":	{
			newTitle = "Click";
			newContent = "to view";
			newImage = "image/studentWork/student13.jpg";
		}
		break;
		case "student15":	{
			newTitle = "Click";
			newContent = "to view";
			newImage = "image/studentWork/student14.jpg";
		}
		break;
		case "student16":	{
			newTitle = "Click";
			newContent = "to view";
			newImage = "image/studentWork/student15.jpg";
		}
		break;
		case "student17":	{
			newTitle = "Click";
			newContent = "to view";
			newImage = "image/studentWork/student16.jpg";
		}
		break;
		case "student18":	{
			newTitle = "Click";
			newContent = "to view";
			newImage = "image/studentWork/student17.jpg";
		}
		break;
		case "student19":	{
			newTitle = "Click";
			newContent = "to view";
			newImage = "image/studentWork/student18.jpg";
		}
		break;
		case "student20":	{
			newTitle = "Click";
			newContent = "to view";
			newImage = "image/studentWork/student19_i.jpg";
		}
		break;
		case "student21":	{
			newTitle = "Click";
			newContent = "to view";
			newImage = "image/studentWork/student20_i.jpg";
		}
		break;
		case "student22":	{
			newTitle = "Click";
			newContent = "to view";
			newImage = "image/studentWork/student21_i.jpg";
		}
		break;
		case "student23":	{
			newTitle = "Click";
			newContent = "to view";
			newImage = "image/studentWork/student22_i.jpg";
		}
		break;
   }
   
   
   head.firstChild.nodeValue=newTitle;
   content.firstChild.nodeValue=newContent;
   $("#popupImage").attr({ 
		src: newImage
	});
}

//create popup
function popup()
{	
	largePopup = true;
	ChangeText();
	positionPopup();
	loadPopup();
	//close popup if timed out
	timer=setTimeout("disablePopup()",closeTime);
}

function formPopup(messageHead,messageBody)
{	
   	largePopup = false;
	var head = document.getElementById("popupHeading");
	var content = document.getElementById("popupContent");
	positionPopup();
	loadPopup();
	head.firstChild.nodeValue=messageHead;
   	content.firstChild.nodeValue=messageBody;
	
	$("#popupImage").attr({ 
		src: "image/popup.gif"
	});
	timer=setTimeout("disablePopup()",5000);
}


function closePopup()
{
	if(hoveringButton == false)
	{
		if(hoveringPopup == false)
		{
			clearTimeout(timer);
			disablePopup();
		}
	}
}

//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Mouseover button event!
	$(".rollOver").mouseover(function(){
		//stop timer if already started
		clearTimeout(timer);
		$("#popupImage").attr({ 
			  src: "loader.gif"
		});
		currentButton=this.id;
		
		//create popup after user hovers for a moment
		timer=setTimeout("popup()",popupTime);
		hoveringButton = false;
	});
	//Mouseoout button event!
	$(".rollOver").mouseout(function(){
		//stop timer if already started
		clearTimeout(timer);
		hoveringButton = false;
		timer=setTimeout("closePopup()",rollOutKillTime);
		//alert(document.body.scrollTop);
	});
	
	/*$("#backgroundPopup").mouseover(function(){
		hoveringPopup = true;
	});
	
	$("#backgroundPopup").mouseout(function(){
		hoveringPopup = false;
		timer=setTimeout("closePopup()",killTime);
	});*/
	
	//CLOSING POPUP

	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});
	
	
	/*$('.blogPageLinks').click(function (){
		$('#blogPage2').slideUp('fast');
		//$('#imageList li:eq('+i+')').slideDown('fast');
		Console.log('hello');
	});
	
	$('#blogPage1').slideUp('fast');*/
	
	//get mouse coordinates for popup location
	$().mousemove(function(e){
		relativeX = e.pageX;
		relativeY = e.pageY;
		positionPopup();
	});
	
	var galleries = $('.ad-gallery').adGallery();
});
