<!--
var xmlHttp = new Array();

function GetXmlHttpObject() {
	var HttpObj = null;
	try	{
		HttpObj = new XMLHttpRequest();
	} catch (e) {
		try {
			HttpObj = new ActiveXObject('Msxml2.XMLHTTP');
		}
		catch (e) {
			HttpObj = new ActiveXObject('Microsoft.XMLHTTP');
		}
	}
	return HttpObj;
}

function startPage(doGoogle, site) {
	var winLoc = String(window.location);
	if (winLoc.indexOf('#') > 0) {
		var protocol = String(window.location.protocol) + '//';
		var host = String(window.location.hostname);
		var url = winLoc.split('#');
		var newUrl = protocol + host + url[1];
		document.location.href = newUrl;
		return;
	}
	
	if (doGoogle != '') gmInitialize();
	
	window.addEvent('resize', function() { 
		changeSize();
	});
	
	var os = (Browser.Platform.name == 'ios' || Browser.Platform.name == 'android') ? 'touch' : 'pc';
	if (os == 'pc') {
		$('logo').addEvent('mouseover', function() {
			$('logo').src = '/images/' + site + 'LogoHover.png';
			var newTween = new Fx.Tween($('mainMenu'), {
				duration: 300,
				transition: Fx.Transitions.Quad.easeOut,
				property: 'height'
			});
			newTween.start(485);
		});
		$('mainMenu').addEvent('mouseleave', function() {
			$('logo').src = '/images/' + site + 'Logo.png';
			var newTween = new Fx.Tween($('mainMenu'), {
				duration: 500,
				transition: Fx.Transitions.Quad.easeOut,
				property: 'height'
			});
			newTween.start(200);
		});
	} else {
		$('mainMenu').setStyle('height', 485);
	}
	
	initBackground();
	initThumbImage();
	initShowroom();
	initPress();
	
	$$('#mainMenu a').each(function(el) {
		if (el.hasClass('active')) {
			$('mainContent').setStyle('visibility', 'visible');
		}
	});
	
	if ($('playerContainer')) {
		var options = {};
		var params = {};
		params.allowScriptAccess = 'always';
		swfobject.embedSWF('/includes/musicplayer.swf', 'playerContainer', '45', '45', '9.0.0', false, options, params, {});
	}
}

function attemptLogin(pressId, pressPageId) {
	if (pressId > 0) {
		var req = new Request({
			url: '/includes/ajax.asp?script=getPage&pageId=' + pressPageId,
			onSuccess: function(txt) {
				var result = txt.split('||##||');
				var bgProperties = result[0].split('|');
				$('arrBackgroundImageId').value = bgProperties[0];
				$('arrBackgroundWidth').value = bgProperties[1];
				$('arrBackgroundHeight').value = bgProperties[2];
				initBackground();
				var newTween = new Fx.Tween($('contentWrapper'), {
					duration: 250,
					property: 'opacity',
					onComplete: function() {
						$('contentWrapper').innerHTML = result[1];
						var newTween = new Fx.Tween($('contentWrapper'), {
							duration: 250,
							property: 'opacity'
						});
						newTween.start(1);
					}
				});
				newTween.start(0);
			}
		}).send();
	}
}

var currentBackgroundImage, previousBackgroundImage, imgBackgroundObj;
var arrBackgroundImageId, currentBackgroundImageId, backgroundTimer, nextBackgroundImageId, imgBackgroundRatio;
var arrBackgroundWidth, arrBackgroundHeight;

function initBackground() {
	if ($('arrBackgroundImageId')) {
		arrBackgroundImageId = $('arrBackgroundImageId').value.split(',');
		arrBackgroundWidth = $('arrBackgroundWidth').value.split(',');
		arrBackgroundHeight = $('arrBackgroundHeight').value.split(',');
		currentBackGroundImage = 0;
		currentBackgroundImageId = 0;
		setBackgroundImage(arrBackgroundImageId[0]);
	}
}

