if ($.cookie("header-persistent")) {
	document.documentElement.className += ' header-cookie';
}


$(document).ready(function($) {

	// open external links in a new window. These links must be marked with the
	// rel attribute.

	$("a[rel=external]").click(function() {
		window.open(this.href);
		return false;
	});

	var themepath = "/wp-content/themes/berattar/";

	// replace email span by real link
	
	$(".email").each(function(i) {
		var href = $(this).text().replace(" (at) ", "@").replace(" (dot) ", ".");
		$(this).html('<a href="mailto:' + href + '">' + href + '</a>');
	});
	
	// wp-admin triple click

	var adminarr = [];
	$(window).keyup(function(e) {
		if (e.keyCode == 27) {
			adminarr.push(e.keyCode);
			if(adminarr.length > 2) {
				document.location = "/wp-admin/";
			}
		} else {
			adminarr = Array();
		}
	});
	
	
	
	// icoooons!
	                                 
	                                 
	$("a[href$=pdf]").addClass("pdf");
	$("a[href$=doc]").addClass("doc");
	$("a[href$=zip]").addClass("zip");

	// lazy load plugin

	// $("img").not(".panel img").lazyload({ 
	// 	placeholder : themepath + "css/img/x.gif",
	// 	effect : "fadeIn"
	// });


	// Infinite Scroll

	$("#posts").infinitescroll({
		debug           : false,
		nextSelector    : ".subnav a:first",
		loadingImg      : themepath + "css/img/load.gif",
		loadingText     : "<em>Laddar fler nyheter...</em>",
		donetext        : "<em>Inga nyheter kvar att ladda</em>",
		navSelector     : ".subnav",
		contentSelector : "#posts",
		itemSelector    : "#posts div.post"
	});

	if($("body.home").length) {
		
		$("#header").hello_persistent("onunset", {
			callback: function() {
				
		
				
				$({property: 0}).delay(1200).animate({
					property: 100
				}, {
					duration: 1000,
					easing: "swing",
					step: function() {
						$("#header").css({
							height: 706-406/100*this.property,
							backgroundPosition: "center -" + 190/100*this.property + "px"
						})
					},
					complete: function() {
						// complete
					}
				});
				
				$("#header").hello_persistent("set");
			}
			
		});
		
	
		
	}
	
	$("div.images li:even").css({clear: "left"});
	
	$(".event").each(function() {
		var $event = $(this);
		$(this).find("a.js_eventopen").click(function(e){
			e.preventDefault();
			$event.find(".description").slideToggle();
		})
	})

});
