/**
 **************************************************
 * Javascript USERFUNCTIONS
 * userfunctions.js
 *
 * @author: HDNET GmbH & Co. KG
 * @version: 1.5
 * @updated: 2010-08-17 (AH)
 **************************************************
**/




/**
 **************************************************
 TYPO3 JAVASCRIPTS
 *
 * @description: scripts needed from typo3
 **************************************************
**/
var browserName=navigator.appName;var browserVer=parseInt(navigator.appVersion);var version="";var msie4=(browserName=="Microsoft Internet Explorer"&&browserVer>=4);if((browserName=="Netscape"&&browserVer>=3)||msie4||browserName=="Konqueror"||browserName=="Opera"){version="n3";}else{version="n2";}
function blurLink(theObject){if(msie4){theObject.blur();}}
function decryptCharcode(n,start,end,offset){n=n+offset;if(offset>0&&n>end){n=start+(n-end-1);}else if(offset<0&&n<start){n=end-(start-n-1);}
return String.fromCharCode(n);}
function decryptString(enc,offset){var dec="";var len=enc.length;for(var i=0;i<len;i++){var n=enc.charCodeAt(i);if(n>=0x2B&&n<=0x3A){dec+=decryptCharcode(n,0x2B,0x3A,offset);}else if(n>=0x40&&n<=0x5A){dec+=decryptCharcode(n,0x40,0x5A,offset);}else if(n>=0x61&&n<=0x7A){dec+=decryptCharcode(n,0x61,0x7A,offset);}else{dec+=enc.charAt(i);}}
return dec;}
function linkTo_UnCryptMailto(s){location.href=decryptString(s,3);}