function setBackgroundImage(imageId, reRun) {
	if (!reRun) {
		currentBackgroundImage = (currentBackgroundImage == 1) ? 2 : 1;
		previousBackgroundImage = (currentBackgroundImage == 1) ? 2 : 1;
	}
	imgBackgroundObj = $('bg' + currentBackgroundImage);
	imgBackgroundObj.setStyle('opacity', 0);
	imgBackgroundObj.setStyle('z-index', 2);
	imgBackgroundObj.src = '/files/media_base/original/' + imageId + '.jpg';
	for (var x = 0; x < arrBackgroundImageId.length; x++) {
		if (arrBackgroundImageId[x].toInt() == imageId.toInt()) {
			var imgWidth = arrBackgroundWidth[x].toInt();
			var imgHeight = arrBackgroundHeight[x].toInt();
			break;
		}	
	}
	$('bg' + previousBackgroundImage).setStyle('z-index', 1);
	var myImage = Asset.image('/files/media_base/original/' + imageId + '.jpg', {
		onLoad: function() {
			var size = imgBackgroundObj.getSize();
			if (size.x == 1) {
				setBackgroundImage(imageId, true);
				return;
			}
			imgBackgroundRatio = imgWidth / imgHeight;
			changeSize(imageId);
		}
	});
}

function changeSize(imageId) {
	var size = window.getSize();
	var winWidth = size.x;
	var winHeight = size.y;
	$('bgImg').setStyle('width', winWidth);
	$('bgImg').setStyle('height', winHeight);
	var winRatio = winWidth / winHeight;
	var imgWidth = winWidth;
	var imgHeight = winHeight;
	if (winRatio > imgBackgroundRatio) {
		imgHeight = (imgBackgroundRatio > 1) ? (imgWidth / imgBackgroundRatio).toInt() : (imgWidth * imgBackgroundRatio).toInt();
	} else {
		imgWidth = (imgBackgroundRatio < 1) ? (imgHeight / imgBackgroundRatio).toInt() : (imgHeight * imgBackgroundRatio).toInt();
	}
	var imgX = (imgWidth > winWidth) ? 0 - ((imgWidth - winWidth) / 2).toInt() : 0;
	var imgY = (imgHeight > winHeight) ? 0 - ((imgHeight - winHeight) / 2).toInt() : 0;
	imgBackgroundObj.setStyle('left', imgX);
	imgBackgroundObj.setStyle('top', imgY);
	imgBackgroundObj.setStyle('width', imgWidth);
	imgBackgroundObj.setStyle('height', imgHeight);
	var newTween = new Fx.Tween(imgBackgroundObj, {
		duration: 1000,
		property: 'opacity',
		onComplete: function() {
			if (imageId) {
				currentBackgroundImageId = imageId;
				for (var x = 0; x < arrBackgroundImageId.length; x++) {
					if (arrBackgroundImageId[x].toInt() == currentBackgroundImageId.toInt()) {
						nextBackgroundImageId = x + 1;
						if (nextBackgroundImageId == arrBackgroundImageId.length) nextBackgroundImageId = 0;
						nextBackgroundImageId = arrBackgroundImageId[nextBackgroundImageId];
						break;
					}	
				}
				if (currentBackgroundImageId != nextBackgroundImageId) { 
					backgroundTimer = setTimeout(function() {
						setBackgroundImage(nextBackgroundImageId);
					}, 5000);
				}
			}	
		}
	});
	newTween.start(1);
	$('links').setStyle('visibility', 'visible');
}

function initShowroom() {
	var continents = new Fx.Accordion($$('div.continent a'), $$('div.continentWrapper'), {
    display: -1,
    alwaysHide: true
	});
	var countries = new Fx.Accordion($$('div.country a'), $$('div.countryWrapper'), {
    display: -1,
    alwaysHide: true
	});
	$$('div.continent a').each(function(el) {
		el.addEvent('click', function() {
			$$('div.continent a').removeClass('active');
			$$('div.country a').removeClass('active');
			el.toggleClass('active');
		});
	});
	$$('div.country a').each(function(el) {
		el.addEvent('click', function() {
			$$('div.country a').removeClass('active');
			el.toggleClass('active');
		});
	});
	$$('div.dealerCountry a').each(function(el) {
		el.addEvent('click', function() {
			$$('div.country a').removeClass('active');
			el.toggleClass('active');
		});
	});
}

function initPress() {
	
	var counter = -1;
	var currentActive = -1;
	$$('div.press a').each(function(el) {
		counter += 1;
		if (el.hasClass('active')) currentActive = counter;
	});
	
	var presses = new Fx.Accordion($$('div.press a'), $$('div.pressWrapper'), {
    display: currentActive,
    alwaysHide: true
	});
	$$('div.press a').each(function(el) {
		el.addEvent('click', function() {
			$$('div.press a').removeClass('active');
			el.toggleClass('active');
		});
	});
}

