function isSmartphone()
{
	return (navigator.userAgent.toLowerCase().search(/(iphone|ipod|opera mini|fennec|palm|blackberry|android|symbian|series60)/)>-1);
}

function cms_repeat_delayed(func, delay){
	
	if(func()) {
		window.setTimeout(function(){cms_repeat_delayed(func, delay);},delay);
	}
	
}

function cms_mergeArrays(arr1, arr2) {

	var result = arr1;
	
	for(var i=0; i<arr2.length; i++)
		result[result.length]=arr2[i];
	
	return result;
}

String.prototype.inString = function(str) {

	for(var i = 0; i <= this.length-str.length; i++) {
		if (this.substring(i,i+str.length)==str) return i;
	}
	
	return -1;
	
}

function thisMovie(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
	 return window[movieName];
	} else {
	 return document[movieName];
	}
}

function showPic(type, mode) {

	if (thisMovie('produkte_flashswf').showPic)
		thisMovie('produkte_flashswf').showPic(type, mode);

}

function showMenu(id) {

	document.getElementById('nav1_' + id).className = 'hover';

}

function hideMenu(id) {

	document.getElementById('nav1_' + id).className = '';

}

function product_preview (product) {

	if (product == false) {

		document.getElementById('product_preview_img').src = '/img/blank.gif';

	} else {
	
		document.getElementById('product_preview_img').src = '/img/produkte/' + product + '/thumb.jpg';
		if (typeof console != 'undefined')
			console.log(document.getElementById('product_preview_img').src);
	
	}

}

function init(flag) {

	if(flag) cms_init();
	check();

}

function check() {

	var el = document.getElementById('bottom');
	var height = (document.documentElement.clientHeight) ? document.documentElement.clientHeight : window.innerHeight;
	el.style.position = (!isSmartphone() && height > 500) ? 'fixed' : 'static';
	el.style.bottom = 0;

}

