function fbs_click() {
    u = location.href;
    t = document.title;
    window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
    return false;
}

function iSlider() {
	
	slideL = window.setInterval('slide(1)',99);
	var slider = $('#iSliderInner');
	var wrapper = 0;
	slider.find('img').each(function() {
		wrapper += $(this).width()+8;
		height = $(this).height();
		margintop = (45-height)/2;
		$(this).css('margin-top',margintop);
	});
	slider.wrapInner("<div id='wrapper'></div>").prepend("<div id='slideLeft'></div>").append("<div id='slideRight'></div>");

	slider.find('#wrapper').css('width',wrapper);

	slider.find('#slideRight').bind("mouseover mouseout", function(event) {
		if(event.type=='mouseover') {
			window.clearInterval(slideL);
			slideL = window.setInterval('slide(1)',99);
		}
		if(event.type=='mouseout') {
			window.clearInterval(slideL);
			slideL = window.setInterval('slide(1)',99);
		}
	});

	slider.find('#slideLeft').bind("mouseover mouseout", function(event) {
		if(event.type=='mouseover') {
			window.clearInterval(slideL);
			slideR = window.setInterval('slide(-1)',99);
		} 
		if(event.type=='mouseout') {
			window.clearInterval(slideR);
			slideL = window.setInterval('slide(1)',90);
		}
	});
}

function slide(dir) {
	var wrapper =  $('#wrapper');
	if(wrapper.css('margin-left')=='auto') {
		wrapper.css('margin-left',0);
	}
    var wrapperPosition = parseInt(wrapper.css('margin-left'));
    var wrapperWidth = parseInt(wrapper.width())*-1;
    if(dir>0) {
        var wrapperNewPosition = wrapperPosition-2;
        if(wrapperNewPosition<-98) {
        	//erstes element nehmen und hinten anstellen und position auf 0
        	var element = $('#wrapper > a:first').remove().appendTo('#wrapper');
        	wrapperNewPosition = 0;
        }
    } else {
        var wrapperNewPosition = wrapperPosition+2;
        if(wrapperNewPosition>0) {
        	var element = $('#wrapper > a:last').remove().prependTo('#wrapper');
        	wrapperNewPosition = -98;
        	//letzes element vorne anstellen und position auf 0
        }
    }
	var newString = wrapperNewPosition+'px';
	wrapper.css('margin-left',newString);
};


$(document).ready( function() {

	//IMG ohne alt Text fuellen
	$("img[alt='']").attr('alt','7iD Technologies GmbH');
	
	// fancybox
	//$('a').fancybox();
	$("a[href$='jpg'], a[href$='JPG'], a[href$='jpeg'], a[href$='JPEG'], a[href$='png'], a[href$='PNG'], a[href$='gif'], a[href$='GIF']").fancybox();
	
	//dropdown metanav
	$('#metanav > div').each(function() {
		width = $(this).find('a:first').width()+2;
		$(this).width(width);
	});
	
	// clean navigation
	$('#navigation div.inner').each(function() {
		if($(this).children().size()==0) {
			$(this).remove();
		}
	});
	
	//dropdown navigation
	$('#navigation div.iRect').hover(function() {
		$(this).css('height','auto');
	}, function() {
		$(this).css('height','24px');
	});
	
	//dropdown index unten
	$('div.pulldown').hover(function() {
		$(this).css('height','auto');
	}, function() {
		$(this).css('height','17px');
	});
	
	//toggle block
	$('h3.blockText').toggle(function() {
		$(this).next().show();
		$(this).css('background-image','url(/_include/css/img/pullup.gif)');
	}, function() {
		$(this).next().hide();
		$(this).css('background-image','url(/_include/css/img/pulldown.gif)');
	});
	
	// iSlider
	iSlider();
	
	// subnavigation einrueckung
	$('#subnavigation span').each(function() {
		height = $(this).parent().height();
		$(this).height(height);
	});
	
	$('#iTeaser').css('margin-top','0');
	
});