var currentThumbImage, previousThumbImage, imgThumbObj;
var arrThumbImageId, currentThumbImageId, thumbTimer, nextThumbImageId;

function initThumbImage() {
	if ($('arrThumbImageId')) {
		if ($('arrThumbImageId').value == '') {
			$('subThumb').addClass('noBorder');
			$('addressInfo').addClass('noBorder');
		} else {
			$('subThumb').removeClass('noBorder');
			$('addressInfo').removeClass('noBorder');
			arrThumbImageId = $('arrThumbImageId').value.split(',');
			currentThumbImageId = 0;
			setThumbImage(arrThumbImageId[0]);
		}
	}
}

function setThumbImage(imageId, reRun) {
	if (thumbTimer) clearTimeout(thumbTimer);
	if (!reRun) {
		currentThumbImage = (currentThumbImage == 1) ? 2 : 1;
		previousThumbImage = (currentThumbImage == 1) ? 2 : 1;
	}
	if ($('bi' + currentThumbImage)) {
		imgThumbObj = $('bi' + currentThumbImage);
		imgThumbObj.setStyle('opacity', 0);
		imgThumbObj.setStyle('z-index', 2);
		imgThumbObj.src = '/files/media_base/work/' + imageId + '.jpg';
		$('bi' + previousThumbImage).setStyle('z-index', 1);
		var arrImage = new Array();
		arrImage[0] = '/files/media_base/work/' + imageId + '.jpg';
		var myImages = Asset.images(arrImage, {
			onComplete: function() {
				var size = imgThumbObj.getSize();
				if (size.x == 1) {
					setThumbImage(imageId, true);
					return;
				}
				putThumbImage(imageId);
			}
		});
	}
}

function putThumbImage(imageId) {
	if (currentThumbImageId > 0) {
		$('subThumb' + currentThumbImageId).removeClass('active');
	}
	currentThumbImageId = imageId;
	$('subThumb' + currentThumbImageId).addClass('active');
	var newTween = new Fx.Tween(imgThumbObj, {
		duration: 1000,
		property: 'opacity',
		onComplete: function() {
			for (var x = 0; x < arrThumbImageId.length; x++) {
				if (arrThumbImageId[x].toInt() == currentThumbImageId.toInt()) {
					nextThumbImageId = x + 1;
					if (nextThumbImageId == arrThumbImageId.length) nextThumbImageId = 0;
					nextThumbImageId = arrThumbImageId[nextThumbImageId];
					break;
				}	
			}
			thumbTimer = setTimeout(function() {
				setThumbImage(nextThumbImageId);
			}, 5000);
		}
	});
	newTween.start(1);
}

function setPause() {
	if (thumbTimer) clearTimeout(thumbTimer);	
	if ($('pauseButton').hasClass('playButton')) {
		$('pauseButton').removeClass('playButton');
		setThumbImage(nextThumbImageId);
	} else {
		$('pauseButton').addClass('playButton');
	}
}












