$(document).ready(function() {
    setHeight('.col');
	
	if($("#content_left")){
		var leftFirstHeight = $(".first_content_frame").height();
		if($("#content_right")){
			//alert(leftFirstHeight);
			$(".first_content_frame").height(leftFirstHeight);
		}
	}
	
	if ($('#submenu ul a')) {
		$(function() {
			$('#submenu ul a').css({backgroundPosition: "-350px 0"}).mouseover(function(){
				$(this).stop().animate({backgroundPosition: "(0 0)"}, {duration: 500})
			}).mouseout(function(){
				$(this).stop().animate({backgroundPosition: "(-350px 0)"}, {duration: 500, complete: function(){
					$(this).css({backgroundPosition: "-350px 0"})
				}})
			})
		});
	}
	if($('#slideshow')){
		$(function() {
		    $('#slideshow').cycle({
		        fx:      'scrollHorz',
		        timeout:  0,
		        prev:    '#prev',
		        next:    '#next',
		        pager:   '#nav',
		        pagerAnchorBuilder: pagerFactory
		    });
		
		    function pagerFactory(idx, slide) {
		        var s = idx > 2 ? ' style="display:none"' : '';
		        return '<a '+s+' href="#"></a>';
		    };
		});
	}
	
	var shadowLeftSmall = "<img class='shadow_bottom_left' src='/images/basics/imageshadowlefts.png'/>";
	var shadowRightSmall = "<img class='shadow_bottom_right' src='/images/basics/imageshadowrights.png'/>";
	var shadowLeftBig = "<img class='shadow_bottom_left' src='/images/basics/imageshadowleftb.png'/>";
	var shadowRightBig = "<img class='shadow_bottom_right' src='/images/basics/imageshadowrightb.png'/>";
	if ($(".img_container_small img")) {
		$(".img_container_small img").before(shadowLeftSmall, shadowRightSmall);
	}
	if ($(".slideshow_container")){
		$(".slideshow_container").append(shadowLeftBig, shadowRightBig);
	}
	if ($(".img_container_large img")){
		$(".img_container_large img").before(shadowLeftBig, shadowRightBig);
	}

	$(".title").each(function(){
	    var me = $(this)
	       , t = me.text().split(' ');
	    me.html( '<b>'+t.shift()+'</b> '+t.join(' ') );
	  });
	  
	if ($(".portfolio_container_home ul li .frame")) {
		$(".portfolio_container_home ul li .frame").hover(function(){
			$(this).stop().animate({
				bottom: 5
			}, 'fast',function(){
				$(this).find(".portfolio_home_categorie").fadeIn("fast");
			});
			$(this).find(".frame_content").stop().animate({
				height: 90
			}, '1000').addClass("highlight");
		}, function(){
			$(this).stop().animate({
				bottom: 0
			}, 'fast');
			$(this).find(".frame_content").stop().animate({
				height: 55
			}, '1000').removeClass("highlight");
			$(this).find(".portfolio_home_categorie").stop().fadeOut("slow");
		});
	}
	if ($('.slideshow')) {
		$('.slideshow').cycle({
			fx: 'fade'
		});
	}
	
	$('#mainmenu li a').dwFadingLinks({
		color: '#FC6500',
		duration: 500
	});
	
	if ($('.content_lagen .laag_row')) {
		$(".content_lagen .laag_row").hover(function(){
			$(this).find('.laag_left').stop().animate({
					
			}, '500');
			$(this).find('.laag_right').stop().animate({
					marginLeft: 150
			}, '500');
		}, function(){
			$(this).find('.laag_left').stop().animate({
					
			}, '500');
			$(this).find('.laag_right').stop().animate({
					marginLeft: 0
			}, '500');			
		});
	}
	
});

/* plugin fade */
jQuery.fn.dwFadingLinks = function(settings) {
	settings = jQuery.extend({
		color: '#FC6500',
		duration: 500
	}, settings);
	return this.each(function() {
		var original = $(this).css('color');
		$(this).mouseover(function() { $(this).stop().animate({ color: settings.color },settings.duration); });
		$(this).mouseout(function() { $(this).stop().animate({ color: original },settings.duration); });
	});
};

//global variable, this will store the highest height value
var maxHeight = 0;

function setHeight(col) {
	//Get all the element with class = col
	col = $(col);
	
	//Loop all the col
    col.each(function() {        
	
		//Store the highest value
		if($(this).height() > maxHeight) {
            maxHeight = $(this).height();;
        }
    });
	
	//Set the height
    col.height(maxHeight);
}
