﻿
function trackEvent(el,type,o){

	delete s.events; 

	for(var i=0; i<=50; i++){
		delete s['eVar'+i];
		delete s['prop'+i];
	}
	
	for(key in o){
		s[key] = o[key];
	}

	s.pageName = pageNamePrefix+o.pageName;

	if(type=='page'){
		void(s.t());
	}else{
		
		var t = 'o';
		if(type=='download'){t='d'; el=false;}
		if(type=='click'){t='o'; el=false;}
		if(type=='link'){t='o';}
		if(type=='exit'){t='e';}
		if(type=='other'){t='o';}
		void(s.tl(el,t,s.pageName));
	
	}
	try{
		debugOmniture(s,type,s.pageName)
	}catch(e){}
}

jQuery.fn.trackEvent = function(t,o){ $(this).click(function(){trackEvent($(this)[0],t,o)}) }


$(function(){ 

	$(".trackevent-search-note").trackEvent('click',{pageName:'Search:Note',channel:'Search'});

	$(".trackevent-product-events").trackEvent('page',{pageName:'Product:Events',channel:'Product' });
	$(".trackevent-product-services").trackEvent('page',{pageName:'Product:Services',channel:'Product'});
	$(".trackevent-product-dates").trackEvent('page',{pageName:'Product:Dates',channel:'Product'});
	$(".trackevent-product-countryinfos").trackEvent('page',{pageName:'Product:CountryInfos',channel:'Product'});
	$(".trackevent-product-gallery a").trackEvent('page',{pageName:'Product:Gallery',channel:'Product'});
	$(".trackevent-product-map>*").trackEvent('page',{pageName:'Product:Map',channel:'Product'});
	$(".trackevent-product-print").trackEvent('page',{pageName:'Product:Print',channel:'Product'});
	$(".trackevent-product-recommend").trackEvent('page',{pageName:'Product:Recommend',channel:'Product'});

	$(".trackevent-press-release").trackEvent('page',{pageName:'Press:Release',channel:'Press'});
	$(".trackevent-press-comments").trackEvent('page',{pageName:'Press:Comments',channel:'Press'});
	$(".trackevent-press-pictures").trackEvent('page',{pageName:'Press:Pictures',channel:'Press'});

	
	$(".trackevent-notepad-addremove").click(function(){
		trackEvent(false, 'click', {
			pageName: $(this).hasClass('unchecked') ? 'Notepad:Remove' : 'Notepad:Add', //umgekehrte Logik, weil class zu erst geändert wird
			channel: 'Notepad', 
			products: ';'+$(this).attr('id').split('-')[1]
		}); 
	});
	
	$(".trackevent-notepad-clear").click(function(){
		trackEvent(false, 'click', {pageName: 'Notepad:Clear', channel: 'Notepad'}); 
	});
	
	$(".trackevent-compare-addremove").click(function(){
		trackEvent(false, 'click', {
			pageName: $(this).hasClass('unchecked') ? 'Compare:Remove' : 'Compare:Add', //umgekehrte Logik, weil class zu erst geändert wird
			channel: 'Compare', 
			products: ';'+$(this).attr('id').split('-')[1] 
		}); 
	});
	
	$(".trackevent-compare-remove").click(function(){
		trackEvent(false, 'click', {pageName: 'Compare:Remove',	channel: 'Compare',	products: ';'+$(this).attr('rel')}); 
	});
	
	$(".trackevent-compare-clear").click(function(){
		trackEvent(false, 'click', {pageName: 'Compare:Clear',	channel: 'Compare'}); 
	});
	
	
	$(".trackevent-tuv").trackEvent('page',{pageName:'TÜV',channel:'TÜV'});
	

	//$(".item").trackEvent('click',{pageName:'TEST',channel:'TEST'});
	//$(".trackevent-").trackEvent('',{pageName:'',channel:''});

	
	/*
	$("input").click(function(){ alert('return false'); this.blur(); return false });
	$("input").bind('click',function(){ alert('bind'); })
	$("input").live('click',function(){ alert('live'); })
	*/

	

	// facebook header
	$(".event-header-fb").click(function(){
		//trackEvent(false, 'click', {pageName:'Home:FaceBook:FanSite',channel:'Home',events:'event42'});
		trackEvent(false, 'click', {events:'event42'});
	});
	
	// facebook product
	try{
		
		FB.Event.subscribe('edge.create',  function(response) {
			//alert(response)
			//trackEvent(false,'click',{pageName:'Product:Like',channel:'Product',events:'event32'}); 
			trackEvent(false,'click',{events:'event32'});
		});
		
		FB.Event.subscribe('message.send',  function(response) {
			//alert(response)
			//trackEvent(false,'click',{pageName:'Product:Share',channel:'Product',events:'event32'});
			trackEvent(false,'click',{events:'event32'}); 
		});

	}catch(e){}

	
	// google plus header
	$(".event-header-plus-one").click(function(){
		//trackEvent(false, 'click', {pageName:'Home:Google:Plus',channel:'Home',events:'event40'});
		trackEvent(false, 'click', {events:'event40'}); 
	});

	// google plus product
	$('a.event-product-plus-one').each(function(){
		var button = this;
		var link= $(this).attr('href');
		gapi.plusone.render(button,{
			size: 'medium',
			annotation: 'bubble',
			href: link,
			callback: function(obj){
				console.log(obj)
				if(obj.state == 'on'){
					//trackEvent(false,'click',{pageName:'Product:Like:Google:Plus:On',channel:'Product',events:'event41'});
					trackEvent(false,'click',{events:'event41'});
				}else{
					
				}
			}
		});
	})

	
});



