/* Add function(s) to specific handlers - START */
$(document).ready(function(){

	/* Round corners */
	$('ul#nav a').nifty("small transparent top");
	// User box
	$('div.columnfilledfr').nifty("small");
	$('div.columnfilledfr div').nifty("small");
	// Info box
	$('div.menurollover').nifty("bottom");
	// Search box
	$('div.columnsearch div').nifty("bottom");
	// Categories
	$('div.columnfilled').nifty("");

	/* Info Pages menu */
	function addHoverHide(sToggler, sLayer) { 
		var t; 
		$(sLayer).hide();
		$(sToggler).hover(function() { 
			clearTimeout(t);
			$(sLayer).show('normal');
		}, function() { 
			t = setTimeout(function() {	$(sLayer).hide('normal'); }, 2000); 
		}); 
		$(sLayer).hover(function() { 
			clearTimeout(t) 
		}, function() { 
			t = setTimeout(function() {	$(sLayer).hide('normal'); }, 2000); 
		}); 
	} 
	addHoverHide("#btn_infopages", 'div.menurollover'); 


	/* Menu */
	jQuery('#categories').accordion({     
		active: false, 
		alwaysOpen: false,
		navigation: true, 
		autoheight: false,
		header: '.toggler',     
		selectedClass: 'selected'
	});

	/* Read more - Expander */
	$('#content_center div.expandable').expander({
		slicePoint: 200, 
		widow: 10,
		expandEffect: 'show',
		expandText: '>>',
		userCollapse: true,
		userCollapseText: '<<'
	});
	
	


	/* Hiding loader */
	if($('contentContainer')) {		
		$('#contentContainer').css('visibility', 'visible');
	}
	$('#content_left').css('display', 'block');
	$('#contentLoader').css('visibility', 'hidden');

	/* Search autocomplete */
	$("#keyword").autocomplete('searchsuggest.php', {
		width: $('#content_left').width() - 34 ,
		offsettop: 3,
		offsetleft: -16
	});
	
	/* Equal all news boxes */
	if($('homeNews')) {		
		height = 0;
		newsItems = $('.homeNews .newsItem');
		if( newsItems.length ) {
			newsItems.each(function(){ if(height < $(this).height()) {height = $(this).height();} });  
			newsItems.each(function(){ 
				$(this).css("height", (height + 10) + 'px');
//				$(this).css("border", '1px solid #DDD');
			});  
		}
	}

	/* set screen height */
/*
	if( $(window).height() > $('#contentinner').height() ) 
	{
		$('#contentSpacer').css('height', $(window).height() - $('#contentinner').height() + 20);
	}

	if( $('#contentinner').height() > $('#content_right').height() ) 
	{
		$('#content_right').css('height', $('#contentinner').height() - 500);
	}
*/	

});


/* Open new windows */
function popupImage(url, title)
{
	var width = 400;
	var height = 400;

	var idChars =
	    "abcdefghijklmnopqurstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	var id = "";
	var s = escape(url);
	
	for (var c = 0; c < s.length; c++) {
		var ch = s.charAt(c);
		if (idChars.indexOf(ch) >= 0) {
			id += ch;
		}
	}
	var w = window.open('', id,
		     "toolbar=0,location=0,statusbar=0,menubar=0,scrollbars=1,width="
		     + (width+40) + ",height=" + height);
	w.document.write("<html><head><title>"+title+"</title></head>");
	w.document.write("<body><img width='"+width+"' src='"+url+"'></body></html>");
}
function NewWindow(mypage,myname,w,h,scroll){
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  var settings  ='height='+h+',';
      settings +='width='+w+',';
      settings +='top='+wint+',';
      settings +='left='+winl+',';
      settings +='scrollbars='+scroll+',';
      settings +='resizable=yes';
  win=window.open(''+mypage+'',myname,settings);
  if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}

/* Layer FUNCTIONS */
function invLayer(ids)
{
	var myArray = ids.split(',');
	for(i=0;i<myArray.length;i++) {
		$(myArray[i]).toggle();
	}
}


/* COOKIE FUNCTIONS */
function createCookie(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+"="+value+expires+"; path=/";
}
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;
}
function eraseCookie(name) {
	createCookie(name,"",-1);
} 