﻿/***************************/
//@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 = 10;
var xOffset = 10;
var timer;
var popupTime = 500;
var closeTime = 5000;
var killTime = 500;
var largPopup = false;
var hoveringPopup = false;
var hoveringButton = 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("fast");
		popupStatus = 1;
	}
}

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

	}
}

//moves popup to desired locatin
/*function positionPopup(){
	var xPos=relativeY+yOffset;
	var yPos=relativeX+xOffset;
	if(largPopup)
	{
		yPos = 10;
		xPos = 10;
	}
	else
	{
		yPos = relativeY+yOffset;
		xPos = relativeX+xOffset;
	}
	
	$(".popupContact").css({
		"position": "absolute",
		"top": yPos,
		"left": xPos
	});
}*/

function positionPopup(){
	
	$(".popupContact").css({
		"position": "absolute",
		"top": 450,
		"left": 550
	});
}

//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 "but1":   {
			newTitle = "Button 1";
			newContent = "Button 1's content, bla bla bla";
			newImage = "image/popup.gif";	
		}
		break;
		case "but2":	{
			newTitle = "Button 2";
			newContent = "Button 2's content, bla bla bla a dcasd as d asdasd as dasd asd asd as da sd asd asd as d asd asd as d asd asd as d asd asd asd as d asd asd asd as d asd asd as d asd ad";
			newImage = "image/popup.gif";	
		}
		break;
		case "but3":   {
			newTitle = "Button 1";
			newContent = "Button 1's content, bla bla bla";
			newImage = "image/popup.gif";	
		}
		break;
		case "but4":	{
			newTitle = "Button 2";
			newContent = "Button 2's content, bla bla bla a dcasd as d asdasd as dasd asd asd as da sd asd asd as d asd asd as d asd asd as d asd asd asd as d asd asd asd as d asd asd as d asd ad";
			newImage = "image/popup.gif";	
		}
		break;
		case "but5":   {
			newTitle = "Button 1";
			newContent = "Button 1's content, bla bla bla";
			newImage = "image/popup.gif";	
		}
		break;
		case "student1": {
			newTitle = "Student name";
			newContent = "Image name";
			newImage = "image/popup.gif";
			largPopup = true;
		}
		break;
		case "student2": {
			newTitle = "Student name";
			newContent = "Image name";
			newImage = "image/aboutconcept.png";
			largPopup = true;
		}
		break;
   }
   
   head.firstChild.nodeValue=newTitle;
   content.firstChild.nodeValue=newContent;
   $("#popupImage").attr({ 
			  src: newImage
	});   
}

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

function formPopup(messageHead,messageBody)
{
	
	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()",closeTime);
}


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

//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Mouseover button event!
	/*$(".button").mouseover(function(){

		currentButton=this.id;
		//stop timer if already started
		clearTimeout(timer);
		//create popup after user hovers fo a moment
		timer=setTimeout("popup()",popupTime);
		hoveringButton = false;
	});
	//Mouseoout button event!
	$(".button").mouseout(function(){
		hoveringButton = false;
		timer=setTimeout("closePopup()",killTime);
	});
	
	$("#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();
		}
	});*/
	
	//get mouse coordinates for popup location
	$('.blogPageLinks').click(function (){
		$('#blogPage2').slideUp('fast');
		//$('#imageList li:eq('+i+')').slideDown('fast');
		Console.log('hello');
	});
	
	$('#blogPage1').slideUp('fast');
	
	$().mousemove(function(e){
		relativeX = e.pageX;
		relativeY = e.pageY;
	});
	
	var galleries = $('.ad-gallery').adGallery();
});