/*
	Featured Post Slider
	Custom version of: Simple jQuery Slideshow Script
    Originally released by Jon Raasch (jonraasch.com) - Customized by Sincklation (sincklation.com)
*/

// Set up the SimpleSlide function

jQuery.fn.simpleSlide = function(a){

	a				= a || {};
	a.duration		= a.duration || 2000;
	a.transition	= a.transition || 250;

	var	c	= $(this);

	$(c).css("position","relative");

	$("div.portfolio_featured",$(c));
	
	/*
		.css({
			'position'	: 'absolute',
			'top'		: '0px',
			'left'		: '0px',
			'z-index'	: '8'
			})
		*/
		$(this).parent().find("div.portfolio_featured:first")
			.addClass("slide-active")
			.css('z-index','10');

	setInterval(function(){

			var $active = $("div.portfolio_featured.slide-active",$(c));

			if($active.length === 0) $active = $("div.portfolio_featured:last",$(c));

			var $next	= $active.next().length ? $active.next() : $("div.portfolio_featured:first",$(c));

			$active
				.addClass("slide-last-active")
				.css('z-index','9');

			$next
				.css({opacity: 0.0})
				.addClass("slide-active")
				.css('z-index','10')
				.animate({opacity: 1.0}, a.transition, function(){
					$active
						.removeClass('slide-active slide-last-active')
						.css('z-index','8');
				});
		}, a.duration);

};

/**
 * jQuery.Preload - Multifunctional preloader
 * Copyright (c) 2008 Ariel Flesler - aflesler(at)gmail(dot)com
 * Dual licensed under MIT and GPL.
 * Date: 3/25/2009
 * @author Ariel Flesler
 * @version 1.0.8
 */
;(function($){var h=$.preload=function(c,d){if(c.split)c=$(c);d=$.extend({},h.defaults,d);var f=$.map(c,function(a){if(!a)return;if(a.split)return d.base+a+d.ext;var b=a.src||a.href;if(typeof d.placeholder=='string'&&a.src)a.src=d.placeholder;if(b&&d.find)b=b.replace(d.find,d.replace);return b||null}),data={loaded:0,failed:0,next:0,done:0,total:f.length};if(!data.total)return finish();var g=$(Array(d.threshold+1).join('<img/>')).load(handler).error(handler).bind('abort',handler).each(fetch);function handler(e){data.element=this;data.found=e.type=='load';data.image=this.src;data.index=this.index;var a=data.original=c[this.index];data[data.found?'loaded':'failed']++;data.done++;if(d.enforceCache)h.cache.push($('<img/>').attr('src',data.image)[0]);if(d.placeholder&&a.src)a.src=data.found?data.image:d.notFound||a.src;if(d.onComplete)d.onComplete(data);if(data.done<data.total)fetch(0,this);else{if(g&&g.unbind)g.unbind('load').unbind('error').unbind('abort');g=null;finish()}};function fetch(i,a,b){if(a.attachEvent&&data.next&&data.next%h.gap==0&&!b){setTimeout(function(){fetch(i,a,1)},0);return!1}if(data.next==data.total)return!1;a.index=data.next;a.src=f[data.next++];if(d.onRequest){data.index=a.index;data.element=a;data.image=a.src;data.original=c[data.next-1];d.onRequest(data)}};function finish(){if(d.onFinish)d.onFinish(data)}};h.gap=14;h.cache=[];h.defaults={threshold:2,base:'',ext:'',replace:''};$.fn.preload=function(a){h(this,a);return this}})(jQuery);


/**
* linkNotify v1.1 // 2009.06.10
* <http://briancray.com/2009/06/09/jquery-plugin-linknotify-inline-link-click-notification/>
* 
* @author    Brian Cray <webmail@briancray.com>
*/

(function($) {
	$.fn.linkNotify = function (notification) {
		notification = notification || 'Loading&hellip;';
		this.not('[href^="#"]').each(function () {
			$(this).click(function () {
				$(this).html(notification);
			});
		});
		return this;
	};
})(jQuery);


// Run scripts on document ready

