/*
* 
* standard.js
*
* Author: Christopher Pietsch - cpietsch at gmail dot com
* Company: Limeflavour | http://www.limeflavour.com
* Date: August 2008
*/


//window.onload = new Function("blurLinks();"); //setHeight();setContrastLink();


/*function blurLinks() {
	var aTags = document.getElementsByTagName('a');
	var i;
	for ( i=0; i < aTags.length; i++ )
	{
		var Fokus = document.createAttribute("onfocus");
		Fokus.nodeValue = "if(this.blur)this.blur()";
		document.getElementsByTagName("a")[i].setAttributeNode(Fokus);
	}
}
*/

// When the page is ready  
$(document).ready(function(){ 
	

		function nothing(){}
	
		//LoRadio
		
		//$(".radioBox p.entry:gt(2)").wrapAll("<div class='moreEntrys'></div>");
		$(".radioBox div.moreEntrys").hide();
		//$(".radioBox p.more")
		//.find("a:even").toggle().end()
		
		$(".radioBox").hoverIntent({
						sensitivity: 4, 
						interval: 200, 
						over: toggleRadio, 
						timeout: 500, 
						out: toggleRadio
					});
		function toggleRadio(){
			$(".radioBox .moreEntrys").slideToggle(300);
			$("#containerMarginalB .teaserBox .contentBox").not(".radioBox").slideToggle(300);
			
			//$(this).find("p.more a:even").toggle().end().find("a:odd").toggle().end()
			//return false;
		}

		//LoRadio
		
		//$(".teleBox p:gt(2)").wrapAll("<div class='moreEntrys'></div>");
		$(".teleBox div.moreEntrys").hide();
		//$(".radioBox p.more")
		//.find("a:even").toggle().end()
		
		$(".teleBox").hoverIntent({
						sensitivity: 4, 
						interval: 200, 
						over: toggleTele, 
						timeout: 500, 
						out: toggleTele
					});
		function toggleTele(){
			$(".teleBox .moreEntrys").slideToggle(300);
			$("#containerMarginalB .teaserBox .contentBox").not(".teleBox").slideToggle(300);
			
			//$(this).find("p.more a:even").toggle().end().find("a:odd").toggle().end()
			//return false;
		}


	//Newsletter
	$("#containerMarginalB .newsletterBox")
	.find(".formBox").hide().end()
	.find(".toggleNewsletter").show().click(function(){  
		$(".toggleNewsletter").fadeOut("fast", function(){
			$(".formBox").fadeIn(""); 
		});
		return false;  
	}).end();
	
	
	//Blogcontent
	$blogBoxen=$(".contentList .teaserBox");
	
	if(!$(".imageBox",$blogBoxen).hasClass("active")){ $(".imageBox",$blogBoxen).eq(0).addClass("active") }
	
	$(".imageBox",$blogBoxen).not(".active").hide().end().end()
	.hoverIntent({
		sensitivity: 3, 
		interval: 200, 
		over: toggleContent, 
		timeout: 200, 
		out: nothing
	})
	
	$.fn.slideFadeToggle = function(speed, easing, callback) {
	       return this.animate({opacity: 'toggle', height: 'toggle'}, speed,
	easing, callback);
	};
	
	function toggleContent(){
		//console.log();
		if($(".imageBox",this)[0] && !$(".imageBox",this).hasClass("active")){
			// animate mit fade in
			
			var toHide=$(".contentList .active"),
				toShow=$(this).find(".imageBox"),
			 	hideHeight = toHide.height(),
				showHeight = toShow.height(),
				difference = showHeight / hideHeight;
				
				//console.log(showHeight+"-"+hideHeight)
			/*
			toShow.addClass("active").slideFadeToggle(500,"swing")
			toHide.removeClass("active").slideFadeToggle(500,"swing")
			*/
			toShow.addClass("active").css({ height: 0, overflow: 'hidden'}).fadeIn(700);
			toHide.removeClass("active").animate({height:"hide"},{
				step: function(now) {
					//console.log(now/toHide.height())
					var current = (hideHeight - now) * difference;
					if ($.browser.msie || $.browser.opera) {
						current = Math.ceil(current);
					}
					toShow.height( current );
					//toHide.css("opacity", 1-now/toHide.height())
				},
				duration: 300,
				easing: "swing",
				complete: function() {
		
				}
			});	

		}
	}
	//slider
	//$('#slider').innerfade({  speed: 500, timeout: 5000, type: 'sequence', containerheight: '287' });
	
	 
	$('#slider')
	.after('<div class="navigationSliderBox"><span class="navigationSlider">')
	.cycle({ 
			    fx:      'fade', 
				pause:1,
				next:'#slider',
			    speed:    1000, 
			    timeout:  5000,
				//height: 
				//easing: 'easeOutExpo',
				//before:   onBefore,
				pager:  '.navigationSlider',
				requeueOnImageNotLoaded: true,
				//pagerAnchorBuilder: function(index, DOMelement){
				//	return '<a href="#"></a>';
				//}
			})
	.parent().css('position','relative').hover(function(){
		$(".navigationSliderBox").fadeIn("fast");
	}, function(){
		$(".navigationSliderBox").fadeOut("fast");
	})
	
	
	$('#slider3')
	.after('<div class="navigationSliderBox"><span class="navigationSlider">')
	.cycle({ 
			    fx:      'fade', 
			    speed:    1000, 
			    timeout:  5000,
				height: '360',
				//easing: 'easeOutExpo',
				//before:   onBefore,
				pager:  '.navigationSlider',
				requeueOnImageNotLoaded: true,
				//pagerAnchorBuilder: function(index, DOMelement){
				//	return '<a href="#"></a>';
				//}
			})
	.parent().css('position','relative').hover(function(){
		$(".navigationSliderBox").fadeIn("fast");
	}, function(){
		$(".navigationSliderBox").fadeOut("fast");
	})
	
	
	//$('#slider2').innerfade({  speed: 500, timeout: 4000, animationtype: 'slide2', type: 'sequence', containerheight: '193', containerwidth: '263' }); 
	//$('#slider3').innerfade({  speed: 500, timeout: 5000, type: 'sequence', containerheight: '360' }); 
	
	//irrelevant start
	$liste=$(".teaserD .textBox");
	$liste.find("ul li div").appendTo(".teaserD .imageBox").hide().end()
	.hoverIntent({
		sensitivity: 3, 
		interval: 400, 
		out: toggleIrrelevantAd, 
		timeout: 400, 
		over: nothing})
	.find("li a").hoverIntent({
		sensitivity: 3, 
		interval: 200, 
		over: toggleIrrelevantItems, 
		timeout: 100, 
		out: nothing
	})


	$images=$(".teaserD .imageBox div");
	$active=0;
	$last=0;

	function toggleIrrelevantItems(){ 
		$last=$active;
		$active=$liste.find("li a").index(this)+1;
		if($last!=$active){
			//console.log($liste.find("li a").eq($active-1));
			//$liste.find("li a").eq($active-1).animate({ background: "#000"})
			//$liste.find("li").eq($last-1).find("h2").slideUp();
			
			$images.eq($last).fadeOut("fast");
			$images.eq($active).fadeIn("fast");
		}
	}
	
	function toggleIrrelevantAd(){
		$images.eq(0).fadeIn("slow");
		$images.eq($active).fadeOut("slow");
		$last=$active;
		$active=0;
		

	}
	
	// comments
	function showCommentForm(){
		$('.storyBox').animate({"opacity": "0.4"});
		$('#formComment').slideToggle();
		$("#respond").css('visibility', 'hidden')
		return false;
	}
	$('#respond').show();
	$('#formComment').hide().addClass('javaCommentForm');
	if($('#formComment .error')[0]) { showCommentForm(); }
	$("#respond").click(showCommentForm);
	$('#closeComment').show().click(function(){
		$('.storyBox').animate({"opacity": "1"});
		$('#formComment').slideToggle();
		$('#respond').fadeIn().css('visibility', 'visible');
		return false;
	})
	
	$commentsBox= $('#commentsBox');
	$commentsBox.hide();	
	
	 $('#showComment').show().toggle(
          function(event) {
            $commentsBox.slideToggle()
			$(this).html("hide comments")
          },
          function(event) {
            $commentsBox.slideToggle()
			$(this).html("show comments")
          }
        );	






	// LOTV
	$('.flash_box_link').fancyZoom({directory: "files/homepage/fancy"});
	/*$('.contentPortal .teaserE .addBoxA a').attr('href','#flash_box').click(function(){
		lotvVideo='nike.mp4';
		lotvHeight=352;
		lotvWidth=629;

	}).fancyZoom({directory: "files/homepage/fancy"});
	//	$('#small_box_link').fancyZoom();
	*/



	
});


