/*!
 * TransmissionController JavaScript Library v1.0.0
 *
 * "Web-Anatomy" s.c. Sebastian "Bastek" Ceglarz i Szymon "Nabu" Polok
 * http://web-anatomy.com
 * Copyright 2011
 
 * Date: 08-06-2011
 */ 

var animations = false;
var firstLunch = false;

window.onload = function(){
	var getAnimstatus = readCookie("animations");
	if(getAnimstatus != null){
		setAnimStatus(getAnimstatus=="true");
	}else{
		setAnimStatus(true);
	}
	$("#animationcloud").css({ opacity: 0 });
}

function setAnimStatus(status){
	if(!document.getElementById('animImgOn')) return;
	if(status == animations && firstLunch) return;
	firstLunch = true;
	if(status){
		document.getElementById('animImgOn').src = 'images/on_active.png';
		document.getElementById('animImgOff').src = 'images/on_off_inactive.png';
	}else{
		document.getElementById('animImgOn').src = 'images/on_off_inactive.png';
		document.getElementById('animImgOff').src = 'images/off_active.png';
	}
	
	createCookie("animations", status, 2419200);
	animations = status;
}

function createCookie(name, value, seconds) {
	if (seconds) {
		var date = new Date();
		date.setTime(date.getTime()+(seconds*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

var animeTimer = false;
var animeAutoOpened = false;
function autoOpenAnimCloud(){
	if(animeAutoOpened) return;
	animeAutoOpened = true;
	openAnimCloud();
	animeTimer = setTimeout(function(){
		closeAnimCloud();
	}, 5000);
}

function closeAnimCloud(){
	$('#animationcloud').animate({
						opacity: 0
			}, 500);
	setTimeout(function(){
		document.getElementById('animationcloud').style.display = 'none';
	},500);
}

function openAnimCloud(){
	$("#animationcloud").stop(true, true);
	var code = 'Wyłączenie animacji może wpłynąć na zmniejszenie obciążenia Twojej przeglądarki';
	document.getElementById('animcloudcontent').innerHTML = code;
	document.getElementById('animationcloud').style.marginLeft = '10px';
	document.getElementById('animationcloud').style.marginTop = '-3px';
	document.getElementById('animationcloud').style.display = 'block';
		$('#animationcloud').animate({
						opacity: 1
		}, 500);
	if(animeTimer)
		clearTimeout(animeTimer);
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