function getURL(obj, pageId, addressId, countryId) {
	if (thumbTimer) clearTimeout(thumbTimer);
	if (backgroundTimer) clearTimeout(backgroundTimer);
	
	var myURI = new URI(obj.href);
	var URL = myURI.toAbsolute().split('/');
	var newURL = '';
	for (var x = 0; x < URL.length; x++) {
		if (URL[x] != '') {
			if (newURL != '') newURL += '/';
			newURL += URL[x];
		}	
	}
	newURL = '#/' + newURL;
	document.location = newURL;
	
	$('mainContent').setStyle('visibility', 'visible');
	
	if (countryId != 0) {
		var req = new Request({
			url: '/includes/ajax.asp?script=getCountry&countryId=' + countryId,
			onSuccess: function(txt){
				$$('div.dealerCountry a').removeClass('active');
				obj.addClass('active');
				var newTween = new Fx.Tween($('content'), {
					duration: 250,
					property: 'opacity',
					onComplete: function() {
						$('content').innerHTML = txt;
						var newTween = new Fx.Tween($('content'), {
							duration: 250,
							property: 'opacity'
						});
						newTween.start(1);
					}
				});
				newTween.start(0);
			}
		}).send();
	} else if (addressId > 0) {
		var req = new Request({
			url: '/includes/ajax.asp?script=getAddress&addressId=' + addressId,
			onSuccess: function(txt){
				$$('div.dealerWrapper a').removeClass('active');
				obj.addClass('active');
				$('subThumb').innerHTML = txt;
				initThumbImage();
			}
		}).send();
	} else {
		var req = new Request({
			url: '/includes/ajax.asp?script=getPageType&pageId=' + pageId + '&addressId=' + addressId,
			onSuccess: function(txt){
				result = txt.split('||##||');
				var parentId = result[0].toInt();
				var isCollection = result[1].toInt();
				var isShowroom = result[2].toInt();
				var isPress = result[3].toInt();
				var isNews = result[4].toInt();
				var isDealer = result[5].toInt();
				var req = new Request({
					url: '/includes/ajax.asp?script=getPage&pageId=' + pageId,
					onSuccess: function(txt) {
						if (parentId == 0) {
							$$('#mainMenu a').removeClass('active');
						} else {
							$$('#subMenu a').removeClass('active');
						}
						obj.addClass('active');
						result = txt.split('||##||');
						var bgProperties = result[0].split('|');
						$('arrBackgroundImageId').value = bgProperties[0];
						$('arrBackgroundWidth').value = bgProperties[1];
						$('arrBackgroundHeight').value = bgProperties[2];
						initBackground();
						if (parentId > 0 && (isCollection == 1 || isShowroom == 1)) {
							$('subThumb').innerHTML = result[1];
							initThumbImage();
						} else if (parentId == 0) {
							var newTween = new Fx.Tween($('contentWrapper'), {
								duration: 250,
								property: 'opacity',
								onComplete: function() {
									var html = result[1];
									$('contentWrapper').innerHTML = html;
									if (isCollection == 1) initThumbImage()
									if (isShowroom == 1 || isDealer == 1) initShowroom();
									if (isPress == 1) initPress();
									if (isNews == 1) initPress();
									var x = 0;
									do {
										x = html.indexOf('extraScript', x);
										if (x != -1) {
											var id = html.substr(x + 11, 6);
											var javaText = $('extraScript' + id).innerHTML;
											x += 1;
											eval(javaText);
										}
									} while (x != -1)
									var newTween = new Fx.Tween($('contentWrapper'), {
										duration: 250,
										property: 'opacity'
									});
									newTween.start(1);
								}
							});
							newTween.start(0);
						} else {
							var newTween = new Fx.Tween($('content'), {
								duration: 250,
								property: 'opacity',
								onComplete: function() {
									var html = result[1];
									$('content').innerHTML = html;
									var x = 0;
									do {
										x = html.indexOf('extraScript', x);
										if (x != -1) {
											var id = html.substr(x + 11, 6);
											var javaText = $('extraScript' + id).innerHTML;
											x += 1;
											eval(javaText);
										}
									} while (x != -1)
									
									var newTween = new Fx.Tween($('content'), {
										duration: 250,
										property: 'opacity'
									});
									newTween.start(1);
								}
							});
							newTween.start(0);
						}
					}
				}).send();
			}
		}).send();
	}
	return false;
}

function keyStroke(e, validate) {
	var key = window.event ? e.keyCode : e.which;
	if (key == 8 || key == 0) return true;
	if (key == 124 ) return false;
	if (validate == 1 && key == 32) return false;
	if (validate == 3 || validate == 2) {
		if (key < 48 || key > 57) {
			if (key != 44 && key != 45) {
				return false;
			} else {
				if (validate == 2 && key == 44) {
					return false;
				}
			}
		}
	}
}

function checkForm(formIdentifier) {
	var formitem = document.getElementById('checkfields' + formIdentifier).value.split('#**#');
	for (var x = 0; x < formitem.length; x++) {
		var formproperties = formitem[x].split('#|#');
		var formfield = formproperties[0];
		var fieldname = formproperties[1];
		var validate = parseInt(formproperties[2]);
		var compulsary = parseInt(formproperties[3]);
		var unique = parseInt(formproperties[4]);
		if (validate != 2) {
			if (document.getElementById(formfield)) {
				var a = doTrim(document.getElementById(formfield));
				document.getElementById(formfield).value = a;
			}
		}
		//if (validate == 2) {
		//	var found = false;
		//	for (var i = 0; i < document.getElementsByName(formfield).length; i++) {
		//		if (document.getElementsByName(formfield)[i].checked) found = true;
		//	}
		//	if (found == false) {
		//		translate(2, '', ': ' + fieldname);
		//		return false;
		//	}
		//}
		if (compulsary == 1) {
			if (document.getElementById(formfield).value == '') {
				if (document.getElementById(formfield).style.visibility != 'hidden') {
					translate(3, '', ': ' + fieldname);
					document.getElementById(formfield).focus();
					return false;
				}
			}
		}
		if (validate == 1) {
			if (emailCheck(formfield, compulsary) == false) {
				translate(4, '', '');
				document.getElementById(formfield).focus();
				return false;
			}
		}
		if (unique == 1) {
			var result = parseInt(document.getElementById(formfield + '_unique').value);
			if (result == 0) {
				translate(5, '', ': ' + fieldname);
				document.getElementById(formfield).focus();
				return false;
			}
		}
	}
	return;
}