//dimScreen()
//by Brandon Goldman
jQuery.extend({
    //dims the screen
    dimScreen: function(speed, opacity, callback) {
        if(jQuery('#__dimScreen').size() > 0) return;
        
        if(typeof speed == 'function') {
            callback = speed;
            speed = null;
        }

        if(typeof opacity == 'function') {
            callback = opacity;
            opacity = null;
        }

        if(speed < 1) {
            var placeholder = opacity;
            opacity = speed;
            speed = placeholder;
        }
        
        if(opacity >= 1) {
            var placeholder = speed;
            speed = opacity;
            opacity = placeholder;
        }

        speed = (speed > 0) ? speed : 500;
        opacity = (opacity > 0) ? opacity : 0.5;
        return jQuery('<div></div>').attr({
                id: '__dimScreen'
                ,fade_opacity: opacity
                ,speed: speed
            }).css({
            background: '#000'
            ,height: $(document).height()
            ,left: '0px'
            ,opacity: 0
            ,position: 'absolute'
            ,top: '0px'
            ,width: '100%'
            ,zIndex: 999
        }).appendTo(document.body).fadeTo(0,opacity);

    },
    
    //stops current dimming of the screen
    dimScreenStop: function(callback) {
        var x = jQuery('#__dimScreen');
        var opacity = x.attr('fade_opacity');
        var speed = x.attr('speed');
        x.fadeOut(0, function() {
            x.remove();
            if(typeof callback == 'function') callback();
        });
    }
});




