

//*********
//VARIABLES
//*********

var currentJobsDD;
var currentJobsDLID;
var jobsBlockAnimated;
var jobsBlockInterval;




//*******
//METHODS
//*******

function init() {
	setFonts();
}


// set Cufon fonts
function setFonts() {
	Cufon.replace('h1');
	Cufon.replace('h2');
	Cufon.replace('h3');
	Cufon.replace('button', {textShadow: '-1px -1px 1px #ad5709'});
	Cufon.replace('a.button', {textShadow: '-1px -1px 1px #ad5709'});
	Cufon.replace('div.mainmenu ul li a', {hover: true});
	Cufon.replace('div.sidemenu ul li a', {hover: true});
}


// sets jobs list
function setJobsList() {
	$('div.jobs dl button').each(function (index) {
		var list = $(this).parent().parent();
		var id = "jobDL" + index;
		$(list).attr('id', id);
		$(this).click(function () {
			if (jobsBlockAnimated) {
				return false;
			}
			var list = $(this).parent().parent();
			var dd = $(list).children('dd');
			if ($(list).attr('id') == currentJobsDLID) {
				toggleJobsBlock(dd);
				currentJobsDD = null;
			}else{
				if (currentJobsDD) {
					toggleJobsBlock(currentJobsDD);
				}
				$(dd).animate({'height': 'show'}, 'fast');
				currentJobsDLID = $(list).attr('id');
				currentJobsDD = dd;
			}
			jobsBlockAnimated = true;
			jobsBlockInterval = setInterval(onJobsIntervalTick, 440);
		});
	});
}

// animates job blog
function toggleJobsBlock(block) {
	if ($(block).is(':visible')) {
		$(block).animate({'height': 'hide'}, 'fast');
	}else{
		$(block).animate({'height': 'show'}, 'fast');
	}
}

// 
function onJobsIntervalTick() {
	jobsBlockAnimated = false;
	clearInterval(jobsBlockInterval);
}




$(document).ready(function () {
	
	init();

	if (('ontouchstart' in document.documentElement)) {
	  var bannerButtonTouchendhandler = function () {
	    $('a.banner-button').removeClass('active');
	    $(document).unbind('touchend', bannerButtonTouchendhandler);
	  };
	  $('a.banner-button').bind('touchstart', function () {
	    $(this).addClass('active');
	    $(document).bind('touchend', bannerButtonTouchendhandler);
	  });
	}
});
