/**
 **************************************************
 * Javascript USERFUNCTIONS
 * userfunctions.js
 *
 * @author: HDNET GmbH & Co. KG
 * @version: 2.0
 * @updated: 2011-03-11 (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]" title="Klick mich!"><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({
			parent:false,
			mouseEvent:'hover',	   
			classHover:'hover'	   			   
		}, hoverOptions);
		
		if(hoverSettings.parent == true) {
			$(this).hover(
				function(){$(this).parent().addClass(hoverSettings.classHover);},
				function(){$(this).parent().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();


/* *** GLOBAL domReady begin *** */
$(document).ready(function() {
	
	/* 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,
			event:'mouseover'
		});
	} else {
		$('.tabContent ul').tabs('> .tabPanel',{
			tabs:'li',
			current:'act',
			effect:'fade',
			fadeOutSpeed:'fast',
			rotate:true,
			event:'mouseover'
		});
	}
	
	$('.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').hoverSwitch();
	 
	 $('textarea').hoverSwitch({
	 	parent:true
	 });

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

	
	/* Initalize the customized tooltip
	 * via tips.js
	 */
	$('.referenceTeaser .media a, .referenceTeaser .content, .navBrowse a[title], .referenceImages ul li, .tabContent a, .images .detail .item a').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'});
		$(this).find('.media').css({'background-position':'top right'})
	}, function() {
		$(this).find('.media a div.mask').fadeIn('fast');
		$(this).css({'background-color':'#eeeeee'});
		$(this).find('.media').css({'background-position':'top left'})
	});


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