// JavaScript Document

$(function(){
		decorateHouse();
});
	
function clickclear(thisfield, defaulttext) 
{
	if (thisfield.value == defaulttext) 
	{
		thisfield.value = "";
	}
}

function clickrecall(thisfield, defaulttext) 
{
	if (thisfield.value == "") {
		thisfield.value = defaulttext;
	}
}


function decorateHouse() {
	
$("#page-wrapper")
		.animate({backgroundColor: '#fe9627'}, 5000)
		.animate({backgroundColor: '#FDC501'}, 5000)
		.animate({backgroundColor: '#5C9E5D'}, 5000)
		.animate({backgroundColor: '#409FA7'}, 5000)
		.animate({backgroundColor: '#662483'}, 5000)
		.animate({backgroundColor: '#ff2881'}, 5000);

$(".lnkcolor")
		.animate({color: '#fe9627'}, 5000)
		.animate({color: '#FDC501'}, 5000)
		.animate({color: '#5C9E5D'}, 5000)
		.animate({color: '#409FA7'}, 5000)
		.animate({color: '#662483'}, 5000)
		.animate({color: '#ff2881'}, 5000, function(){decorateHouse()});


}




function wordScramble()
{

	$.ajax({
	  url: '_wordCloud.asp',
	  success: function( data ) {
		setContent('#buzz',data)
		setTimeout("wordScramble()",2000)
	  }
	});

}


function setContent(obj,value)
{
	//$(obj).text(value);
	$(obj).html(value)
}

$(function () {
 
  $('#welcome-pnl').bind('inview', function (event, visible) {
	if (visible) {
	
		switchClass('#utility-nav li','');
		switchClass('#mopt1','active');
		
	}
  });
});


function overlayOpen() {
	showElement('#overlay')
}

function overlayClose() {
	hideElement('#overlay')
	hideElement('.popup')
	
	/* Stop YouTube videos from playing in the background */
	$('#ytembed').attr('src', 'null');
	
}


function hideElement(obj)
{
	$(obj).css('display', 'none');
}

// Shows the desired element
function showElement(obj)
{
	$(obj).css('display', 'block');

}

var projectLink;
var projectData;
var currentIndex;

function showProject()
{
	

	hideElement('.popup #loader')
	showElement('.popup #project')	
	setContent('#project',projectData)
	
	if(projectData.length ==0){
		showElement('#punable');
	}
	
	updateNavigation();
}

function resetEnvironment()
{
	hideElement('.popup #project')
	showElement('.popup #loader')
	hideElement('#punable');
}

function updateNavigation()
{
	if((currentIndex - 1) == 0){
		hideElement('.left-nav')
	}	
	if((currentIndex + 1) > (houseWork.length - 1)){
		hideElement('.right-nav')
	}
}

function goToProject(projIndex)
{
	
	resetEnvironment()
	overlayOpen()
	
	showElement('.popup')
	
	$.ajax({
	  url: '_getProjectLink.asp?id=' + houseWork[projIndex] + '&callID=' + Math.random(),
	  success: function( data ) {
		
		projectReference = data
				
		$.ajax({
		  url: 'projects/contentBuilder.asp?reference=' + projectReference + '&callID=' + Math.random(),
		  success: function( data )
		  {
			projectData = data;
			currentIndex = projIndex;
			setTimeout("showProject()",500) 
		  }
		})
				
	  }
	});
	
}

function goToProjectBak(projIndex)
{
	
	resetEnvironment()
	overlayOpen()
	
	showElement('.popup')
	
	$.ajax({
	  url: '_getProjectLink.asp?id=' + houseWork[projIndex] + '&callID=' + Math.random(),
	  success: function( data ) {
		  
		  
		projectLink = data
		
		//alert(projectLink);
		
		$.ajax({
		  url: projectLink + '?callID=' + Math.random(),
		  success: function( data )
		  {
			projectData = data;
			currentIndex = projIndex;
			setTimeout("showProject()",500) 
		  }
		})
				
	  }
	});
	
}

function viewProject(showIndex)
{
				
	var y = $("#project_" + showIndex).offset().top;
	//alert(y);
	
	$('.popup').css('top', y);
	
	goToProject(showIndex);

		
}

function nextProject()
{
	
	goToProject(currentIndex + 1);

}

function previousProject()
{
	goToProject(currentIndex - 1);
}


function switchClass(obj,className)
{
	$(obj).attr('class', className);
}

function scrollToSection(pnlID, linkID)
{	
	switchClass('#utility-nav li','');
	switchClass(linkID,'active');
	$.scrollTo(pnlID, 800,{offset:-70} );
}


$(document).ready(function(){

		//insert contact pop-up controls
		$("#overlay").click(function(){overlayClose();});
		//wordScramble();
		
});

function enquireSuccess()
{
	
	//$.scrollTo('#contact-cnt', 0,{offset:-110} );
	
	showElement('.enquire-response');
	hideElement('.welcome-response');
	
	//setTimeout("scrollToSection('#welcome-pnl','#mopt1')",500) 
	
	
}

function toggleLogin()
{
	
	if($("#gh-popup").css("display") == 'none')
	{
		$("#gh-popup").css("display","block");
	}
	else
	{
		$("#gh-popup").css("display","none");	
	}
		
}
