// can be used for debugging messages in several scripts
var yuna = yuna || {};
yuna.debugEnabled = true;
yuna.log = function(message, type){
    if(yuna.debugEnabled == false){
        return false;
    }
    if('console' in window && 'log' in window.console){
        console.log(message);
    }
    return true;
}

$(document).ready(function(){
	/**
	* lightbox
	*/
	$('a[rel=lightbox]').lightBox();

/*
	var $img = $("dl dt img");
	$img.each(function(){
		imgHeight = this.height;
		imgWidth = this.width;
		htmlBefore = '<div class="corners3" style="width:'+imgWidth+'px; height:'+imgHeight+'px; display: inline; margin: 0px; padding: 0px; background: red;"><img src="'+this.src+'" /></div>';
//		htmlBefore = '<div class="corners3" style="width:'+imgWidth+'px; height:'+imgHeight+'px; display: inline; background: red;">hello</div>';
		$(htmlBefore).insertBefore(this);
//		$('</div>').insertAfter(this);
	});
*/

	/**
	* rounded corners
	*/
	$(".corners").corner("8px");
    $(".corners4").corner("4px");
    $(".corners3").corner("3px");
	$(".corners2").corner("2px");
	$("input.submit").corner("4px");
	$(".BTN a").corner("4px");
	$(".formContainer form").corner("8px");
	$(".searchForm form").corner("8px");
//	$("dl dt img").corner("3px");


	/*toolTip*/
	$('a.toolTip').tooltip({
		track: true,
		delay: 0,
		showURL: false,
		showBody: " - ",
		fade: 250,
		opacity: 50
	});


	/*homepage teaser*/
	$('.cycleContainer').cycle({
		fx: 'fade'
	});



	$('.jobImgCarousel').cycle({
//		fx: 'fade'
	});

	/**
	* Search field
	*/
	var $field = $('#searchfield');
	$field.data("initValue",$field.val());
	$field.bind('focus',{},function(e) {
		if($(this).val() == $(this).data("initValue")) {
			$(this).val('');
		}
	});

	$field.bind('blur',{},function(e){
		if($(this).val() == $(this).data("initValue") || $(this).val()=='') {
			$(this).val($(this).data("initValue"));
		}
	});
	$field.parent().bind('submit', {}, function(e) {
		if($field.val() == $field.data("initValue")) {
			$field.val('');
		}
		return true;
	});

	/*
	 * Project drop down menu
	 */
	var toggleProjectDisplay = function(e){
		$('div.hiddenProjects').toggle();
		/*var $link = $($('a.showMoreProjects', e.currentTarget)[0]);
		var data = $link.attr('data');
		$link.attr('data', $link.html());
		$link.html(data);
		if($link.hasClass('projectsShown')){
			$link.removeClass('projectsShown');
		}else{
			$link.addClass('projectsShown');
		}*/
	}
	var projectsVisible = false;
	$('div.showMoreProjects').live('mouseover', function(e){
		if(projectsVisible == false){
			projectsVisible = true;
			$('div.hiddenProjects').css('display', 'block');
			//toggleProjectDisplay(e);
		}
		return false;
	});
	$('div.showMoreProjects').live('mouseout', function(e){
		if(projectsVisible == true){
			projectsVisible = false;
			$('div.hiddenProjects').css('display', 'none');
			//toggleProjectDisplay(e);
		}
		return false;
	});


	/**
	 * Track download button clicks
	 */
	$('.trackDownload').bind('click', function(e) {
		value = $(this).attr('title');
		_gaq.push(['yuna._trackEvent', 'Download', 'click', value, 0]);
	});


	$('.backNav a.btnBack').click(function(e){
		setCookie('hitBackButton', '1', 1);
		history.go(-1);
		return false;
	});
	
	
	$('#refreshCaptcha').live('click', function(e){
		var $captchaImg = $(this).prev('img');
		var newHref = $captchaImg.attr('src') + Math.round(Math.random() * 1000);
		$captchaImg.attr('src', newHref);
		return false;
	});
	
	setTimeout("setCookie('hitBackButton', '0', 1);", 1000);

});

	// loading Google analytics
(function() {
	var ga = document.createElement('script');ga.type = 'text/javascript';ga.async = true;
	ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
	var s = document.getElementsByTagName('script')[0];s.parentNode.insertBefore(ga, s);
})();

var _gaq = _gaq || [];
_gaq.push(['yuna._setAccount', 'UA-1339331-20']);
_gaq.push(['yuna._trackPageview']);



function setCookie(name, value, exdays){
	var exdate = new Date();
	exdate.setDate(exdate.getDate() + exdays);
	value = escape(value) + ((exdays==null) ? "" : "; expires=" + exdate.toUTCString()) + '; path=/';
	document.cookie = name + "=" + value;
}

function getCookie(name){
	var cookies = document.cookie.split(";");
	for(var i=0; i < cookies.length; i++){
		var label = cookies[i].substr(0, cookies[i].indexOf("="));
		var value = cookies[i].substr(cookies[i].indexOf("=")+1);
		label = label.replace(/^\s+|\s+$/g,"");
		if(label == name){
			return unescape(value);
		}
	}
	return null;
}
