$(document).ready(function() {
align_menu();
/*$('.gallery .images_holder a').colorbox();
$('.colorbox').colorbox();
$('.gallery .read_content').colorbox({width:'720px', inline:true, href:"#content_text"});
*/

$("a[rel=galleri_grupp]").fancybox({
	'transitionIn'		: 'elastic',
    'transitionOut'		: 'none',
    'titlePosition' 	: 'outside',
    'overlayColor'		: '#000',
    'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
    	return '<span id="fancybox-title-outside">Bild ' + (currentIndex + 1) + ' av ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
    }
});

var menu_hidden = false;
var menu_height = 220;

$(document).mousemove(function(e){
if(e.pageY < menu_height && menu_hidden && readCookie('showMenu')=='false'){
	show_menu();
}else if(e.pageY >= menu_height+160 && !menu_hidden && readCookie('showMenu')=='false'){
	hide_menu();
}
});

if(readCookie('showMenu')=='false'){
$('#show_menu').removeAttr( 'checked' );
}

$('#show_menu').click(function(){
if(readCookie('showMenu')=='true'){
createCookie('showMenu',false,7);
}else{
createCookie('showMenu',true,7);
}
});





$('#twitter_search').twitterSearch({ 
    term:   'Blankforte', 
    title: ' ',
    animOut: { opacity: 0 }, 
    avatar:  false, 
    anchors: true, 
    bird:    false, 
    colorExterior: '#fcfcfc', 
    colorInterior: '#fcfcfc', 
    pause:   true, 
    time:    true, 
    timeout: 30000,
});


function align_menu(){
$('#menu ul').each(function(i){
	var liC = $(this).children().size();
	var liH = $('#menu ul li a').height();
	var padding = ($(this).height()-liC*liH+32)/2;
	$(this).css({"padding-top": padding, "height" : $(this).height()+32-padding});
})
}


//Visa och göm menyn

function show_menu(){
menu_hidden = false;
$('#menu h5').stop().animate({'opacity' : '1'},400);
$('#menu').stop().animate({'height' : '200px'},600);
$('#menuBg').stop().animate({'height' : '200px'},600);
};

function hide_menu(){
menu_hidden = true;
$('#menu h5').stop().animate({'opacity' : '0'},400);
$('#menu').stop().animate({'height' : '20px'},600);
$('#menuBg').stop().animate({'height' : '20px'},600);
};

})

//Cookies

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);
}

function removeClass(ele,cls) {
	if (hasClass(ele,cls)) {
		var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
		ele.className=ele.className.replace(reg,' ');
	}
}

function hasClass(ele,cls) {
return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}


