(function (a) {
    a(document).ready(function () {
        a("#dots").pan({
            fps: 30,
            speed: 0.4,
            dir: "left",
            depth: 10
        });
        a("#radials_background2").pan({
            fps: 30,
            speed: 2,
            dir: "right",
            depth: 30
        });
        a("#radials_background1").pan({
            fps: 30,
            speed: 2,
            dir: "left",
            depth: 70
        });
        a("#bar").pan({
            fps: 30,
            speed: 3,
            dir: "right",
            depth: 100
        });
        a("#radial").pan({
            fps: 30,
            speed: 0.6,
            dir: "up",
            depth: 70
        });
        a("#effect1").sprite({
            fps: 6,
            no_of_frames: 30
        });
        a("#effect2").sprite({
            fps: 7,
            no_of_frames: 11
        });
        a("#effect3").sprite({
            fps: 6,
            no_of_frames: 10
        });
        a("#effect4").sprite({
            fps: 6,
            no_of_frames: 14
        });
        a("#effect5").sprite({
            fps: 6,
            no_of_frames: 9
        });
        a("#effect6").sprite({
            fps: 8,
            no_of_frames: 22
        });
        a("#effect7").sprite({
            fps: 8,
            no_of_frames: 40,
            pause: 3000
        });
        a("#effect8").sprite({
            fps: 2,
            no_of_frames: 10
        });
        a(".halftone").sprite({
            fps: 6,
            no_of_frames: 38
        });
        a("#slides").slides({
            preload: true,
            hoverPause: true,
            play: 5000,
            pause: 2000,
            effect: "fade",
            generateNextPrev: false
        });
        a("#slides2").slides({
            preload: true,
            hoverPause: true,
            play: 5000,
            pause: 2000,
            effect: "slide",
            generateNextPrev: false
        });
        a("#cases_loader").load("cases.php?work=projecten");
        a("div.filter_work a").click(function () {
            a(this).css("outline", "none");
            a("div.filters .current").removeClass("current");
            a(this).parent().addClass("current");
            //if (!a(this).parent().hasClass("overzicht-alle-opdrachtgevers") && !a(this).parent().hasClass("overzicht-alle-opdrachtgevers")) {
                var b = a(this).text().toLowerCase().replace(" ", "-");
                //alert(b);
                if (b == "overzicht-alle opdrachtgevers") {
                    a("#title_loader").text("Overzicht alle opdrachtgevers");
                    a("#cases_loader").load("cases.php?page=overzicht-alle-opdrachtgevers")
                } else {
                    if (a(this).parent().hasClass("margin-top-10")) {
                        a("#title_loader").text("Alle projecten");
                        a("#cases_loader").load("cases.php?work=recent-opgeleverd&p=all")
                    } else {
                        a("#title_loader").text(a(this).text());
                        a("#cases_loader").load("cases.php?work=" + encodeURI(b))
                    }
                }
                return false
            //}
        });
        a("div.filter_products a").click(function () {
            a(this).css("outline", "none");
            a("div.filters .current").removeClass("current");
            a(this).parent().addClass("current");
            var b = a(this).text().toLowerCase().replace(" ", "-").replace(" ", "-");
            a("#title_loader").text(a(this).text());
            a("#cases_loader").load("cases.php?product=" + encodeURI(b));
            return false
        })
    })
	
})(jQuery);

$(document).ready(function() {
 
    //move the image in pixel
    var move = 0;
     
    //zoom percentage, 1.2 =120%
    var zoom = 1.12;
 
    //On mouse over those thumbnail
    $('.zoom').hover(function() {
         
        //Set the width and height according to the zoom percentage
        width = $('.zoom').width() * zoom;
        height = $('.zoom').height() * zoom;
         
        //Move and zoom the image
        $(this).find('img').stop(false,true).animate({'width':width, 'height':height, 'top':'-5%','left':'-5%', 'bottom':'-5%', 'right':'-5%'}, {duration:300});
         
    },
    function() {
        //Reset the image
        $(this).find('img').stop(false,true).animate({'width':$('.zoom').width(), 'height':$('.zoom').height(), 'top':'0%', 'bottom':'0%', 'left':'0%', 'right':'0%'}, {duration:200});  

    });
 
});

$(document).ready(function () {
    
	$("#open").click(function () {
        $("div#panel").slideDown("slow")
    });
    $("#close").click(function () {
        $("div#panel").slideUp("slow")
    });
    $("#toggle a").click(function () {
        $("#toggle a").toggle()
    })
	
    $("ul.login li a").click(function () {
        $(this).parent().find("ul#menu-socials-menu").slideDown("fast").show();
        $(this).parent().hover(function () {}, function () {
            $(this).parent().find("ul#menu-socials-menu").slideUp("slow")
        })
    }).hover(function () {
        $(this).addClass("subhover")
    }, function () {
        $(this).removeClass("subhover")
    })
	
    $('input[type="text"]').addClass("idleField");
    $('input[type="text"]').focus(function () {
        $(this).removeClass("idleField").addClass("focusField");
        if (this.value == this.defaultValue) {
            this.value = ""
        }
        if (this.value != this.defaultValue) {
            this.select()
        }
    });
    $('input[type="text"]').blur(function () {
        $(this).removeClass("focusField").addClass("idleField");
        if ($.trim(this.value) == "") {
            this.value = (this.defaultValue ? this.defaultValue : "")
        }
    })
	
    $(".button").append('<span class="hover"&gt</span&gt').each(function () {
        var a = $("&gt span.hover", this).css("opacity", 0);
        $(this).hover(function () {
            a.stop().fadeTo(500, 1)
        }, function () {
            a.stop().fadeTo(500, 0)
        })
    })
	
    $(".color").hover(function () {
        $(this).stop().animate({
            opacity: "1"
        }, "slow")
    }, function () {
        $(this).stop().animate({
            opacity: "1"
        }, "slow")
    })
	
    $("#logoslider").carouFredSel({
        auto: true,
        circular: true,
        infinite: true,
        duration: "5000",
        width: 960,
        height: 65,
        padding: "auto",
        direction: "right",
        items: {
            visible: "variable",
            width: "variable",
            height: 65
        },
        scroll: {
            mousewheel: true,
            pauseOnHover: true
        },
        prev: {
            button: ".prev-btn",
            key: "left"
        },
        next: {
            button: ".next-btn",
            key: "right"
        }
    })
	

});


