var slideSpeed = 600;
var timeOut = 1500;
var timeOut2 = 1500;
var closeTimer = 0;
var currentLinks = 0;
var closeTimer2 = 0;
var currentLinks2 = 0;
var count = 1;
var slides = new Array("img1", "img2", "img3", "img4");
var currentParent = 0;
var currentSubParent = 0;


//-------------------------------------------------------------------------------------------------------
//------------------------------------------------ LINKS ------------------------------------------------
//-------------------------------------------------------------------------------------------------------

// open links
function openLinks(id, parent)
{		
	// cancel close timer
	cancelCloseTimer();

	// close old layer
	if(currentLinks != document.getElementById(id)){
		if(currentLinks) 
			closeLinks();
	
	
		// get new layer and show it
		currentLinks = document.getElementById(id);
		currentLinks.style.visibility = 'visible';
		$(currentLinks).slideDown(slideSpeed);

	$(document.getElementById(currentParent)).css("filter","alpha(opacity=100)");
	$(document.getElementById(currentParent)).css("-moz-opacity","1.0");
	$(document.getElementById(currentParent)).css("opacity","1.0");
    	$(document.getElementById(currentParent)).css("-khtml-opacity","1.0"); 
    	
	$(document.getElementById(parent)).css("filter","alpha(opacity=50)");
	$(document.getElementById(parent)).css("-moz-opacity","0.5");
	$(document.getElementById(parent)).css("opacity","0.5");
    	$(document.getElementById(parent)).css("-khtml-opacity","0.5"); 
	currentParent = parent;
	}

}

// open links
function openSecondLinks(id, parent)
{	

	// cancel close timer
	cancelCloseTimer2();
	if(currentLinks2 != document.getElementById(id)){
		if(currentLinks2) 
		closeLinks2();
		
	// get new layer and show it
	currentLinks2 = document.getElementById(id);
	currentLinks2.style.visibility = 'visible';
	//$(currentLinks2).slideDown(slideSpeed);
	$(currentLinks2).animate({width: 'show'}, slideSpeed);
	}
	
	$(document.getElementById(currentSubParent)).css("filter","alpha(opacity=100)");
	$(document.getElementById(currentSubParent)).css("-moz-opacity","1.0");
	$(document.getElementById(currentSubParent)).css("opacity","1.0");
	$(document.getElementById(currentSubParent)).css("-khtml-opacity","1.0"); 
	    	
	$(document.getElementById(parent)).css("filter","alpha(opacity=50)");
	$(document.getElementById(parent)).css("-moz-opacity","0.5");
	$(document.getElementById(parent)).css("opacity","0.5");
	$(document.getElementById(parent)).css("-khtml-opacity","0.5"); 
	currentSubParent = parent;

}

// close links
function closeLinks()
{
	if(currentLinks2){
		currentLinks2.style.visibility = 'hidden';
		//$(currentLinks2).stop(true,true).slideUp();
		$(currentLinks2).stop(true,true).animate({width: 'hide'});
		currentLinks2=0;
		
		$(document.getElementById(currentSubParent)).css("filter","alpha(opacity=100)");
		$(document.getElementById(currentSubParent)).css("-moz-opacity","1.0");
		$(document.getElementById(currentSubParent)).css("opacity","1.0");
		$(document.getElementById(currentSubParent)).css("-khtml-opacity","1.0");
		currentSubParent = 0;
		
			
	}
	if(currentLinks){
		currentLinks.style.visibility = 'hidden';
		$(currentLinks).stop(true,true).slideUp();
		currentLinks=0;
		$(document.getElementById(currentParent)).css("filter","alpha(opacity=100)");
		$(document.getElementById(currentParent)).css("-moz-opacity","1.0");
		$(document.getElementById(currentParent)).css("opacity","1.0");
		$(document.getElementById(currentParent)).css("-khtml-opacity","1.0");
		currentParent = 0;
	}
}

// close links
function closeLinks2()
{
	if(currentLinks2){
		currentLinks2.style.visibility = 'hidden';
		//$(currentLinks2).stop(true,true).slideUp();
		$(currentLinks2).stop(true,true).animate({width: 'hide'});
		currentLinks2=0;
		$(document.getElementById(currentSubParent)).css("filter","alpha(opacity=100)");
		$(document.getElementById(currentSubParent)).css("-moz-opacity","1.0");
		$(document.getElementById(currentSubParent)).css("opacity","1.0");
		$(document.getElementById(currentSubParent)).css("-khtml-opacity","1.0");
		currentSubParent = 0;
	}
}


// set closeTimer
function setCloseTimer()
{
	closeTimer = window.setTimeout(closeLinks, timeOut);
}

// cancel closeTimer
function cancelCloseTimer()
{
	if(closeTimer)
	{
		window.clearTimeout(closeTimer);
		closeTimer = null;
	}
}


// set closeTimer
function setCloseTimer2()
{
	closeTimer2 = window.setTimeout(closeLinks2, timeOut);
}

// cancel closeTimer
function cancelCloseTimer2()
{
	if(closeTimer2)
	{
		window.clearTimeout(closeTimer2);
		closeTimer2 = null;
	}
}


