﻿$(document).ready(function() {
						   
	$("img.email").each(function(){
					 
		var attr_ = $(this).attr("src");
		var d = attr_.lastIndexOf('.');
		var mail =  attr_.substring(attr_.lastIndexOf('/') + 1, d < 0 ? attr_.length : d);
		mail = mail.replace('_','.');
		
		// Also consider email-image with light-font, replace buzzword in name.
		mail = mail.replace('_light','');
		
		$(this).wrap('<a href="mailto:'+ mail +'@inova-ch.com" />');
	});					   
	
	$("img.email-block").each(function(){
					 
		var attr_ = $(this).attr("src");
		var d = attr_.lastIndexOf('.');
		var mail =  attr_.substring(attr_.lastIndexOf('/') + 1, d < 0 ? attr_.length : d);
		mail = mail.replace('_','.');
		
		// Also consider email-image with light-font, replace buzzword in name.
		mail = mail.replace('_light','');
		
		//$(this).wrap('<span class="hidden">.</span><a href="mailto:'+ mail +'@inova-ch.com" />');
		$(this).wrap('<a href="mailto:'+ mail +'@inova-ch.com" class="maillink" />');
		//$(this).wrap('<span class="hidden">.</span><a href="mailto:'+ mail +'@inova-ch.com" />');
	});	
	
	/* Make Slider sliding */					   
						   
	if($("div.scrollable").size() > 0) {
	
	$("div.scrollable").scrollable({
		size:1,
		onStart: function() {
			var nextPage_ = $("a.nextPage.browse.right");
			if(this.getPageIndex() >= 4) {
				nextPage_.hide();
			}
			else {
				if(nextPage_.css("display") == "none") {
					nextPage_.show();
				}
			}
		},
		onSeek:  function() {
			var active_ = $("div.textbox.active");
			showBox(this.getIndex());
		},
		api: true
	}).seekTo(2);
	
	}
	
	function showBox(firstEle_) {
		
		
		$("div.image a").mouseover(function(){
				var id_ = $(this).attr("id");	
				$("div.textbox").hide().removeClass("active");
				$("div.textbox[rel=" + id_ + "]").show().addClass("active");
				
				var current_ = $("div.items div.image a").index($(this));

				var curarrow_ = current_-firstEle_;
				
				//console.log(curarrow_);
				$("div.textarrow div").hide();
				$("div.textarrow div").eq(curarrow_).show();
			});	
		
	}
	
	$("div.textbox").each(function(){
		var ta = $(this);

			// two rows of text
		if(ta.height() > 30 && ta.height() < 40) {
			ta.addClass("double-row");
		}
			// three rows of text
		else if(ta.height() > 50) {
			ta.addClass("triple-row");
		}
		
	});
	
	
	$("body").mouseover(function(e){
		var node = null;
	
		if(e.srcElement) {
			node = e.srcElement;	
		}
		else if(e.target){
			node = e.target;
		}
	
		if($(node).parents("div.scrollable").size() !== 1) {
				$("div.textbox").hide().removeClass("active");	
				$("div.textarrow div").hide();
		}
	});
	
	(function(){

		function getRequestParam(key) {
		  var requestParams = decodeURI(window.location.search), i, temp, list;
		  
		  if(requestParams !== null){
		      requestParams = requestParams.substr(1);
		      list = requestParams.split("&");
		      for(i=0; i < list.length; i++){
		          temp = list[i].split("=");  
		          if(key === temp[0]) {
		              return temp[1];
		          }
		      }
		  }
		  return null;
		}
		
		function getLanguage() {
			var language = "en";
			
			if(window.location.href.match(/\/deu\//)) {
				language = "de";
			}
			
			return language;
		}
		
		var language = getLanguage(), category = "Unspezifizierte_Seite_" + language, pagetype = getRequestParam("option");
		if($("div.productslider").size() === 1) {
			category = "Homepage_";
		}
		else if(pagetype && pagetype === "reports") {
			category = "Projektberichte_" + language;
		}
		else if(pagetype && pagetype === "com_inova_media_releases") {
			category = "Presse_und_News_" + language;
		}
		
	  $("td.content-area a").each(function(){
	  	var link = $(this), trackingName, onclick = link.attr("onclick");
	  	
	  	if(link.attr("href")) {
	  		trackingName = link.attr("href").match(/[^\/]*\.pdf$/i);
	  	}
	  	
	  	if(trackingName) {
	  		link.click(function(){
	  			_gaq.push(['_trackEvent', category, trackingName[0], 'clicked']);
	  		});
	  	}
	  	else if(onclick) {
	  		onclick = onclick.toString();
	  		if(onclick.match(/print=print/)) {
		  		link.click(function(){
		  			_gaq.push(['_trackEvent', 'PrintIcon', 'clicked']);
		  		});
		  	}
		  	else if(onclick.match(/emailfriend/)) {
		  		link.click(function(){
		  			_gaq.push(['_trackEvent', 'EmailToFriend', 'clicked']);
		  		});
		  	}	  	
	  	}
	  });
	
	})();
	
});
