var country_arr;

////////////////////////////////////////////////////// DEALER FLASH MODULE  ////////////////////////////////////////////////////// 

function loadDealerModule(id, countrylist, extra, cnt){
	//create holder
	var object = $('#'+id);
	object.html('<div id="world"></div>');
	//get countries
	$.ajax({
			type	: 'POST',
			url		: '/ajax.php?lang='+$('html').attr('lang'),
			data	: {
				m		: 'GETCOUNTRYARR'
			},
			success	: function(data){
				
				var output = data;
				country_arr = output.split(',');
				
				//write module
				var lang = $('html').attr('lang');
				var flashvars = {file: "/ajax.php?m=GETCOUNTRIES", countryList: countrylist, cntry: extra, cnt:cnt, language:lang};
				var params = {wmode: "transparent", allowScriptAccess: "always"};
				swfobject.embedSWF("/media/swf/world.swf", "world", "100%", "100%", "9.0.0", "/media/swf/expressInstall.swf", flashvars, params);
			}
	});
}
function loadWorld(id){
	var fla = document.getElementById('world');
	fla.loadWorldJS();
	clearCountryList();
}
function loadContinent(id){
	var fla = document.getElementById('world');
	fla.loadContinentJS(id);
	clearCountryList();
}
function loadCountry(id){
	var fla = document.getElementById('world');
	fla.loadCountryJS(id);
}
function setContinentList(id){
	if(id>=0){
		$('#dealernavcontinents li a').css({'color': '#fff'});
		$('#dealernavcontinents li:eq('+id+') a').css({'color': '#8E181B'});
		$('#dealernavworld li a').css({'color': '#fff'});
	}else{
		$('#dealernavcontinents li a').css({'color': '#fff'});
		$('#dealernavworld li a').css({'color': '#8E181B'});
	}
}
function setCountryList(id){
	//alert("ok");
	$('#dealernavcountries ul.minicol li a').css({'color': '#fff'});
	$('#dealernavcountries ul.minicol li:eq('+id+') a').css({'color': '#8E181B'});
}
function loadCountryList(arr){

	var posArr = arr.split(',');

	//flash outputs an array with positions of the countries, work around for Flash Mac fucking up chars, compare numberArray with positions with the countrylist
	var newArr = new Array();
	for(i=0; i<posArr.length; i++){
		var position = posArr[i];
		newArr[i] = country_arr[position];
	}

	var obj = document.getElementById("dealernavcountries");
	var temp = newArr;
	var html = "<ul class='minicol'>";

	for(i=0; i<temp.length; i++){
		html += "<li><a href='javascript:loadCountry("+i+");' title='show "+temp[i]+"'>"+temp[i]+"</a></li>";
	}
	html += "</ul>";
	obj.innerHTML = html;
}
function clearCountryList(){
	//clear country list
	var obj = document.getElementById("dealernavcountries");
	obj.innerHTML = "";
}
function setDealers(country,area){
	$('#dealers .contactDealer').unbind('click');
	hidePostalCode();
	$('#dealers').html('');
	
	$.ajax({
		type	: 'POST',
		url		: '/ajax.php?lang='+$('html').attr('lang'),
		data	: {
			m		: 'INTERDEALERS',
			country	: country_arr[country],
			area : area
		},
		success	: function(data){
			$('#dealers').html(data);
			//alert('data')
			/*$('#dealers .contactDealer').click(function(){
				var dealerEmail = $(this).attr('rel');
				openPopUp(dealerEmail);
			});*/
		}
	})
}
function loadPostalCode(c){
    $('#dealers').html('');
    var obj = $("#dealerpostal");
    obj.attr('rel', c);
    obj.show();
}
function hidePostalCode(){
	var obj = $("#dealerpostal");
	obj.hide();
}

function getDealerByPostalCode(c,postcode){
    //alert(c)
	$.ajax({
		type	: 'POST',
		url		: '/ajax.php?lang='+$('html').attr('lang'),
		data	: {
			m			: 'DEALERS',
			country		: c,
			postcode	: postcode
		},
		success	: function(data){
			$('#dealers').html(data);
			$('#dealers .contactDealer').click(function(){
				var dealerEmail = $(this).attr('rel');
				openPopUp(dealerEmail);
			})
		}
	
	})	
}

function getDefaultDealer(c){
	
}

function openPopUp(e){
	$('#contactDealerClose').unbind('click');
	$('#contactDealerWrapper, #contactDealer').show();
	$('#emailDealer1, #emailDealer').val(e);
	$('#contactDealerClose').click(function(){
		$('#contactDealerWrapper, #contactDealer').hide();
	})
}
