(function(){var objects=document.getElementsByTagName('object'),object,params,param,name,value,clip_id,paramsArr,finds;for(var i=0;i<objects.length;i++){object=objects[i],params=object.getElementsByTagName('param');finds=0;for(var ii=0;ii<params.length&&finds==0;ii++){param=params[ii];name=param.getAttribute('name');if(name=='src'||name=='movie'){value=param.getAttribute('value');if(/moogaloop/.test(value)){finds++;paramsArr=value.split('?')[1].split('clip_id=')[1].split('&');clip_id=paramsArr[0];qparams=paramsArr[1];replace(object,clip_id,qparams,object.getAttribute('width'),object.getAttribute('height'));}}}}
function replace(target,clip_id,params,width,height){var iframe=document.createElement('iframe');iframe.setAttribute('width',width);iframe.setAttribute('height',height);iframe.setAttribute('src','http://player.vimeo.com/video/'+clip_id+'?'+params);iframe.setAttribute('frameborder',0);target.parentNode.insertBefore(iframe,target);target.parentNode.removeChild(target);}})();/*
 * jQuery replaceText - v1.1 - 11/21/2009
 * http://benalman.com/projects/jquery-replacetext-plugin/
 * 
 * Copyright (c) 2009 "Cowboy" Ben Alman
 * Dual licensed under the MIT and GPL licenses.
 * http://benalman.com/about/license/
 */
(function($){$.fn.replaceText=function(b,a,c){return this.each(function(){var f=this.firstChild,g,e,d=[];if(f){do{if(f.nodeType===3){g=f.nodeValue;e=g.replace(b,a);if(e!==g){if(!c&&/</.test(e)){$(f).before(e);d.push(f)}else{f.nodeValue=e}}}}while(f=f.nextSibling)}d.length&&$(d).remove()})}})(jQuery);