jQuery(document).ready(function() {
								
		// preload slidshow
		
		/*
		$(this).find('#featured .portfolio_featured img').preload({
      	onFinish: function(){
       	$('#featured').fadeIn(1000); //show all images
      	}
    	});
		*/
		
		$(function() {
    	// setTimeout() function will be fired after page is loaded
   		setTimeout(function() { $("#llAni .imageAni").css({'display' : 'block'}).animate({ opacity: 1}, 1000 ) }, 10000);
		});
		
		// switch link text to "loading"
		
		$('.recent_posts a').linkNotify(); // display "Loading..." when any link is clicked
		//$('#content a').linkNotify('Loading your next page'); // display 'Loading your next page' on all links in the #content div
		
		
		// hiding the text on top of the thumbnails in Archive and on top of the Featured images on Home and in Archives
		
		$(".portfolio_info").hide();
		
		$(".portfolio_thumb").bind("mouseenter",function(){
			$(".portfolio_info:first",this).show();
			$(".portfolio_info",this).css({'filter' : 'alpha(opacity=90)', 'filter' : 'progid:DXImageTransform.Microsoft.Alpha(opacity=90)', '-moz-opacity' : '0.90', 'opacity' : '0.90'});
			$(".portfolio_info h4").css({'color' : '#666'});
			$(".portfolio_info a").css({'color' : '#666'});
			$(".portfolio_info p").css({'color' : '#666'});
		}).bind("mouseleave",function(){
			$(".portfolio_info:first",this).hide();
			});
		
		$("#featured").bind("mouseenter",function(){
			$(".portfolio_info",this).show();
			$(".portfolio_info",this).css({'filter' : 'alpha(opacity=90)', 'filter' : 'progid:DXImageTransform.Microsoft.Alpha(opacity=90)', '-moz-opacity' : '0.90', 'opacity' : '0.90'});
			$(".portfolio_info h4").css({'color' : '#000'});
			$(".portfolio_info p").css({'color' : '#000'});
		}).bind("mouseleave",function(){
			$(".portfolio_info",this).hide();
		});
		
		// Run the SimpleSlide
		
		$("#featured").simpleSlide();
		
		// Red plus in front of social media links on hover
		
		$("#sidebar .social_networks ul li").hover(function(){
			$("#sidebar .social_networks h4").css({'background-position' : '0% -17px'});
		}, 
      function () {
			$("#sidebar .social_networks h4").css({'background-position' : '0% 0px'});
		}
		);
		
		$("#sidebar .share ul li").hover(function(){
			$("#sidebar .share h4").css({'background-position' : '0% -17px'});
		}, 
      function () {
			$("#sidebar .share h4").css({'background-position' : '0% 0px'});
		}
		);
		
		$("#sharethis_0").hover(function(){
			$("#sidebar .share h4").css({'background-position' : '0% -17px'});
		}, 
      function () {
			$("#sidebar .share h4").css({'background-position' : '0% 0px'});
		}
		);
		
		// Lazyload to Load/Show images as you scroll down. Uses jquery.lazyload.js
		
		$(".four_col_span img").lazyload({
			placeholder : "http://www.lundgrenlindqvist.se/wp-content/themes/plus/script/transparent.png",
			effect : "fadeIn",
			threshold : "200"
		});
		
		// Go To Top
		// From Daniel Fajardo - http: //wwww.danielfajardo.com
		$("li.up a").click(function(){
			$(window)._scrollable().scrollTo( 0, 1000 );
		});
		
		
		// hide Comment field 'til clicked
		
		$("h4.comment").css({'display' : 'block', 'cursor' : 'pointer'});
		$("h4.comment").css({'cursor' : 'pointer'});
		
		$("h4.comment").hover(function(){
			$("#sidebar h4.comment").css({'background-position' : '0% -17px'});
		}, 
      function () {
			$("#sidebar h4.comment").css({'background-position' : '0% 0px'});
		}
		);
		
		$(".sidebar_section .respond").hide();
		
		
		
		$("#sidebar .comments h4.comment").click(function(){
   		var obj = $(this);
   			if(!obj.hasClass('open')){
       	obj.addClass('open');
   		}
   		else{
       		obj.removeClass('open');
   		}
   		$(".sidebar_section .respond").slideToggle();
   		return false;
		});
		
		// hide Recent Posts on Single post 'til clicked
		
		$("h4.recent_posts").css({'display' : 'block', 'cursor' : 'pointer'});
		$("h4.recent_posts").css({'cursor' : 'pointer'});
		
		$("h4.recent_posts").hover(function(){
			$("#sidebar h4.recent_posts").css({'background-position' : '0% -17px'});
		}, 
      function () {
			$("#sidebar h4.recent_posts").css({'background-position' : '0% 0px'});
		}
		);
		
		$(".sidebar_section.recent_posts.single_post ul").hide();
		
		$("#sidebar .sidebar_section.recent_posts.single_post h4.recent_posts").click(function(){
   		var obj = $(this);
   			if(!obj.hasClass('open')){
       	obj.addClass('open');
   		}
   		else{
       		obj.removeClass('open');
   		}
   		$(".sidebar_section.recent_posts.single_post ul").slideToggle();
   		return false;
		});
		
		
		
		// show and hide swedish translation on About page
		
		$(".swe_text").hide();
		
		$(".flag").hover(function(){
			$(".flag").css({'background-position' : 'left -14px'});
		}, 
      function () {
			$(".flag").css({'background-position' : 'left 0'});
		});
		
		
		$(".flag").click(function(){
   		var obj = $(this);
   			if(!obj.hasClass('swe')){
       		obj.addClass('swe');
			$(".eng_text").hide();
			$(".swe_text").show();
			$(".about h2").html("Hej!");
   		}
   		else{
       		obj.removeClass('swe');
			$(".eng_text").show();
			$(".swe_text").hide();
			$(".about h2").html("Hello!");
		}	
   		return false;
		});

			
});

// make #content_grow wider if possible to fit another 376px

    	$.fn.content_grow = function() {  
        //Invoke the resizenow() function on document ready
        $(document).ready(function() {
            $('#content_grow').resizenow();
        });
        //Invoke the resizenow() function on browser resize
        $(window).bind("resize", function() {
            $('#content_grow').resizenow();
        });
    	};
    	//Adjust image size
    	$.fn.resizenow = function() {
        	
			var $thewidth = $(window).width();		
			var $fitTwoImg = 960;
			var $fitThreeImg = 1336;
			var $fitFourImg = 1712;
			var $fitFiveImg = 2088;
			var $fitSixImg = 2464;
			var $fitSevenImg = 2840;
		
			if ($thewidth <= $fitThreeImg) {
				$(this).css({'width' : '752px'});
			}
			else if ($thewidth <= $fitFourImg) {
				$(this).css({'width' : '1128px'});
			}
			else if ($thewidth <= $fitFiveImg) {
				$(this).css({'width' : '1504px'});
			}
			else if ($thewidth <= $fitSixImg) {
				$(this).css({'width' : '1880px'});
			}
			else if ($thewidth <= $fitSevenImg) {
				$(this).css({'width' : '2256px'});
			}
			else {
				$(this).css({'width' : '752px'});
			}
    	};
		
		$(document).ready(function() {
    		$("div#content_grow").content_grow();
		});
