var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera",
			versionSearch: "Version"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

function initProductList() {
	var productList = jQuery('.product-list');

	if( productList.length == 0 ) return;

	//backup original Text in red box
	jQuery('#page-summary').first('p').data('originalHtml', jQuery('#page-summary').first('p').html());

	//insert "Details" Label
	jQuery('#page-home .product-link').before('<span class="label-details">Details</span>');

	// Klick Event - Link auf die ganze Kachel umlegen
	jQuery('.product-item', productList).click(
			function() {
				window.location.href = $('a.product-link', this).attr('href');
			}
	);


	jQuery('.product-item', productList).hover(
			function () {
				jQuery(this).addClass('ishoverselected');

if (BrowserDetect.browser=='Explorer') {
	jQuery('.product-item:not(.ishoverselected) .slayer', productList).stop(true, true).addClass('not_ishoverselected');
}
else {
	jQuery('.product-item:not(.ishoverselected) .slayer', productList).stop(true, true).animate({opacity : 0.6, filter: 'alpha(opacity=60)'}, 'slow');
}
				jQuery('.product-item.ishoverselected', productList).children('.product-image').stop(true, true).animate({top: '-15px'}, 'fast');

				jQuery(this).children('.product-link').stop(true, true).animate({opacity: 1, top: '220px'}, 'slow');
				jQuery(this).children('.label-details').stop(true, true).fadeOut('fast');
				jQuery(this).children('.product-family').stop(true, true).fadeOut('fast');
				jQuery(this).children('.product-version').stop(true, true).fadeOut('fast');

				jQuery('#page-summary').first('p').html(jQuery('.product-description', this).html());
		  	},
			function () {
				jQuery(this).children('.product-link').stop(true, true).animate({opacity: 0, top: '160px'}, 'fast');
				jQuery(this).children('.label-details').stop(true, true).fadeIn('fast');
				jQuery(this).children('.product-family').stop(true, true).fadeIn('fast');
				jQuery(this).children('.product-version').stop(true, true).fadeIn('fast');


if (BrowserDetect.browser=='Explorer') {
	jQuery('.product-item:not(.ishoverselected) .slayer', productList).stop(true, true).removeClass('not_ishoverselected');
}
else {
	jQuery('.product-item:not(.ishoverselected) .slayer', productList).stop(true, true).animate({opacity : 0, filter: 'alpha(opacity=0)'}, 'slow');
}
				jQuery('.product-item.ishoverselected', productList).children('.product-image').stop(true, true).animate({top: '0px'}, 'fast');
				jQuery(this).removeClass('ishoverselected');

				jQuery('#page-summary').first('p').html(jQuery('#page-summary').first('p').data('originalHtml'));
		  	}
	);












}


function initFaq() {
	var faqList = jQuery('#faq');
	if( faqList.length == 0 ) return;
	jQuery('dl:not(.isactive) dd',faqList).hide(0);
	jQuery('dt', faqList).click(
			function() {
				if( jQuery(this).parent().hasClass('isactive') ) return;
				jQuery('dl.isactive dd', faqList).hide(250).parent().removeClass('isactive');
				jQuery(this).parent().addClass('isactive');
				jQuery(this).next().show(250);
			}
	);
}





function initTeaser() {
/* breaks other things...
	jQuery('.teaser').click(
			function() {
				window.location.href = $('h2 a', this).attr('href');
			}
	);
*/
}


function initForms() {
	jQuery('.quantity-trigger input').after('<span class="minus">-</span><span class="plus">+</span>');

	jQuery('.quantity-trigger .plus').data('increment','1');
	jQuery('.quantity-trigger .minus').data('increment','-1');

	jQuery('.quantity-trigger .plus, .quantity-trigger .minus').click(
		function () {
				var tf = jQuery('input', jQuery(this).parent());
				var newValue = parseInt(tf.attr('value')) +  parseInt(jQuery(this).data('increment'));
				if (newValue <= 1 || isNaN(newValue)) newValue = 1;
				tf.attr('value', newValue);
	  	}
	);



	jQuery('.quantity-trigger-cart input').after('<span class="minus">-</span><span class="plus">+</span>');

	jQuery('.quantity-trigger-cart .plus').data('increment','1');
	jQuery('.quantity-trigger-cart .minus').data('increment','-1');

	jQuery('.quantity-trigger-cart .plus, .quantity-trigger-cart .minus').click(
		function () {
				var tf = jQuery('input', jQuery(this).parent());
				var newValue = parseInt(tf.attr('value')) +  parseInt(jQuery(this).data('increment'));
				if (newValue <= 0 || isNaN(newValue)) {
					newValue = 0;
				}
				else {

				}
				tf.attr('value', newValue);
	  	}
	);
}


