$(document).ready(function(){	
	bind_hover ();
	bind_bubble ();
	bind_scrollable ();
	bind_skin ();
	bind_contact ();
	//bind_grayscale ();
});

function bind_hover ()
{
	$("#main-navi li").hover(
		function() {
			$(this).addClass("sfhover");
		},
		function() {
			$(this).removeClass("sfhover");
		}
	);
}

function bind_bubble ()
{
	$("#bubble").addClass("noscreen");

	$("#portret").hover(
		function() {
			$("#bubble").removeClass("noscreen");
			$("#corner").addClass("z-top");
		},
		function() {

		}
	);
	
	$("#corner").hover(
		function() {

		},
		function() {
			$("#bubble").addClass("noscreen");
			$("#corner").removeClass("z-top");
		}
	);
}

function bind_scrollable ()
{
	// main vertical scroll
	$("#main").scrollable({
	
		// basic settings
		vertical: true,
		size: 1,
		clickable: false,
	
		// up/down keys will always control this scrollable
		keyboard: 'static',
	
		// assign left/right keys to the actively viewed scrollable
		onSeek: function(event, i) {
			horizontal.scrollable(i).focus();
		}
	
	// main navigator (thumbnail images)
	}).navigator("#main-navi");
	// horizontal scrollables. each one is circular and has its own navigator instance
	var horizontal = $(".scrollable").scrollable({size: 1}).circular().navigator(".navi");
	// when page loads setup keyboard focus on the first horzontal scrollable
	horizontal.eq(0).scrollable().focus();	
}

/* SKIN */
var today = new Date();
var expire = new Date();

function getCookie(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;
}

function setCookie(name, value) {
	expire.setTime(today.getTime() + 3600000*24*1000);
	document.cookie = name+"="+escape(value)+";expires="+expire.toGMTString()+"; path=/";
}

function switchstyle1 () {
	var peno = getCookie ('peno');
	//setCookie ('peno', peno == '1'?'2':'1');
	setCookie ('peno', '1');
	document.location.replace (document.location);
}

function switchstyle2 () {
	var peno = getCookie ('peno');
	setCookie ('peno', '2');
	document.location.replace (document.location);
}

function switchstyle3 () {
	var peno = getCookie ('peno');
	setCookie ('peno', '3');
	document.location.replace (document.location);
}
		
function bind_skin ()
{
	var style = getCookie('peno');
	if (style != '1' && style != '2' && style != '3') setCookie ('peno','1');
	$("link[title='theme']").attr('href', 'css/skin0'+getCookie('peno')+'.css');
}

function bind_contact ()
{
	$("#contact span").text("");
	$("#contact span").append("&#112;e&#116;r."/* spambot @ retarder */).append("n&#111;h&#101;j&#108;"/* spambot @ retarder */);
	$("#contact span").append(/* spambot retarder */'&#64;'/* spambot retarder */);
	$("#contact span").append(/* spambot retarder */'&#103;m&#97;i&#108;'/* spambot retarder */).append(/* spambot retarder */"&#46;c&#111;m");
}

function bind_grayscale ()
{
	//grayscale( $('.page td img') );
	
	$('.page td img').each(function(index) {
	    grayscale( $(this) );
	});
	
	$(".page td img").hover(
		function() {
			grayscale.reset( $(this) );
		},
		function() {
			grayscale( $(this) );
		}
	);
}