window.addEvent('domready', function()
{
	check();
	
	// startseite
	if ($('home_box3'))
	{
		$$('#home_box3 .infobox').each(function(el) { el.addEvent('click', function() { window.location.href = '/' + lang + '/Produkte/Luftlagerbuchsen'; })});
	}
	
	// Flash-Movie Home
	if ($('home_flash') && Browser.Plugins.Flash.version >= 9)
	{
		var home_flash = new Swiff('/flash/' + lang + '/home.swf',
		{
			id: 'home_flashswf',
			container: 'home_flash',
			width: 845,
			height: 279,
			params:
			{
				wmode: 'transparent',
				menu: 'false'
			},
			vars:
			{
				lang: lang
			}
		});
	}
	
	// Flash-Movie Headlines
	/*
	$$('table#product_table td.head p').each(function(el)
	{
		var home_flash = new Swiff('/flash/text.swf',
		{
			id: 'home_flashswf',
			container: el,
			width: 20,
			height: 177,
			params:
			{
				wmode: 'transparent',
				menu: 'false'
			},
			vars:
			{
				lang: lang,
				text: el.get('text')
			}
		});
	});*/
	
	// Flash-Movie Produkte
	if ($('categories_flash'))
	{
		if (Browser.Plugins.Flash.version >= 9)
		{
			var home_flash = new Swiff('/flash/' + lang + '/produkte.swf',
			{
				id: 'produkte_flashswf',
				container: 'categories_flash',
				width: 845,
				height: 177,
				params:
				{
					wmode: 'transparent',
					menu: 'false'
				},
				vars:
				{
					lang: lang
				}
			});
		}
		
		if ($('nav1_m'))
		{
			$('nav1_m').addEvent('mouseover', function() { showPic('m', true); });
			$('nav1_m').addEvent('mouseout', function() { showPic('m', false); });
		}
		
		if ($('nav1_z'))
		{
			$('nav1_z').addEvent('mouseover', function() { showPic('z', true); });
			$('nav1_z').addEvent('mouseout', function() { showPic('z', false); });
		}
		
		if ($('nav1_sk'))
		{
			$('nav1_sk').addEvent('mouseover', function() { showPic('sk', true); });
			$('nav1_sk').addEvent('mouseout', function() { showPic('sk', false); });
		}
		
		if ($('nav1_flansch'))
		{
			$('nav1_flansch').addEvent('mouseover', function() { showPic('flansch', true); });
			$('nav1_flansch').addEvent('mouseout', function() { showPic('flansch', false); });
		}
		
		if ($('nav1_chopper'))
		{
			$('nav1_chopper').addEvent('mouseover', function() { showPic('chopper', true); });
			$('nav1_chopper').addEvent('mouseout', function() { showPic('chopper', false); });
		}
		
		if ($('nav1_powerline'))
		{
			$('nav1_powerline').addEvent('mouseover', function() { showPic('powerline', true); });
			$('nav1_powerline').addEvent('mouseout', function() { showPic('powerline', false); });
		}
		
		if ($('nav1_zubehoer'))
		{
			$('nav1_zubehoer').addEvent('mouseover', function() { showPic('zubehoer', true); });
			$('nav1_zubehoer').addEvent('mouseout', function() { showPic('zubehoer', false); });
		}
		
		if ($('nav1_kataloge'))
		{
			$('nav1_kataloge').addEvent('mouseover', function() { showPic('kataloge', true); });
			$('nav1_kataloge').addEvent('mouseout', function() { showPic('kataloge', false); });
		}
	}
	
	// Toolchange Movies
	if ($('toolchangemovie'))
	{
		if ($('toolchange_manual'))
		{
			$('toolchange_manual').addEvent('mouseover', function()
			{
				var toolchange = new Swiff('/flash/manuell.swf',
				{
					id: 'toolchangeswf',
					container: 'toolchangemovie',
					width: 166,
					height: 177,
					params:
					{
						wmode: 'transparent',
						menu: 'false'
					},
					vars:
					{
						lang: lang
					}
				});
			});
			$('toolchange_manual').addEvent('mouseout', function()
			{
				$('toolchangemovie').set('html', '');
			});
		}
		if ($('toolchange_taper'))
		{
			$('toolchange_taper').addEvent('mouseover', function()
			{
				var toolchange = new Swiff('/flash/hskwechsel.swf',
				{
					id: 'toolchangeswf',
					container: 'toolchangemovie',
					width: 166,
					height: 177,
					params:
					{
						wmode: 'transparent',
						menu: 'false'
					},
					vars:
					{
						lang: lang
					}
				});
			});
			$('toolchange_taper').addEvent('mouseout', function()
			{
				$('toolchangemovie').set('html', '');
			});
		}
		if ($('toolchange_taper2'))
		{
			$('toolchange_taper2').addEvent('mouseover', function()
			{
				var toolchange = new Swiff('/flash/wkwechsel.swf',
				{
					id: 'toolchangeswf',
					container: 'toolchangemovie',
					width: 166,
					height: 177,
					params:
					{
						wmode: 'transparent',
						menu: 'false'
					},
					vars:
					{
						lang: lang
					}
				});
			});
			$('toolchange_taper2').addEvent('mouseout', function()
			{
				$('toolchangemovie').set('html', '');
			});
		}
		if ($('toolchange_direct'))
		{
			$('toolchange_direct').addEvent('mouseover', function()
			{
				var toolchange = new Swiff('/flash/pneumatisch.swf',
				{
					id: 'toolchangeswf',
					container: 'toolchangemovie',
					width: 166,
					height: 177,
					params:
					{
						wmode: 'transparent',
						menu: 'false'
					},
					vars:
					{
						lang: lang
					}
				});
			});
			$('toolchange_direct').addEvent('mouseout', function()
			{
				$('toolchangemovie').set('html', '');
			});
		}
	}
	
	// Product table
	if ($('product_table'))
	{
		$$('.productline').each(function(el)
		{
			el.addEvent('mouseover', function() { product_preview(this.get('id').replace(/^product_/, '')); });
			el.addEvent('mouseout', function() { product_preview(false); });
			el.addEvent('click', function() { window.location.href = this.getElement('a').href; return false; });
		});
	}
	
	// Product Detail Image
	if ($('product_image'))
	{
		if (Browser.Plugins.Flash.version >= 9)
		{
			var home_flash = new Swiff('/flash/produkt.swf',
			{
				id: 'product_imageswf',
				container: 'product_image',
				width: 279,
				height: 403,
				params:
				{
					wmode: 'transparent',
					menu: 'false'
				},
				vars:
				{
					lang: lang,
					img: '/img/produkte/' + $('product_image').get('title') + '/detail.jpg'
				}
			});
		}
	}
	
	// Filme
	if ($('movie_spot'))
	{
		var home_flash = new Swiff('/flash/flvplayer/flvplayer.swf',
		{
			id: 'videoPlayer',
			container: 'movie_spot',
			width: 320,
			height: 280,
			params:
			{
				scale: 'noscale',
				allowfullscreen: 'true',
				salign: 'tl',
				base: '.'
			},
			vars:
			{
				playerpath: '/flash/flvplayer/',
				contentpath: '/flash/video',
				video: 'spot.flv',
				preview: '../preview/spot.jpg',
				skin: 'skin-applestyle.swf',
				skincolor: '0x009ee0',
				skinscalemaximum: '1'
			}
		});
	}
	
	if ($('movie_company'))
	{
		var home_flash = new Swiff('/flash/flvplayer/flvplayer.swf',
		{
			id: 'videoPlayer',
			container: 'movie_company',
			width: 320,
			height: 220,
			params:
			{
				scale: 'noscale',
				allowfullscreen: 'true',
				salign: 'tl',
				base: '.'
			},
			vars:
			{
				playerpath: '/flash/flvplayer/',
				contentpath: '/flash/video',
				video: 'company_' + lang + '.flv',
				preview: '../preview/company.jpg',
				skin: 'skin-applestyle.swf',
				skincolor: '0x009ee0',
				skinscalemaximum: '1'
			}
		});
	}
	
	if ($('movie_engraving'))
	{
		var home_flash = new Swiff('/flash/flvplayer/flvplayer.swf',
		{
			id: 'videoPlayer',
			container: 'movie_engraving',
			width: 320,
			height: 280,
			params:
			{
				scale: 'noscale',
				allowfullscreen: 'true',
				salign: 'tl',
				base: '.'
			},
			vars:
			{
				playerpath: '/flash/flvplayer/',
				contentpath: '/flash/video',
				video: 'engraving.flv',
				preview: '../preview/engraving.jpg',
				skin: 'skin-applestyle.swf',
				skincolor: '0x009ee0',
				skinscalemaximum: '1'
			}
		});
	}
	
	
	if ($('movie_chopper'))
	{
		var home_flash = new Swiff('/flash/flvplayer/flvplayer.swf',
		{
			id: 'videoPlayer',
			container: 'movie_chopper',
			width: 320,
			height: 280,
			params:
			{
				scale: 'noscale',
				allowfullscreen: 'true',
				salign: 'tl',
				base: '.'
			},
			vars:
			{
				playerpath: '/flash/flvplayer/',
				contentpath: '/flash/video',
				video: 'chopper.flv',
				preview: '../preview/chopper.jpg',
				skin: 'skin-applestyle.swf',
				skincolor: '0x009ee0',
				skinscalemaximum: '1'
			}
		});
	}
	
	// Search
	if ($('search'))
	{
		$('search').set('html', '<form action="/Suche.html" id="cse-search-box"><div><input type="hidden" name="cx" value="003512419345984869110:vtqgjjnkzug" /><input type="hidden" name="cof" value="FORID:10" /><input type="hidden" name="ie" value="UTF-8" /><input type="text" name="q" size="31" class="search" />&nbsp;<input type="submit" name="sa" value="' + lblSearch + '" class="button" /></div></form><script type="text/javascript" src="http://www.google.com/cse/brand?form=cse-search-box&lang=de"></script>');
	}
});