// run after page has loaded
function closeOnLoad(){
	var $drop = $(".drop2");
	$drop.slideUp(0);
	var $e = $(".drop1");
	$e.slideUp(0);
	var $slidingContent = $(".slidingContent");
	$slidingContent.slideUp(0);
}

// close links on-click
document.onclick = closeLinks;


//-------------------------------------------------------------------------------------------------------
//---------------------------------------------- CONTENT ------------------------------------------------
//-------------------------------------------------------------------------------------------------------

function openContent(num)
{		

	//var $slidingContent = $(".slidingContent");
	//$slidingContent.slideUp();
	
	var id = "dropDiv" + num;
	var arrowId = "dropArrow" + num;
	// get new layer and show it
	var content = document.getElementById(id);
	var arrow = document.getElementById(arrowId);
	//$(content).slideDown();

	if ($(content).is(":hidden")) {
		$(content).slideDown();
		arrow.src="img/upArrow.png";
	} else {
		$(content).slideUp();
		arrow.src="img/downArrow.png";
	}
	
	websiteHeight();

}


function closeContent(id)
{
		var content = document.getElementById(id);
		$(content).stop(true,true).slideUp();
}

function websiteHeight() {
	$("#website").css("height", "100%");
}

//-------------------------------------------------------------------------------------------------------
//----------------------------------------------- POPUP ------------------------------------------------
//-------------------------------------------------------------------------------------------------------
			
function toggle(ele) {
	var ele = document.getElementById(ele);
	var $allPopup = $(".popup");
	$allPopup.hide();
	ele.style.display = "block";
	document.getElementById("popupBackground").style.display = "block";
	centerPopup(ele);
}

function closeAll() {
	var $allPopup = $(".popup");
	$allPopup.hide();
	document.getElementById("popupBackground").style.display = "none";
}

function centerPopup(ele)	{

	//var popMaxHeight = $(window).height()-100;
	//var popMaxWidth = $(window).width()-100;
			
	//$(ele).css("max-height", popMaxHeight + "px");
	//$(ele).css("max-width", popMaxWidth + "px");
	
	var wWidth = document.documentElement.clientWidth;	
	var wHeight = document.documentElement.clientHeight;

	var pWidth = $(ele).width();	
	var pHeight = $(ele).height();		
	
	$("div.popup").css(		
	{				
		"top": wHeight/2-pHeight/2,	
		"left": wWidth/2-pWidth/2		
	});
}

//-------------------------------------------------------------------------------------------------------
//------------------------------------------------ CLOCK ------------------------------------------------
//-------------------------------------------------------------------------------------------------------
function startClock() {
	var today = new Date();
	var hours = today.getHours();
	var min = today.getMinutes();
	var sec = today.getSeconds();
	var gmt = -today.getTimezoneOffset()/60;
	
	if(gmt > 0)
		gmt = "+" + gmt;
	if(gmt == 0)
		gmt = "";
	
	hours = checkDigits(hours);
	min = checkDigits(min);
	sec = checkDigits(sec);
	
	var day = today.getDate();
	var month = today.getMonth();
	var year = today.getFullYear();
	
	var months = new Array(12);
	months[0]="January";
	months[1]="February";
	months[2]="March";
	months[3]="April";
	months[4]="May";
	months[5]="June";
	months[6]="July";
	months[7]="August";
	months[8]="September";
	months[9]="October";
	months[10]="November";
	months[11]="December";
 
 
	
	document.getElementById("bannerTime").innerHTML = day + " " + months[month] + " " + year + "<br />" +  hours + ":" + min + ":" + sec + " (GMT" + gmt + ")";
	t = setTimeout('startClock()',1000);
	
}

function checkDigits(n) {
	if(n<10){
		var n = "0" + n;
		return n;
	}
	
	return n;
}


//-------------------------------------------------------------------------------------------------------
//----------------------------------------------- BANNER ------------------------------------------------
//-------------------------------------------------------------------------------------------------------


function banner() {
	var $slides = $("#header img");
	
	var $element = $slides.get(count%$slides.length);
	var $nextElement = $slides.get((count+1)%$slides.length);
	var $prevElement = $slides.get((count-1)%$slides.length);
	
	var elementId = document.getElementById($element.id);		
	var nextElementId = document.getElementById($nextElement.id);
	var prevElementId = document.getElementById($prevElement.id);

	$(elementId).animate({right: "0px"}, 500);	
	$(prevElementId).animate({right: "950px"}, 500);
	$(nextElementId).css("right", "-950px");
	
	//$(prevElementId).fadeOut(500);
	//$(elementId).fadeIn(500);
	
	count = count + 1;
}

$(window).load(function() {
	closeOnLoad();
	var popMaxHeight = $(window).height()-100;
	var popMaxWidth = $(window).width()-100;
	$(".popup .popupContent").css("max-height", popMaxHeight + "px");
	$(".popup .popupContent").css("max-width", popMaxWidth + "px");
	$(document.getElementById(slides[0])).css("right", "0px");
	setInterval( "banner()", 5000 );
	startClock();
	//$('.content').draggable({ containment: 'parent' });
});