function popitup(destination,win_name,width,height, withScrollbar, toolBar) {
	if (popitup.arguments.length < 5) withScrollbar = true;			// default ist mit scrollbars
	var toolBar = "no";
	
	var x=( (screen.width - width ) / 2 );
	var y=( (screen.height - height ) / 2 );
	
	if (BrowserDetect.browser=="Explorer" && BrowserDetect.version=="6") {
		var height = height + 11;
		var width = width + 8;
	}
	
	if (BrowserDetect.browser=="Explorer" && BrowserDetect.version=="7") {
		var height = height + 60;
		var width = width + 10;
	}
	
	if (BrowserDetect.browser=="Opera") {
		var height = height + 14;
	}
	
	if (BrowserDetect.browser=="Firefox" && BrowserDetect.version=="2" && BrowserDetect.OS=="Windows") {
		var height = height + 32;
		var width = width + 8;
	}
	
	if (BrowserDetect.browser=="Firefox" && BrowserDetect.version=="3" && BrowserDetect.OS=="Windows") {
		var height = height + 62;
		var width = width + 8;
	}
	
	if (BrowserDetect.browser=="Firefox" && BrowserDetect.version=="3" && BrowserDetect.OS=="Mac") {
		var height = height + 47;
	}
	
	
	
	
	
	
	if (width==0 ||  height == 0)
	{
		fs = window.open (destination,win_name);
	} else {
		if (withScrollbar){
			fs = window.open (destination,win_name,'width=' + width + ',height=' + height + ', left=' + x + ', top=' + y + ',resizable=yes,scrollbars=yes,toolbar=' +toolBar + ',status=no,directories=no,menuebar=no,location=tabelle');
		} else {
			fs = window.open (destination,win_name,'width=' + width + ',height=' + height + ', left=' + x + ', top=' + y + ',resizable=yes,scrollbars=no,toolbar=' +toolBar + ',status=no,directories=no,menuebar=no,location=tabelle');
		}
		fs.resizeTo(width,height);
	}
	fs.focus();
}




var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();




