// JavaScript Document

$(function(){

	Cufon.replace('.cufontext', { fontFamily: 'Stag Semibold' });
	Cufon.replace('.cufontextBook', { fontFamily: 'Stag Book' });
	Cufon.replace('.cufontextBold', { fontFamily: 'Stag Bold' });
	Cufon.now();

	$('#selectPortfolio').change(function(){  window.location = $('#selectPortfolio').val(); });
	
	//set our session timeout in seconds
	var session = 20;
	
	
	//if we dont have a cookie to hide
	if($.cookie("propaganda") != "no-show")
	{
		//if the timer cookie is at zero they must have had the popup this session.
		if($.cookie("propaganda-to") == "timed out")
		{
			//alert('already had popup');
		}else{
			if($.cookie("propaganda-to") > 0){
				//alert('session already started (' + $.cookie("propaganda-to") + 'secs left) ');
			}else{
				//alert('new session start timer (' + session + 'secs)');
				$.cookie("propaganda-to", session);
			}

			//start the session and timer
			var timer = setInterval(function() {
				counter();
			}, 1000);
		}
	}else{
		/*alert('no show cookie');
		$.cookie("propaganda",null);
		$.cookie("propaganda-to",null);
		*/
	}
	
	showPopup = function(){
		$("#transform-popup").animate(
			{top:'0px'},
			{queue:false, duration:1000, easing:'swing'}
		);
	}
	
	hidePopup = function(){
		$("#transform-popup").animate(
			{top:'-400px'},
			{queue:false, duration:1000, easing:'swing'}
		);
	}
	
	$("a.close-link").click(function() {
		$.cookie("propaganda", "no-show", { expires: 365 });
		hidePopup();
	});
	
	counter = function(){
		var secs = $.cookie("propaganda-to");
		secs = secs-1;
		
		if(secs == 0)
		{
			clearInterval(timer);
			$.cookie("propaganda-to", 'timed out');
			showPopup();
		}else{
			$.cookie("propaganda-to", secs);
		}
	}
	
});