/**
 **************************************************
 JQUERY EXTEND
 *
 * @description: extend the general jquery with the
 * following functions
 **************************************************
**/
$.fn.extend({


	/* IMAGES
	 * @description: displays thumbnails 
	 * and switch the detail image and its title
	 */
	images: function(imageOptions) {
		var imageOptions = imageOptions;
									   
		// Define the settings		   
		var imageSettings = $.extend({	   
			wrapper : 'div.images',
			detailClass : 'detail',	   
			detailItemClass : 'item',  
			detailIdPrefix : 'i',	   
			anchorIdPrefix : 'a',	   
			actClass : 'act',		   
			delay : 500,			   
			fadeTime : 300,			   
			speed : 900				   
		}, imageOptions);			   
									   
		$(imageSettings.wrapper).ready(function() {
									   
			// Find the trigger elements
			var aObject = $(imageSettings.wrapper+' ul').find('li').find('a');
									   
			// For each trigger element...
			$(aObject).each(function(i) {
				// Set an identifier   
				$(this).attr('id', imageSettings.anchorIdPrefix+i);
									   
				var eImage = $(this).attr('href');
								
				var eBoxImage = $(this).parent().find('img.boxImage').attr('src');
									   
				// Insert an detail element with the params from the trigger element
				$(imageSettings.wrapper+' div.'+imageSettings.detailClass).append('<div class="'+imageSettings.detailItemClass+'" id="'+imageSettings.detailIdPrefix+i+'"><a href="'+eBoxImage+'" rel="lightbox[presentlb1337]"><img src="'+eImage+'" /></a></div>');
			});						   
			
			$(imageSettings.wrapper+' ul li:last').addClass('last');
								   
			// Displays the first detail image and the first trigger to act
			$(imageSettings.wrapper+' div.'+imageSettings.detailClass).find('div.'+imageSettings.detailItemClass+':first').fadeIn(imageSettings.fadeTime);
			$(imageSettings.wrapper+' ul li:first').find('div.act').fadeOut(imageSettings.fadeTime);
									   
									   
			$(imageSettings.wrapper+' ul li').each(function(i) {
				// Switch the detail content to the correct content shown in the triggerd element
				
	//			$(this).onMakeActive(function(){
	//				alert('get active');
	//			});
				
				var eTitle = $(this).find('a').attr('title');
				
				$(this).click(function() {
					// Set the act status
					$(imageSettings.wrapper+' ul li').find('div.act').fadeIn(imageSettings.fadeTime);
					$(this).find('div.act').fadeOut(imageSettings.fadeTime/5);
							   
				    // Get id from trigger element
		    		var id = $(this).find('a').attr('id');
									   
					// Set for id only the number
					var idIndex = id.replace('a','');
									   
				    // Set id from event element with the trigger id
		    		var idDetail = imageSettings.detailIdPrefix+idIndex;
									   
		    		// Toggle the event elements with fadein
				    $(imageSettings.wrapper+' div.'+imageSettings.detailClass+' div.'+imageSettings.detailItemClass).fadeOut(imageSettings.fadeTime).removeClass(imageSettings.actClass);
				    $(imageSettings.wrapper+' div#'+idDetail).fadeIn(imageSettings.fadeTime);
									   
					return false;	   
				});					   
				
				this.title = eTitle;

				
				//$(this).find('a').attr('title').val() = eTitle;
									   
				// Set the hover status
				$(this).hover(function(){
					$(this).find('div.hover').fadeIn(imageSettings.fadeTime/5);
				}, function() {		   
					$(this).find('div.hover').fadeOut(imageSettings.fadeTime/10);
				});					   
				
			});						   
									   
		});							   
	},							   
	

	/* HOVER-SWITCH
 	 * @description: add an remove the pseudo-class
 	 * hover to element which are no links
	 */
	hoverSwitch: function(hoverOptions) {
		var hoverOptions = hoverOptions;
	
		// Define the settings		   
		var hoverSettings = $.extend({	   
			mouseEvent : 'hover',
			classHover : 'hover'	   			   
		}, hoverOptions);

		    
		if(hoverSettings.mouseEvent == 'focus') {
		    $(this).focus(function(){
		    	$(this).addClass(hoverSettings.classHover);
		    }).blur(function() {		   
		    	$(this).removeClass(hoverSettings.classHover);
		    });
		} else if(hoverSettings.mouseEvent == 'mouseenter') {
		    $(this).mouseenter(function(event) {
		    	$(this).addClass(hoverSettings.classHover);
		    });
		    $(this).mouseleave(function(event) {
		    	$(this).removeClass(hoverSettings.classHover);
		    });
		} else {
		    $(this).hover(function(){
		    	$(this).addClass(hoverSettings.classHover);
		    }, function() {			   
		    	$(this).removeClass(hoverSettings.classHover);
		    });
		}
	}


});




/**
 **************************************************
 GLOBAL DEFINITIONS
 *
 * @description: global domready function for all functions
 * run jQuery in noConflict mode
 **************************************************
**/
/* no conflict mode - it works besides prototype */
//var $ = jQuery.noConflict();

/**
 * Try to animate the cover-flow
 * @author Michael Feinbier
 * @param  {}
 */
HDNET = {};
HDNET.imageflow = {
	onClick : function() {
		var url = this.url;
		$('#contentArea').slideUp('slow',function() {
			$('#contentArea').load(url + " #contentArea > div",function() {
				//Cufon again
				Cufon.replace('#contentArea h1',{
					fontFamily:'light',
					hover:true
				});
				
				$('#contentArea').slideDown();
			});
		});
	}
};

