	//form change default value
	function changeDefaultValue(sender, default_value, change_value)
	{
		if (sender.value == default_value) sender.value = change_value;
	}

	//clasirane box

	function changeListContent(sender_select, active)
	{
		if (sender_select.value == window[active]) return;

		document.getElementById(window[active]).className = 'hidden';
		document.getElementById(sender_select.value).className = 'visible';
		window[active] = sender_select.value;
	}

	function radioButton(sender, form_name, hidden, value)
	{
		var obj = sender.parentNode.getElementsByTagName('span')[0];
		
		if (obj.id != 'checked_radio_button_' + form_name + hidden)
		{
			var active = document.getElementById('checked_radio_button_' + form_name + hidden);
			if (active)
			{
				active.id = '';
				active.className = 'radio_button';
			}

			obj.id = 'checked_radio_button_' + form_name + hidden;
			obj.className = 'radio_button checked_radio';

			document.forms[form_name].elements[hidden].value = value;
		}
	}


	//change content info
	function MoveActiveContent(root_id, tag, active_id, ms_move, index)
	{
		this.obj = document.getElementById(root_id).getElementsByTagName(tag);
		this.active_id = active_id;
		this.active_element = document.getElementById(this.active_id);

		this.index = index;
		this.ms_move = ms_move;
		this.timer = null;
	}

	MoveActiveContent.prototype.startMove = function()
	{
		var self = this;
		this.timer = setInterval(function(){self.moveNextContent()}, this.ms_move);
	}

	MoveActiveContent.prototype.stopMove = function()
	{
		clearInterval(this.timer);
	}

	MoveActiveContent.prototype.removeActive = function()
	{
			document.getElementById(this.active_element.getAttribute('title')).className = 'hidden';
			this.active_element.id = '';
	}

	MoveActiveContent.prototype.setActive = function(sender)
	{
		if (!isNaN(sender))
		{
			if (sender == this.index) return;

			this.index = sender;
		}

		this.removeActive();

		var obj = this.obj[this.index];
			document.getElementById(obj.getAttribute('title')).className = 'visible';
			obj.id = this.active_id;
			this.active_element = obj;
	}

	MoveActiveContent.prototype.moveNextContent = function()
	{
		if (++this.index >= this.obj.length) this.index = 0;

		this.setActive();
	}

	MoveActiveContent.prototype.movePreviousContent = function()
	{
		if (--this.index < 0) this.index = this.obj.length - 1;

		this.setActive();
	}

	//user tools for zoom text, print, send friend

	var curFont = 10;

	function replaceClassNameObj(obj, regExp, replacer)
	{
		obj.className = obj.className.replace(regExp, replacer);
	}

	function incrementDecrementFont(obj_id, cur_button, ot_button_id, step)
	{
		if (cur_button.className.indexOf(' disable') > -1) return;

		curFont += step;
		document.getElementById(obj_id).style.fontSize = curFont + 'px';

		if (curFont <= 10 || curFont >= 13)
		{
			cur_button.className += ' disable';
		}
		else replaceClassNameObj(document.getElementById(ot_button_id), / disable$/, '');
	}

	//checkbox

	function checkbox(obj, formR, hiddenEl)
	{
		var hiddenElement = document.forms[formR].elements[hiddenEl];
		if (obj.className == 'checkbox')
		{
			obj.className += ' checked';
			hiddenElement.value = 'true'
			return;
		}

		replaceClassNameObj(obj, / checked$/, '');
		hiddenElement.value = '';
	}

	function checkbox2(obj, formR, hiddenEl, index)
	{
		var hiddenElement = document.forms[formR].elements[hiddenEl];
		if (hiddenElement.length > 0) hiddenElement = hiddenElement[index];
		
		if (obj.className == 'checkbox')
		{
			obj.className += ' checked';
			hiddenElement.checked = true;
			return;
		}

		replaceClassNameObj(obj, / checked$/, '');
		hiddenElement.checked = false;
	}

	//ComboBox
	function addEvent(element, handler, callback, capture)
	{
		if (window.addEventListener) element.addEventListener(handler, callback, capture);
		else element.attachEvent('on' + handler, callback);
	}
	
	function removeEvent(element, handler, callback, capture)
	{
		if (window.removeEventListener) element.removeEventListener(handler, callback, capture);
		else element.detachEvent('on' + handler, callback);
	}


	var currentComboBox = null;
	var flagComboBox = false;
	function moveSelected(sender, index)
	{
		if (sender.className == 'selected') return;

		currentComboBox.getElementsByTagName('li')[currentComboBox.currentSelected].className = '';
		sender.className = 'selected';
		currentComboBox.currentSelected = index;
	}

	function changeSelected(index, text, value)
	{
		if (index == currentComboBox.selectedIndex) return;

		currentComboBox.selectedIndex = index;
		updateTextValue(text, value);
		if (currentComboBox.listener) currentComboBox.listener.call(this, currentComboBox);
	}

	function showComboBox(combo_dom)
	{
		if (combo_dom != currentComboBox) hideComboBox();

		currentComboBox = combo_dom;
		currentComboBox.parentNode.style.zIndex = 9999; //M$ stupid browser hack!!!
		var combo = combo_dom.getElementsByTagName('div')[0];
			moveSelected(combo.getElementsByTagName('li')[combo_dom.selectedIndex], combo_dom.selectedIndex);
			combo.style.display = (combo.style.display != 'block') ? 'block' : 'none';
			flagComboBox = false;
	}

	function hideComboBox()
	{
		if (!currentComboBox || !flagComboBox)
		{
			flagComboBox = true;
			return;
		}
		currentComboBox.parentNode.style.zIndex = 100; //M$ stupid browser hack!!!
		currentComboBox.getElementsByTagName('div')[0].style.display = 'none';
		currentComboBox = null;
	}

	function updateTextValue(text, value)
	{
		var obj = currentComboBox.getElementsByTagName('input');
		currentComboBox.value =  obj[0].value = value;
		currentComboBox.getElementsByTagName('span')[0].innerHTML = text;
	}

	function OptionItem(text, value, selected)
	{
		this.text = text;
		this.value = (!value) ? this.text : value;
		this.selected = selected;
	}

	function ComboBox(name)
	{
		this.name = name;
		this.options = new Array();
		this.selectedIndex = 0;
		this.onchange_listener = null;
	}

	ComboBox.prototype.addOption = function(Option)
	{
		this.options.push(Option);

		if (Option.selected) this.selectedIndex = this.options.length - 1;
	}

	ComboBox.prototype.removeOption = function(index)
	{
		this.options.splice(index, 1);
	}

	ComboBox.prototype.setOnChangeListener = function(callback)
	{
		if (!(callback instanceof Function))
		{
			throw new Error('Arguments must be Function!!!');
		}

		this.onchange_listener = callback;
	}

	ComboBox.prototype.renderComboBox = function(id_element)
	{
		if (!this.options.length) return;
		
		var selectedElement = this.options[this.selectedIndex];

		var combo_root = document.createElement('div');
			combo_root.className = 'combo_box';
			combo_root.selectedIndex = this.selectedIndex;
			combo_root.currentSelected = this.selectedIndex;
			combo_root.value = this.options[this.selectedIndex].value;
			combo_root.listener = this.onchange_listener;
			combo_root.onclick = function(){showComboBox(this);};
		var htmlCode = '<span>' + selectedElement.text + '</span><input type="hidden" name="' + this.name + '" value="' + selectedElement.value + '"><div><ul>';

		for (var i = 0, len = this.options.length; i < len; i++)
		{
			htmlCode += '<li onclick="changeSelected(' + i + ',\'' + this.options[i].text + '\',\'' + this.options[i].value + '\')" onmouseover="moveSelected(this, '+ i +')">' + this.options[i].text + '</li>';
		}

		htmlCode += '</ul></div></div>';
		combo_root.innerHTML = htmlCode;
		document.getElementById(id_element).appendChild(combo_root);
	}


	addEvent(document, 'click', hideComboBox, false);

	function checkActiveLiveScores()
	{
		var row = document.getElementById('ls_p1_container').getElementsByTagName('tr');
		var i = 0;
		while(i < row.length && row[i].className != 'active_match') i++;

		if (i < row.length) setActiveLiveScores();
	}
	
	function updateFileValue(sender, id_element)
	{
		document.getElementById(id_element).value = sender.value;
	}
	
	function MM_swapImgRestore() { //v3.0
	  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
	}

	function MM_preloadImages() { //v3.0
	  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
		var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
		if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
	}

	function MM_findObj(n, d) { //v4.01
	  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	  if(!x && d.getElementById) x=d.getElementById(n); return x;
	}

	function MM_swapImage() { //v3.0
	  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
	}
	
	$(document).ready(function() {
		
		// family drop down
		$(".bikeName").mouseover(function() { 
			dropLeft = getRealLeft(document.getElementById('bikeNameMarker'));
			showFamilyDropDown(); 
		}).mouseout(function() { 
			return; 
		});
		/*
		// enhance compare link - set new compare URL in subnav
		$("#subNavInner ul li.compare a").attr("href", $("p.compareBikes a").attr("href"));
		
		// update compare links if we came from the compare page
		if (document.referrer) {
			var checkMatch;
			checkMatch = document.referrer;
			if (checkMatch.indexOf('/bikes/compare/') > 0) {
				$("#subNavInner ul li.compare a").click(function() {
					history.go(-1);
					return false;
				});	
				$("#bikeHeader .right p.compareBikes a").click(function() {
					history.go(-1);
					return false;
				});
			}
		}
		*/

		// tabs
		$("div.hidden").hide();
		$("div.tabHeaders ul li a").click(function() { 
			$(this).parent().parent().children().removeClass('selected'); // remove currently selected
			$(this).parent().addClass('selected'); // make this selected
			var linkHash = this.hash; // find selected tab
			if (linkHash.length > 1) {
				linkHash = linkHash.substring(1,linkHash.length);
			}
			$("#"+linkHash).siblings().hide(); // hide siblings
			$("#"+linkHash).show(); // show selected tab
			$(this).blur();
			return false;
		});
		
		/*
		// geometry
		if ($.cookie('MEASUREMENT_UNITS') != undefined) {
			document.getElementById('geometryTable').className = $.cookie('MEASUREMENT_UNITS');
			if ($.cookie('MEASUREMENT_UNITS') == 'imperial') {
				document.getElementById('measureImperial').checked = true;
			} else {
				document.getElementById('measureMetric').checked = true;
			}
		}
		*/
	});
	
	function showFamilyDropDown() {
		$("#bikeFamilyDrop").show();
		getDropDownHitArea(); 
		$("#bikeFamilyDrop").css("left", dropLeft);
		$().mousemove(function(e){
			if (!stillShowFamilyDropDown(e.pageX, e.pageY)) {
				$("#bikeFamilyDrop").hide();
			}
		});
	}
	
	function getDropDownHitArea() {
		if (document.getElementById("bikeFamilyDrop")) {
			// find position of hit area
			position = findPos(document.getElementById("bikeFamilyDrop"));
			hitAreaTopX = position[0];
			hitAreaTopY = position[1] - 30;
			hitAreaBottomX = hitAreaTopX + $("#bikeFamilyDrop").width() + 50;
			hitAreaBottomY = hitAreaTopY + $("#bikeFamilyDrop").height() + 30;
		}
	}
	
	function stillShowFamilyDropDown(mouseX, mouseY) {
		if ((mouseX < hitAreaTopX) || (mouseY < hitAreaTopY)) {
			return false;
		} else if ((mouseX > hitAreaBottomX) || (mouseY > hitAreaBottomY)) {
			return false;
		} else {
			return true;
		}
	}

	function findPos(obj) {
		var curleft = curtop = 0;
		if (obj.offsetParent) {
			curleft = obj.offsetLeft
			curtop = obj.offsetTop
			while (obj = obj.offsetParent) {
				curleft += obj.offsetLeft
				curtop += obj.offsetTop
			}
		}
		return [curleft,curtop];
	}

	function setMeasurementSystem(systemString) {
		$.cookie('MEASUREMENT_UNITS', systemString, {expires: 365});
		document.getElementById('geometryTable').className = systemString;
	}

	function getRealTop(e) {
		var realTop = 0;
		while (e.offsetParent) {
			realTop += e.offsetTop;
			e = e.offsetParent;
		}
		return realTop;
	}

	function getRealLeft(e) {
		var realLeft = 0;
		while (e.offsetParent) {
			realLeft += e.offsetLeft;
			e = e.offsetParent;
		}
		return realLeft;
	}
	
	function changeDetails(imageFileNameLarge, height) {
		MagicZoom_stopZooms();
		var oldRel = document.getElementById('zoom1').rel;
		var n = oldRel.indexOf(": ");
		var m = oldRel.indexOf("px");
		if(n == -1) { n = oldRel.length;}
		var nq = oldRel.substring(0, n);
		var nl = oldRel.substring(m);
		var newRel = nq+": "+height+nl;
		document.getElementById('zoom1').rel = newRel;
		//$("a.zoom1").attr("rel", newRel);
		MagicZoom_stopZooms();
		
		//alert(n+"@"+m);
		//$("img.bkImage").attr("src", '/templates/site/pictures/'+imageFileName);
		//var bikeImage = document.getElementById('bkImage');
		//var bc2 = document.getElementById('bc2');
		//var bikeImageLarge = bc2.firstChild.firstChild;
		/*
		if (!bikeImageLarge) {
			bikeImageLarge = bc2.lastChild.firstChild;
		}
		*/
		//bikeImage.src = '/templates/site/pictures/'+imageFileName;
		//bikeImageLarge.src = '/images/bikes/'+current_model_year+'/xl/'+imageFileName;

		// update selected item
		/*
		$(".bikeGalleryItem").removeClass("selected");
		idName = imageFileName.substring(0, (imageFileName.length - 4));
		$("#bikeGalleryThumbs #" + idName).addClass("selected");
		*/
		// update download image links
		$("a.download").attr("href", imageFileNameLarge);
		return false;
	}
