//*********************************************
// Cookies class
//*********************************************

var Cookie = {
	// Days: 0 - trashed when the closes browser. -1 - trashed immediately.
	// escape for save space and ';' characters also
	CreateCookie: function (name,value,days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+escape(value)+expires+"; Path=/"; //+";domain=" + CookieDomain;
	},

	get: function (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 unescape(c.substring(nameEQ.length,c.length));
		}
		return null;
	},

	set: function (name, value) {
		this.CreateCookie(name,value,365);
	},

	del: function (name) {
		this.CreateCookie(name,"",-1);
	},

	getAll: function() {
		return unescape(document.cookie.substring(0, document.cookie.length));
	}

}

//*********************************************
// localStorage
//*********************************************

// check supports html5 localStorage
function isLocalStorage() {
	try {
		return !! localStorage.getItem
	} catch(a) {
		return ! 1
	}
}

var localStor = {

	get: function (key) {
		if (isLocalStorage()) {
			return localStorage.getItem(key);
		} else {
			return '';
		}
	},

	set: function (key, value) {
		if (isLocalStorage()) {
			localStorage.setItem(key, value);
			return true;
		} else {
			return false;
		}
	},

	del: function (key) {
		if (isLocalStorage()) {
			localStorage.removeItem(key);
			return true;
		} else {
			return false;
		}
	},

	clear: function (key) {
		if (isLocalStorage()) {
			localStorage.clear();
			return true;
		} else {
			return false;
		}
	},

	getAll: function() {
		if (isLocalStorage()) {
			var key;
			var s = '';
			for (var i=0; i<=localStorage.length-1; i++) {
				key = localStorage.key(i);
				s = s + key + '=' + localStorage.getItem(key) + '\n';
			}
			return s;
		} else {
			return '';
		}
	}

}

//*********************************************
// utils function
//*********************************************

// ReplaceString
function ReplaceString(origString, inChar, outChar) {
	var newString = origString.split(inChar);
	newString = newString.join(outChar);
	return newString;
}

// number version IE browser. if(GetVersionIE()!=0) { no IE }
function GetVersionIE(){
	var IE=v=false,n;try{n=navigator.appVersion;IE=(n.indexOf('MSIE')!=-1)}catch(e){}
  if(IE)v=n.substr(n.indexOf('MSIE')+5,1);
	v= parseInt(v);
  if (isNaN(v)) { return 0; } else { return v; }
}

function SetInnerHTML(id, s) {
	var elem = document.getElementById(id);
	if (elem != null) {
		elem.innerHTML = s;
	}
}

function GetInnerHTML(id) {
	var elem = document.getElementById(id);
	if (elem != null) {
		return elem.innerHTML;
	}
}

// Actual Y Scroll position page-body in browser window
function getScrollY() {
	var scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		scrOfY = window.pageYOffset;
	} else if( document.body && ( document.body.scrollTop ) ) {
		scrOfY = document.body.scrollTop;
	} else if( document.documentElement && ( document.documentElement.scrollTop ) ) {
		scrOfY = document.documentElement.scrollTop;
	}
	return scrOfY;
}

//*********************************************
// Other for page
//*********************************************

// Blink color
function FlashColor(id, kolor, czas, kolor2, czas2) {
	document.getElementById(id).style.color = kolor;
	setTimeout('FlashColor("' + id + '","' + kolor2 + '",' + czas2 + ',"' + kolor + '",' + czas + ')', czas);
}

// Do Blink color
function DoFlashColor(id, kolor, czas, kolor2, czas2) {
	var elem = document.getElementById(id);
	if (elem == null) { return 0; }
	FlashColor(id, kolor, czas, kolor2, czas2);
}

//*********************************************
// Sound
//*********************************************

var Played = false;
var SoundPlay = 'SoundPlay';

// Write flash move to id
function PlaySound() {
	if (Played || !PageLoaded) return false;
	if (Cookie.get(SoundPlay) == "0") { return false }
	var so = new SWFObject("swf/birds.swf", "birds", "4", "4", "5", "#008000");
	so.addParam("quality", "low");
	so.addParam("wmode", "transparent");
	//so.addParam("salign", "t");
	so.addVariable("VarPlay", "1");
	so.write("flash_birds");
	Played = true;
}

function StopSound() {
	document.getElementById('flash_birds').innerHTML = "";
	Played = false;
}

function ToggleSound() {
	if (!PageLoaded) return false;
	if (Cookie.get(SoundPlay) == "0") {
		Cookie.set(SoundPlay, '1');
		Played = false;
		PlaySound();
	}
	else {
		Cookie.set(SoundPlay, '0');
		StopSound();
	}
}

//*********************************************
// Flash
//*********************************************

function WriteTitleSfw() {
	var so = new SWFObject("swf/title.swf", "titleswf", "942", "202", "5", "#000000");
	so.addParam("quality", "high");
	so.addParam("wmode", "transparent");
	so.write("block_title");
}

//*********************************************
// OnLoad Body
//*********************************************

var PageLoaded = false;

// *** DoOnLoad ***
function DoOnLoad() {
	PageLoaded = true;
	// Blink color
	DoFlashColor('flash', '#006600', 1000, '#00A800', 500);
	// Play Birds
	PlaySound();
	// Flash baner on header top
	if (document.getElementById('galleryid')== null) { WriteTitleSfw() }
}

