
////change content in homepage///////
var ShowHideContent = new Class({
	Implements: [Options],
	
	options: {
		
	},
	initialize: function(element, options){
		this.element = $(element);
		this.setOptions(options);
		this.intScrollContent();		
	},
	intScrollContent: function(){
		if (!this.element) {
			return;
		}
			
		this.element.getElements('dl').each(function(item, index){
			var elementDD = item.getElement('dd');
			elementDD.store('myFx', new Fx.Tween(elementDD, {
				link:'ignore'								
			}));
			
			var elementA = item.getElement('dt a');

			elementDD.addEvents({
				mouseenter: function(evt){
					new Event(evt).stop();
					this.addClass('current');
					this.setStyle('cursor', 'pointer');
					
					if (item.hasClass('last')) {
						this.retrieve('myFx').cancel().start('top', 3);
					} else {
						this.retrieve('myFx').cancel().start('top', 50);
					}
				},
				
				click: function(evt){
					window.location = elementA.get('href');
				},
					
				mouseleave: function(evt){
					new Event(evt).stop();
					this.removeClass('current');	
					
					if (item.hasClass('last')) {
						this.retrieve('myFx').cancel().start('top', 125);
					} else {
						this.retrieve('myFx').cancel().start('top', 125);
					}
					
				}
			});
		});		
	}	
});
/////////////////////
function chooseLanguage(){
	var elements = $$('p.pad1 label');
	if(elements.length < 1){
		return;
	}
	elements[1].addEvent('click', function(evt){
		evt.stop();
		elements[2].removeClass('chekBoxCurrent');
		this.addClass('chekBoxCurrent');
		$$('input.languageType')[0].set('value', '1');
		
	});
	elements[2].addEvent('click', function(evt){
		evt.stop();
		elements[1].removeClass('chekBoxCurrent');
		this.addClass('chekBoxCurrent');
		$$('input.languageType')[0].set('value', '0');
			
	});
}

function initContactDealer() {
	// validate page
	var aDiv = $("contactDealer");
	if (aDiv == null) {
		return;
	}
	
	// get content of all cities
	var arrData = aDiv.getElements("div");
	
	// the last one contains list of countries and cities
	var container = arrData.pop();
	
	// get list of cities of each country
	var arrListCities = container.getElements("ul");
	
	// the first one is list of countries
	var countryList = arrListCities.shift();
	
	var curCountryIndex = 0;
	var counter = 0;
	
	//Set first active
	/*
	if(countryList.getElements("a")[0] && arrListCities[0]){
		countryList.getElements("a")[0].addClass("active");
		arrListCities[0].removeClass("hidden");
	}
	*/
	
	// add event listeners for all countries
	countryList.getElements("a").each(function(aLink, countryIndex) {
		
		if (aLink.hasClass("active")) {
			curCountryIndex = countryIndex;
		}
		
		aLink.addEvent("click", function(evt) {
			evt.stop();
			
			this.getParent().getParent().getElements("a")[curCountryIndex].removeClass("active");
			this.addClass("active");
			
			arrListCities[curCountryIndex].addClass("hidden");
			arrListCities[countryIndex].removeClass("hidden");
			curCountryIndex = countryIndex;
			
			//var activeCity = arrListCities[countryIndex].getElement("a");
			//activeCity.fireEvent("click", activeCity);
		});
		
		/*
		arrListCities[countryIndex].getElements("a").each(function(aCityLink, cityIndex) {
			aCityLink.counter = counter;
			
			aCityLink.addEvent("click", function(evt) {
				try {
					evt.stop();
				} catch (e) {}
				
				this.getParent().getParent().getElements("a").removeClass("active");
				this.addClass("active");
				
				for (var i = 0; i < arrData.length; i++) {
					arrData[i].addClass("hidden");
				}
				arrData[this.counter].removeClass("hidden");
			});
			
			counter++;
		});
		*/
	});
}


////////////////
window.addEvent('domready', function(){

	new ShowHideContent('highlight');
	chooseLanguage();
	
	initContactDealer();
	var so = new SWFObject("/Frontend/swfs/cochin.swf", "conchin", "1", "1", "8", "#000000");
	if (deconcept.SWFObjectUtil.getPlayerVersion().major < 8) {
		var aDiv = new Element("div");
		aDiv.set("html", so.getSWFHTML());		
		aDiv.setStyles({
			"visibility": "hidden",
			"position": "absolute",
			"top": "0",
			"left": "0"
		});
		aDiv.inject($$("body")[0]);
	}
});