function checkUnique(dbtable, dbfield, id, formfield) {
	xmlHttp[1] = GetXmlHttpObject();
	var url = '/includes/ajax.asp?script=checkunique&dbtable=' + dbtable + '&dbfield=' + dbfield + '&dbvalue=' + escape(document.getElementById(formfield).value) + '&id=' + id + '&sid=' + Math.random();
	xmlHttp[1].open('GET', url, true);
	xmlHttp[1].onreadystatechange = function() {
		if (xmlHttp[1].readyState == 4) {
			result = xmlHttp[1].responseText;
			document.getElementById(formfield + '_unique').value = result;
		}
	}
	xmlHttp[1].send(null);
}

function emailCheck(formfield, compulsary) {
	var emailStr=document.getElementById(formfield).value
	if (compulsary == 0 && emailStr == '') return true;
	var checkTLD=1;
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);
	if (matchArray==null) return false;
	var user=matchArray[1];
	var domain=matchArray[2];
	for (i = 0; i < user.length; i++) {
		if (user.charCodeAt(i) > 127) return false;
	}
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i) > 127) return false;
	}
	if (user.match(userPat)==null) return false;
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
		for (var i = 1;i <= 4; i++) {
			if (IPArray[i] > 255) return false;
		}
		return true;
	}
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i = 0; i < len; i++) {
		if (domArr[i].search(atomPat) == -1) return false;
	}
	if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) return false;
	if (len < 2) return false;
	return true;
}

function translate(id, before, after) {
	xmlHttp[2] = GetXmlHttpObject();
	var url = 'includes/ajax.asp?script=translate&id=' + id + '&rid=' + Math.random();
	xmlHttp[2].open('GET', url, true);
	xmlHttp[2].onreadystatechange = function() {
		if (xmlHttp[2].readyState == 4) {
			response = before + xmlHttp[2].responseText + after;
			alert(response);
		}
	}
	xmlHttp[2].send(null);
}

function tagReaction(reaction_id) {
	xmlHttp[1] = GetXmlHttpObject();
	var url = 'includes/ajax.asp?script=tagreaction&reaction_id=' + reaction_id + '&tagged=1&rid=' + Math.random();
	xmlHttp[1].open('GET', url, true);
	xmlHttp[1].onreadystatechange = function() {
		if (xmlHttp[1].readyState == 4) {
			document.getElementById('ok' + reaction_id).innerHTML = document.getElementById('tagMessage').value;
		}
	}
	xmlHttp[1].send(null);
}

function showAdvanced() {
	if (document.getElementById('advanced').style.display == 'none') {
		document.getElementById('advanced').style.display = 'block';
	} else {
		document.getElementById('advanced').style.display = 'none';
	}
}

function doTrim(obj) {
	var a = trim(obj.value);
	obj.value = a;
	return a;
}

function trim(strValue) {
	if (strValue.length < 1) return '';
	strValue = rTrim(strValue);
	strValue = lTrim(strValue);
	return strValue;
}

function rTrim(strValue) {
	var w_space = String.fromCharCode(32);
	var v_length = strValue.length;
	var strTemp = '';
	if (v_length < 0) return '';
	var iTemp = v_length - 1;
	while(iTemp > -1) {
		if (strValue.charAt(iTemp) != w_space) {
			strTemp = strValue.substring(0, iTemp + 1);
			break;
		}
		iTemp = iTemp - 1;
	}
	return strTemp;
}

function lTrim(strValue) {
	var w_space = String.fromCharCode(32);
	if (v_length < 1) return '';
	var v_length = strValue.length;
	var strTemp = '';
	var iTemp = 0;
	while (iTemp < v_length) {
		if (strValue.charAt(iTemp) != w_space) {
			strTemp = strValue.substring(iTemp, v_length);
			break;
		}
		iTemp = iTemp + 1;
	}
	return strTemp;
}


//-->