$(function() {

//    $(".photo a").each(function(){
//        if ($(this).attr("href").search(/instagr/gi) != -1){
//            $(this).attr("href", $("img",this).attr("src"));
//        }
//    })
//	if (navigator.userAgent.indexOf('iPhone') == -1) {
		$("img").parent("a").fancybox();
//		$("div.photoset a").fancybox({
//    		'transitionIn'		: 'none',
//    		'transitionOut'		: 'none',
//    		'titlePosition' 	: 'over',
//    		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
//    			return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
//    		}
//    	});
//	}
	$(".caption a[href*='youtube.com']").addClass("youtube").addClass("social");
	$(".caption a[href*='flickr.com']").addClass("flickr").addClass("social");
	$(".caption a[href*='twitter.com']").addClass("twitter").addClass("social");
	$(".caption a[href*='facebook.com']").addClass("facebook").addClass("social");
	$(".caption a[href*='tumblr.com']").addClass("tumblr").addClass("social");
	$(".caption a[href*='digg.com']").addClass("digg").addClass("social");
	$(".caption a[href*='google.com']").addClass("google").addClass("social");
	$(".caption a[href*='friendfeed.com']").addClass("friendfeed").addClass("social");
	$(".caption a[href*='gowalla.com']").addClass("tumblr").addClass("social");
	$(".caption a[href*='lastfm.com']").addClass("lastfm").addClass("social");
	$(".caption a[href*='linkedin.com']").addClass("linkedin").addClass("social");
	$(".caption a[href*='apple.com']").addClass("apple").addClass("social");
	$(".caption a[href*='vimeo.com']").addClass("vimeo").addClass("social");
	$(".caption a img").parent("a").removeClass("social");

	$("a[style='font-size: 85%;']").css("color","#c33");

	$(".date .text").replaceText( /monday/gi, "måndag" );
	$(".date .text").replaceText( /tuesday/gi, "tisdag" );
	$(".date .text").replaceText( /wednesday/gi, "onsdag" );
	$(".date .text").replaceText( /thursday/gi, "torsdag" );
	$(".date .text").replaceText( /friday/gi, "fredag" );
	$(".date .text").replaceText( /saturday/gi, "lördag" );
	$(".date .text").replaceText( /sunday/gi, "söndag" );

	$(".date .text").replaceText( /january/gi, "januari" );
	$(".date .text").replaceText( /february/gi, "februari" );
	$(".date .text").replaceText( /march/gi, "mars" );
	$(".date .text").replaceText( /april/gi, "april" );
	$(".date .text").replaceText( /may/gi, "maj" );
	$(".date .text").replaceText( /june/gi, "juni" );
	$(".date .text").replaceText( /july/gi, "juli" );
	$(".date .text").replaceText( /august/gi, "augusti" );
	$(".date .text").replaceText( /september/gi, "september" );
	$(".date .text").replaceText( /october/gi, "oktober" );
	$(".date .text").replaceText( /november/gi, "november" );
	$(".date .text").replaceText( /december/gi, "december" );
//	$(".date .text").replaceText( /january/gi, "jan" );
//	$(".date .text").replaceText( /february/gi, "feb" );
//	$(".date .text").replaceText( /march/gi, "mar" );
//	$(".date .text").replaceText( /april/gi, "apr" );
//	$(".date .text").replaceText( /may/gi, "maj" );
//	$(".date .text").replaceText( /june/gi, "jun" );
//	$(".date .text").replaceText( /july/gi, "jul" );
//	$(".date .text").replaceText( /august/gi, "aug" );
//	$(".date .text").replaceText( /september/gi, "sep" );
//	$(".date .text").replaceText( /october/gi, "okt" );
//	$(".date .text").replaceText( /november/gi, "nov" );
//	$(".date .text").replaceText( /december/gi, "dec" );
	$(".date").fadeIn();
	$("ul.social img").mouseenter(function(){
		var index = $("ul.social img").index(this);
		$("ul.social img:not(this))").fadeTo("fast",0.33)
		$(this).fadeTo("fast",1)
	});
	$("ul.social").mouseleave(function(){
		$("img",this).fadeTo("fast",1)
	});
	$("nav ul:not(.social) li li a").mouseenter(function(){
		$("img",this).fadeTo("fast",1)
	})
	$("nav ul:not(.social) li li a").mouseleave(function(){
		$("img",this).fadeTo("fast",0.5)
	})
	$(".vimeoBadge a").mouseenter(function(){
		$("img",this).fadeTo("fast",1)
	})
	$(".vimeoBadge a").mouseleave(function(){
		$("img",this).fadeTo("fast",0.5)
	})
	$("a.postLink").each(function(){
        var theHref = $(this).attr("href");
        var theLink = $(this);
        $.get(theHref, function(data){
            var theText = $(data).find("h1").text();
            var theDate = $(data).find("time:first").attr("datetime")
            theLink.html(theLink.text() + "<h2>" + theText + "</h2><p class='datum'>" + theDate + "</p>");
	  	})
	});
	$(".paginator a").each(function(){
        var theHref = $(this).attr("href");
        var theLink = $(this);
        $.get(theHref, function(data){
            var endText = $(data).find(".date:first time").attr("datetime");
            var startText = $(data).find(".date:last time").attr("datetime");
            theLink.attr("title", startText + " - " + endText);
	  	})
	
	});


	// search field nicer (more style in the future)
	$("#topSearch label:first").hide()
	var searchText = $("#topSearch label:first").text();
	$("#topSearch input:first").val(searchText);
	$("#topSearch input:first").focus(function(){
		$(this).addClass("focused");
		if($(this).val() == searchText){
			$(this).val("")
		}
	});
	$("#topSearch input:first").blur(function(){
		$(this).removeClass("focused");
		if(jQuery.trim($(this).val()) == ""){
			$(this).val(searchText)
		}
	});
	
	
	
	$(".mailForm label").each(function(){
		$(this).hide();
		var theText = $(this).text()
		if($(this).next().val() == ""){
			$(this).next().val(theText)
		}
		$(this).next().focus(function(){
			$(this).addClass("focused");
			if($(this).val() == theText){
				$(this).val("")
			}
			
		});
		$(this).next().blur(function(){
			$(this).removeClass("focused");
			if(jQuery.trim($(this).val()) == ""){
				$(this).val(theText)
			}
			
		});
		
	})
	
	var searchText = $("#topSearch label:first").text();
	$("#topSearch input:first").val(searchText);
	$("#topSearch input:first").focus(function(){
		$(this).addClass("focused");
		if($(this).val() == searchText){
			$(this).val("")
		}
	});
	$("#topSearch input:first").blur(function(){
		$(this).removeClass("focused");
		if(jQuery.trim($(this).val()) == ""){
			$(this).val(searchText)
		}
	});



	$(".post .date").each(function(){
		if($(this).parents(".post").next().children().hasClass("date")){
			$(this).parents(".post").css("min-height","34px")
		}
	});
	$(".photoAlbumsPhotos img").mouseover(function(){
		$(this).css({
			margin:"4px",
			width:"46px",
			height:"46px"
		})	
	})
	$(".photoAlbumsPhotos img").mouseout(function(){
		$(this).css({
			margin:"6px",
			width:"42px",
			height:"42px"
		})	
		$(this).css("margin","6px")	
		$(this).css("width","42px")	
		$(this).css("height","42px")	
	})
	$(".photoAlbumPhotos img").mouseover(function(){
		$(this).css("margin","4px")	
		$(this).css("width","73px")	
		$(this).css("height","73px")	
	})
	$(".photoAlbumPhotos img").mouseout(function(){
		$(this).css("margin","6px")	
		$(this).css("width","69px")	
		$(this).css("height","69px")	
	})
 	$("#sidebar").append('<img src="http://stil.janner.se/image/button.close.gif" alt="close" class="sidebarCloser">');

	$(".nav li:first a:eq(1),.sidebarCloser").click(function(){
		$("#sidebar").fadeToggle(400)
		if ($(".nav li:first a:eq(1)").text() != "6"){
			$(".nav li:first a:eq(1)").text("6");
		} else {
			$(".nav li:first a:eq(1)").text("5");	
		}
		return false;
	})

	var query = '?';
	$("a[href$='#disqus_thread']").each(function(i){
		query += 'url' + i + '=' + encodeURIComponent($(this).attr("href")) + '&';
	})
	$.getScript('http://disqus.com/forums/martinjanner/get_num_replies.js' + query );
	
	$.fn.fadeToggle = function(speed, easing, callback) {
		return this.animate({opacity: 'toggle'}, speed, easing, callback); 
	};
	var kkeys = [], konami = "38,38,40,40,37,39,37,39,66,65";
	$(window).keydown(function(e){
	    kkeys.push(e.keyCode);
	    	
	    if ( kkeys.toString().indexOf( konami ) >= 0 ) {
	    	$.getScript("http://www.cornify.com/js/cornify.js",function(){
	    		cornify_add();
	    	});
	    }
	}, true);
});


