
function view(type)
{
	closeall();
	
	if(type=='map')
	{
		$('map-map').style.display = 'block';
		$(type+'-btn').src ='assets/images/'+type+'-btn-hover.gif';
		$(type+'-btn').stopObserving('mouseout');
		$('property-btn').src = 'assets/images/property-btn.gif';
		Event.observe($('property-btn'), 'mouseout', function() { $('property-btn').src='assets/images/property-btn.gif'; });
	}
	else {
		$('properties').style.display = 'block';
		$('property-btn').src ='assets/images/property-btn-hover.gif';
		$('property-btn').stopObserving('mouseout');
		$('map-btn').src = 'assets/images/map-btn.gif';
		Event.observe($('map-btn'), 'mouseout', function() { $('map-btn').src='assets/images/map-btn.gif'; });
		move('right',0);
		$('mainimg').src = 'assets/images/home-bg.jpg';
		new Effect.Parallel([
		  new Effect.appear($('mainimg'), { sync: true, from: 0, to: 1}) 
		], { 
		  duration: 0.5
		});
	}
}
function closeall()
{
	$('map-map').style.display = 'none';
	$('properties').style.display = 'none';
}
function show_property(country,state,city)
{
	$$('.black').each(function(s){ s.style.display='none'; });
	$$('.href').each(function(s){ s.style.backgroundColor =''; });
	//$('mainimg').fade({ duration: 1.0, from: 1, to: 0 });

	new Ajax.Request('index.php', {
		method: 'post',
		parameters: {
			'fx':'show_property',
			'country':country,
			'state':state,
			'city':city
		},
		onSuccess: function(transport) {
			$('desc').style.visibility='visible';
			$('desc').update(transport.responseText);
			setDefault();
			city = city.toLowerCase();
			city = city.replace(" ","");
			$(city+'_img').src = 'assets/images/'+city+'_gold.png';
			$(city+'_img').stopObserving('mouseout');
			Event.observe($(city+'_img'), 'mouseout', function() { $(city+'_img').src='assets/images/'+city+'_gold.png'; });
			$(city+'_href').style.backgroundColor ='#000000';
			$('mainimg').fade({ 
				duration: 0.5, 
				from: 1, 
				to: 0,
				afterFinish: function() {
					$('mainimg').src = 'assets/images/'+city+'-bg.jpg';	
					new Effect.Parallel([
					  new Effect.Appear($('desc'), { sync: true, from: 0, to: 1}), 
					  new Effect.Appear($('mainimg'), { sync: true, from: 0, to: 1}) 
					], { 
					  duration: 0.5
					});
				}
			});
			$(city+'_black_bar').style.display='block';
			
		}
	});
}
function closeDesc()
{
	$('desc').fade({ duration: 1.0, from: 1, to: 0 });
}
function setDefault()
{
	$$('.city_img').each(function(s) {
		var id = s.id;					
		id = id.replace("_img","");
		s.stopObserving('mouseover');
		s.stopObserving('mouseout');				
		s.src='assets/images/'+id+'.png';
		Event.observe(s, 'mouseover', function() { s.src='assets/images/'+id+'_gold.png'; });
		Event.observe(s, 'mouseout', function() { s.src='assets/images/'+id+'.png'; });
	});
}
function initialize()
{
	Event.observe($('property-btn'), 'mouseover', function() { $('property-btn').src='assets/images/property-btn-hover.gif'; });
	Event.observe($('map-btn'), 'mouseout', function() { $('map-btn').src='assets/images/map-btn.gif'; });
	Event.observe($('map-btn'), 'mouseover', function() { $('map-btn').src='assets/images/map-btn-hover.gif'; });
	Event.observe('button-right', 'mouseover', function() { move('right'); });
	Event.observe('button-right', 'mouseout', function() { active = 0; });
	Event.observe('button-left', 'mouseout', function() { active = 0; });
}
function handle(oEvent) {
	var clickedX = oEvent.clientX;
	var screenWidth = screen.width;
	var initialVal = (screenWidth - 912)/2;
	var temp = initialVal + (1*184);
	var i = 1;
	while(temp < clickedX)
	{
		i++;
		temp = initialVal + (i*184);
		
	}
	if(i-1>0)
	{
		var distance = (i-1)*184;
		distance = 0 - distance;
		move('left',distance);
	}
}

function move(to,x) 
{	
	if(to=='left')
	{
		var pos = 184;
	}
	else if(to=='right')
	{
		var pos =-184;	
	}

	if(x != undefined)
	{
		if(x == 0)
		{
			pos = x - moveI;
		}
		else if(x < 0) 
		{
			pos= x;		
		}
	}
	else {
		active=1;
		setDefault();	
	}	
	
	moveI += pos;	
	
	
	new Effect.Move($('cities'), { 
		x: pos,
		y: 0,
		beforeStart: function() {
			$('button-right').stopObserving('mouseover');
			$('button-left').stopObserving('mouseover');
			$('desc').hide();
			$$('.black').each(function(s){ s.style.display='none'; });
			$$('.city_img').each(function(s) {
			var id = s.id;					
			id = id.replace("_img","");
			s.stopObserving('mouseover');
			s.stopObserving('mouseout');				
			s.src='assets/images/'+id+'.png';
			Event.observe(s, 'mouseover', function() { s.src='assets/images/'+id+'_gold.png'; });
			Event.observe(s, 'mouseout', function() { s.src='assets/images/'+id+'.png'; });
		});
		},
		afterFinish: function(e) 
		{
			//alert(moveI+' '+active);
				if(to=='right' && moveI<=-914)
				{
					if(active==1)
					{
						active=0;	
					}
				}
				else if(to=='left' && moveI>=0)
				{
					if(active==1)	
					{
						active=0;	
					}
				}
			if(moveI>=0)
			{
				Event.observe('button-right', 'mouseover', function() { move('right'); });	
				if(active==1)
				{
					move(to);
				}
			}
			else if(moveI<-914)
			{
				Event.observe('button-left', 'mouseover', function() { move('left'); });
				if(active==1)
				{
					move(to);
					
				}
			}
			else {
				Event.observe('button-right', 'mouseover', function(e) { 
					move('right'); 
				});
				Event.observe('button-left', 'mouseover', function(e) { 
					move('left'); 
				});
				if(active==1)
				{
					move(to);
				}
			}
			
		}
	});	            	
	return false;
}