/* *** GLOBAL domReady begin *** */
$(document).ready(function() {
	
	/* Replacing the first nav-level, the h1 of media and
	 * all h1 in the contentArea with a nice font
	 */
	pf = navigator.platform;

	if(pf != 'iPhone') {
		if(pf != 'iPod') {
			Cufon.replace('ul#navMain>li>a',{
				fontFamily:'bold_cond',
				hover:true
			});
			
			Cufon.replace('.media h1',{
				fontFamily:'thin',
				textShadow:'1px 2px rgba(51, 51, 51, 0.2)',
				hover:true
			});
			
			Cufon.replace('#contentArea h1',{
				fontFamily:'light',
				hover:true
			});
						
			Cufon.replace('#contentArea h1.refHeader',{
				fontFamily:'thin',
				hover:true
			});

			Cufon.replace('.referenceTeaser h2',{
				fontFamily:'bold_cond',
				hover:true
			});
		}
	}
	
	
	/* Tabs in Media Area shown with slideshow plugin
	 * and changing hover class for the tab nav
	 */	
	if ($.browser.msie && $.browser.version*1 < 8) {
		$('.tabContent ul').tabs('> .tabPanel',{
			tabs:'li',
			current:'act',
			rotate:true
		}).slideshow({
			autoplay:true,
			interval:12000
		});
	} else {
		$('.tabContent ul').tabs('> .tabPanel',{
			tabs:'li',
			current:'act',
			effect:'fade',
			fadeOutSpeed:'slow',
			rotate:true
		}).slideshow({
			autoplay:true,
			interval:12000
		});
	}
	
	$('.tabContent ul li').hoverSwitch();
	

	/* Accordion in the content
	 */
	$('.accordion').tabs('div',{
		initialIndex:-1,
		tabs:'h3',
		effect:'slide'
	});

	
	/* Inputs are getting a focus class
	 */
	 $('input.text, textarea').hoverSwitch({
	 	mouseEvent:'focus',
	 	classHover:'hover'
	 });

	
	/* Image gallery with thumbnails
	 * for the reference page
	 */
	$('div.images').images();

	
	
	/* Coverflow for team and references
	 * with dynamic reflection via php
	 * set hover classes for nav buttons
	 */
	/*var team = new ImageFlow();
	team.init({
		aspectRatio:1.964,
		buttons:true,
        captions:false,
		circular:true,
		imageCursor:'pointer',
		ImageFlowID:'team',
		imageFocusMax:3,
		imagePath:'../../../',
		opacity:true,
		percentLandscape:100,            
		percentOther:80,
        reflections:true, 
        reflectionP:0.5,
        reflectionPNG:true, 
   		reflectPath:'/fileadmin/templates/php/', 
        slider:true,
        xStep:88
    });
    
    
	var references = new ImageFlow();
	references.init({
		aspectRatio:1.964,
		buttons:true,
        captions:false,
		circular:true,
		imageCursor:'pointer',
		ImageFlowID:'references',
		imageFocusMax:2,
		imagePath:'../../../',
		opacity:true,
		percentLandscape:130,            
		percentOther:100,
        reflections:true, 
        reflectionP:0.5,
        reflectionPNG:true, 
   		reflectPath:'/fileadmin/templates/php/', 
        slider:true,
        xStep:100
    });*/

	
	$('.flowArea .previous').hoverSwitch({
		mouseEvent:'mouseenter',
		classHover:'preHov'
	});
	
	$('.flowArea .next').hoverSwitch({
		mouseEvent:'mouseenter',
		classHover:'nextHov'
	});
	
	
	/* RSS Feed hover effect */
	$('.rss .item').hover(function() {
		var link = $(this).find('h2').find('a').attr('href');
		$(this).find('.text').animate({'top':'0'},0).addClass('hover').click(function(){window.location = link;});
		$(this).find('p').show();
	}, function(){
		$(this).find('p').hide();
		$(this).find('.text').animate({'top':'+=140px'},0).removeClass('hover');
	});
	
	
	/* Initalize the customized tooltip
	 * via tips.js
	 *//*
	$('#contentArea a[title]').tipsy({
		gravity:'s',
		live: true
	});*/
	
	
	$('.referenceTeaser .media a, .referenceTeaser .content, .navBrowse a[title], .referenceImages ul li').tooltip({
		track:true, 
    	delay:250, 
		showURL:false, 
		opacity:1, 
		fixPNG:true,
		top:-25,
		left:10
	});
	
	$('#tooltip').bgiframe();
	
	
	/* Hover effect on the reference page
	 */
	$('.referenceTeaser').hover(function() {
		$(this).find('.media a div.mask').fadeOut('fast');
		$(this).css({'background-color':'#f5f5f5'});
	}, function() {
		$(this).find('.media a div.mask').fadeIn('fast');
		$(this).css({'background-color':'#eeeeee'});
	});


/* *** GLOBAL domready end *** */
});