//initialize some actions
	jQuery(document).ready(function($) {

		initProductList();
		initTeaser();
		initForms();
		initFancyBox();
		initFaq();

function initFancyBox(){
	$('a[href$=".jpg"] img').parent().addClass('group').addClass('zoomLink').attr('rel', 'group').fancybox({
		'overlayColor'			: '#fff',
		'overlayOpacity'		: 0.9,
		'overlayShow'			: true,
		'transitionIn'			: 'elastic',
		'transitionOut'			: 'elastic',
		'speedIn'				: 250,
		'speedOut'				: 250,
		'centerOnScroll'		: true
	}).addClass('fancyboxLink').prepend('<span class="zoomIcon"></span>');
}






	});

//google conversion code for download PDFMAILER FREE DE
function trackConv() {
	var google_conversion_id = 1071032926;
	var google_conversion_language = "de";
	var google_conversion_format = "3";
	var google_conversion_color = "ffffff";
	var google_conversion_label = "HBRsCICT7gEQ3tTa_gM";
	var google_conversion_value = 0;
	if (0) {
	  google_conversion_value = 0;
	}
    image = new Image(1,1);
	image.src = "http://www.googleadservices.com/pagead/conversion/"+google_conversion_id+"/?value=0&label="+google_conversion_label+"&script=0&google_conversion_value="+google_conversion_value;
}

//google conversion code for download PDFMAILER FREE EN
function trackConvEN() {
	var google_conversion_id = 1071032926;
	var google_conversion_language = "en";
	var google_conversion_format = "3";
	var google_conversion_color = "ffffff";
	var google_conversion_label = "BzR2CLCErQIQ3tTa_gM";
	var google_conversion_value = 0;
	if (0) {
	  google_conversion_value = 0;
	}
    image = new Image(1,1);
	image.src = "http://www.googleadservices.com/pagead/conversion/"+google_conversion_id+"/?value=0&label="+google_conversion_label+"&script=0&google_conversion_value="+google_conversion_value;
}



//google conversion code for campain page
function trackConvCampaign() {
	var google_conversion_id = 1071032926;
	var google_conversion_language = "de";
	var google_conversion_format = "3";
	var google_conversion_color = "ffffff";
	var google_conversion_label = "clHRCPj87gEQ3tTa_gM";
	var google_conversion_value = 0;
	if (0) {
	  google_conversion_value = 0;
	}
	image = new Image(1,1);
    image.src = "http://www.googleadservices.com/pagead/conversion/"+google_conversion_id+"/?value=0&guid=ON&label="+google_conversion_label+"&script=0&google_conversion_value="+google_conversion_value;
}


function trackConvForm() {
	var google_conversion_id = 1071032926;
	var google_conversion_language = "de";
	var google_conversion_format = "3";
	var google_conversion_color = "ffffff";
	var google_conversion_label = "0triCJDg5gEQ3tTa_gM";
	var google_conversion_value = 0;
	if (0) {
	  google_conversion_value = 0;
	}
	image = new Image(1,1);
	image.src = "http://www.googleadservices.com/pagead/conversion/"+google_conversion_id+"/?value=0&guid=ON&label="+google_conversion_label+"&script=0&google_conversion_value="+google_conversion_value;
}
//pdf mailer professional conversion contact form -> english
function trackConvFormEN() {
	var google_conversion_id = 1071032926;
	var google_conversion_language = "en";
	var google_conversion_format = "3";
	var google_conversion_color = "ffffff";
	var google_conversion_label = "0triCJDg5gEQ3tTa_gM";
	var google_conversion_value = 0;
	if (0) {
	  google_conversion_value = 0;
	}
	image = new Image(1,1);
	image.src = "http://www.googleadservices.com/pagead/conversion/"+google_conversion_id+"/?value=0&guid=ON&label="+google_conversion_label+"&script=0&google_conversion_value="+google_conversion_value;
}

//prints a div
function printDiv()
{
   var divToPrint=document.getElementById('areaToPrint');
  newWin= window.open("");
  newWin.document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">'+
'<html><head><title>Print Order</title></head><body>' + divToPrint.innerHTML + '</body></html>');//+'<script type="text/JavaScript">window.print();</script>'
  newWin.print();
  newWin.close();
  return false;
}
