$(document).ready(function(){  
	
	// NAVIGATION
	
	if($.browser.msie) {
		
		if($.browser.version.substr(0,3) == "6.0" || $.browser.version.substr(0,3) == "5.5") {	
			if (String(window.location).search(/imprint.threeview.+/) == -1) {	
				if(String(window.location).search(/.com.+/) != -1) { location.href = "http://imprint.threeview.com/index.php?browser=nosupport"; }
				else { location.href = "http://imprint.threeview.de/index.php?browser=nosupport"; }
			}
		} else if($.browser.version.substr(0,3) == "7.0") {			
					
			if (String(window.location).search(/events.threeview.+/) == -1 &&
				String(window.location).search(/imprint.threeview.+/) == -1 &&
				String(window.location).search(/goodkarma.threeview.+/) == -1 &&
				String(window.location).search(/www.threeview.+/) == -1 &&
				String(window.location).search(/socialmedia.threeview.+/) == -1 &&
				String(window.location).search(/5years.threeview.+/) == -1 && 
				String(window.location).search(/blog.threeview.+/) == -1 &&
				String(window.location).search(/staging.threeview.+/) == -1) {	
						
				if(String(window.location).search(/.com.+/) != -1) { location.href = "http://imprint.threeview.com/index.php?browser=nosupport"; }
				else { location.href = "http://imprint.threeview.de/index.php?browser=nosupport"; }
			}
		}		
	}
	
	$.getScript("http://www.threeview.com/include/js/jquery-backgroundPosition.js");
	$.getScript("http://www.threeview.com/include/js/jquery.color.js");
		
	var 		
		_strHREF,	
        _src,
        _srcHover;      
		
	if($.browser.msie) 	$("img.hover").hide();	
	
	_strHREF = String(window.location);
	$('#main_nav ul li').each(function(i){
		if(_strHREF.search($(this).attr('class')) != -1){			
			if(i != 0) {
				if($("#main_nav ul li").index(this) != 1) $(this).insertBefore($(this).parent('ul li:eq(1)'));		 
			  	$(this).addClass('active');	
			  	
			  	if($.browser.msie) {
				  	_src = $("img.nohover",this).attr("src");       
				  	_srcHover = _src.substr(0, _src.lastIndexOf(".")) + "_hover" + _src.substr(_src.lastIndexOf("."));                 
				  	$("img.nohover", this).attr("src",_srcHover);    
			  	} else $("img.nohover",this).hide();
			} 
		} else if(!$(this).hasClass("logo")) { 
			$(this).hide();
			$(this).addClass("sub");
		}
		if(i == $("#main_nav ul li").length-1) {
			$("#main_nav").fadeIn();
		}
  	});

			
	$("#nav_background").hide();
		
	$("#main_nav").hover(function() {	
		if($.browser.msie) {	
			$("#nav_background").show();
			$("ul li.sub", this).show();	
		} else {
			$("#nav_background").stop(false, true).fadeIn("slow");	
			$("ul li.sub", this).stop(false, true).fadeIn("slow");	
		}	
	}, function() {
		if($.browser.msie) {	
			$("#nav_background").hide();
			$("ul li.sub", this).hide();	
		} else {								 
			$("#nav_background").stop(false, true).fadeOut("slow");
			$("ul li.sub", this).stop(false, true).fadeOut("slow");	
		}					
	});
	
	$("#main_nav li").hover(function() {  
		if(!$(this).hasClass("active") && !$(this).hasClass("logo")) {
			if($.browser.msie) {
				_src = $("img.nohover",this).attr("src");       				                    
				_srcHover = _src.substr(0, _src.lastIndexOf(".")) + "_hover" + _src.substr(_src.lastIndexOf("."));
				$("img.nohover", this).attr("src",_srcHover);      			
				
				$("a",this).stop(false, true).css({ backgroundPosition:"0 -350px"}); 		
			
			} else {	
				$("img.nohover",this).stop(false, true).fadeOut(600);
				$("p",this).stop(false, true).animate({ color: "#d6d098"}, 300);
				$("a",this).stop(false, true).animate({ backgroundPosition:"(0 -350px)"}, {duration:400});
			}
		}
	}, function() {  
	  	if(!$(this).hasClass("active") && !$(this).hasClass("logo")) {
			
			if($.browser.msie) {
				$("img.nohover", this).attr("src",_src); 								
				$("a",this).stop(false, true).css({ backgroundPosition:"0 0px"}); 
			} else {
				
				$("img.nohover",this).stop(false, true).fadeIn(600);
				$("p",this).stop(false, true).animate({ color: "#4a4834"}, 300); 				
				$("a",this).stop(false, true).animate({ backgroundPosition:"(0 0)"}, {duration:500});  
			}
		}		
	}); 
	
	// FOOTER
	
	var
		newlink,
		pos;		
	
	pos = String(window.location).search(/.com.+/);			
	if (pos == -1) $("a.language").html("<strong>English</strong>");
	else $("a.language").html("<strong>Deutsch</strong>");
		 
	$("a.language").click(function(event) {  				
		event.preventDefault();				
		if (pos == -1) {
			if (String(window.location).search(/news.threeview.+/) != -1) {				
				newlink = "http://news.threeview.com";
			} else {
				newlink = String(window.location).replace('.de', '.com');
			}
		} else {
			if (String(window.location).search(/news.threeview.+/) != -1) {				
				newlink = "http://news.threeview.de";
			} else {
				newlink = String(window.location).replace('.com', '.de');
			}		
		} 
		window.location = newlink;		       	
    });	
		
	$("a.share_facebook").click(function(event) {		
		event.preventDefault();	
		window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(location.href)+'&t='+encodeURIComponent(document.title),' sharer', 'toolbar=0, status=0, width=626, height=436'); 		
	});
	$("a.share_twitter").click(function(event) {
		event.preventDefault();	
		window.open('http://twitter.com/home?status=Currently reading '+encodeURIComponent(location.href)+'&t='+encodeURIComponent(document.title),' sharer', 'toolbar=0, status=0, width=800, height=436'); 		
	});
	$("a.share_add").click(function(event) {
		event.preventDefault();	 
		window.open('http://www.addtoany.com/share_save?linkurl='+encodeURIComponent(location.href)+'&linkname='+encodeURIComponent(document.title),' sharer', 'toolbar=0, status=0, width=1000, height=436');
	});
	
});