// 
// Twitter feed
// 
JQTWEET = {
	
	// Set twitter username, number of tweets & id/class to append tweets
	user: 'YellowLemonTree',
	numTweets: 2, 
	appendTo: '#jstweets',
 
	// core function of jqtweet
	loadTweets: function() {
		$.ajax({
			url: 'http://api.twitter.com/1/statuses/user_timeline.json/',
			type: 'GET',
			dataType: 'jsonp',
			data: {
				screen_name: JQTWEET.user,
				include_rts: true,
				count: JQTWEET.numTweets,
				include_entities: true
			},
			success: function(data, textStatus, xhr) {
 
				 var html = '<li>TWEET_TEXT<div class="time">AGO</li>';
		 
				 // append tweets into page
				 for (var i = 0; i < data.length; i++) {
					$(JQTWEET.appendTo).append(
						html.replace('TWEET_TEXT', JQTWEET.ify.clean(data[i].text) )
							.replace(/USER/g, data[i].user.screen_name)
							.replace('AGO', JQTWEET.timeAgo(data[i].created_at) )
							.replace(/ID/g, data[i].id_str)
					);
				 }                 
			}  
 
		});
		 
	},
	 
		 
	/**
	  * relative time calculator FROM TWITTER
	  * @param {string} twitter date string returned from Twitter API
	  * @return {string} relative time like "2 minutes ago"
	  */
	timeAgo: function(dateString) {
		var rightNow = new Date();
		var then = new Date(dateString);
		 
		if ($.browser.msie) {
			// IE can't parse these crazy Ruby dates
			then = Date.parse(dateString.replace(/( \+)/, ' UTC$1'));
		}
 
		var diff = rightNow - then;
 
		var second = 1000,
		minute = second * 60,
		hour = minute * 60,
		day = hour * 24,
		week = day * 7;
 
		if (isNaN(diff) || diff < 0) {
			return ""; // return blank string if unknown
		}
 
		if (diff < second * 2) {
			// within 2 seconds
			return "nu";
		}
 
		if (diff < minute) {
			return Math.floor(diff / second) + " seconden geleden";
		}
 
		if (diff < minute * 2) {
			return "ongeveer 1 minuut geleden";
		}
 
		if (diff < hour) {
			return Math.floor(diff / minute) + " minuten geleden";
		}
 
		if (diff < hour * 2) {
			return "ongeveer 1 uur geleden";
		}
 
		if (diff < day) {
			return  Math.floor(diff / hour) + " uur geleden";
		}
 
		if (diff > day && diff < day * 2) {
			return "gisteren";
		}
 
		if (diff < day * 365) {
			return Math.floor(diff / day) + " dagen geleden";
		}
 
		else {
			return "ongeveer een jaar geleden";
		}
	}, // timeAgo()
	 
	 
	/**
	  * The Twitalinkahashifyer!
	  * http://www.dustindiaz.com/basement/ify.html
	  * Eg:
	  * ify.clean('your tweet text');
	  */
	ify:  {
	  link: function(tweet) {
		return tweet.replace(/\b(((https*\:\/\/)|www\.)[^\"\']+?)(([!?,.\)]+)?(\s|$))/g, function(link, m1, m2, m3, m4) {
		  var http = m2.match(/w/) ? 'http://' : '';
		  return '<a class="twtr-hyperlink" target="_blank" href="' + http + m1 + '">' + ((m1.length > 25) ? m1.substr(0, 24) + '...' : m1) + '</a>' + m4;
		});
	  },
 
	  at: function(tweet) {
		return tweet.replace(/\B[@＠]([a-zA-Z0-9_]{1,20})/g, function(m, username) {
		  return '<a target="_blank" class="twtr-atreply" href="http://twitter.com/intent/user?screen_name=' + username + '">@' + username + '</a>';
		});
	  },
 
	  list: function(tweet) {
		return tweet.replace(/\B[@＠]([a-zA-Z0-9_]{1,20}\/\w+)/g, function(m, userlist) {
		  return '<a target="_blank" class="twtr-atreply" href="http://twitter.com/' + userlist + '">@' + userlist + '</a>';
		});
	  },
 
	  hash: function(tweet) {
		return tweet.replace(/(^|\s+)#(\w+)/gi, function(m, before, hash) {
		  return before + '<a target="_blank" class="twtr-hashtag" href="http://twitter.com/search?q=%23' + hash + '">#' + hash + '</a>';
		});
	  },
 
	  clean: function(tweet) {
		return this.hash(this.at(this.list(this.link(tweet))));
	  }
	} // ify
 
	 
};

(function($) {
	$.fn.equalHeights = function(minHeight, maxHeight) {
		tallest = (minHeight) ? minHeight : 0;
		this.each(function() {
			if($(this).height() > tallest) {
				tallest = $(this).height();
			}
		});
		if((maxHeight) && tallest > maxHeight) tallest = maxHeight;
		return this.each(function() {
			$(this).height(tallest).css("overflow","auto");
		});
	}
})(jQuery);



