var isIE = (navigator.appVersion.indexOf("MSIE 6.0") > 0)?true:false;


function initImageMap(){
	jQuery('map').each(function(){
		
		var parent = jQuery(this).attr('parentNode');
		
		jQuery(this).mouseover(function(){
			jQuery(parent).addClass('active');
		});
		
		jQuery(this).mouseout(function(){
			//alert(parent);
			jQuery(parent).removeClass('active');
			
		});		
	});
}

function showInfo(id){
	
	
	jQuery('#map div, #legend img').removeClass('active');
	
	showLegend(id);
	
	jQuery('#legend img').css('z-index','0');
	
	jQuery('#map div').attr('isActive', '');
	jQuery('#map div.' + id + ', #' + id + '_legend').addClass('active');

	jQuery('#map div.' + id).attr('isActive', 'yes');
	
	jQuery('#map_view').slideUp(function(){
		
		jQuery('#map_view').html(jQuery('#' + id + '_list .content:first').html());		

		
	});
	jQuery('#map_view').slideDown('fast');
	
}

function showLegend(id){
	
	var parent = '#' + id;
	
	if(!isIE)
	{
		var w = jQuery(parent).width();
		var h = jQuery(parent).height();
		
		var l = jQuery(parent).css('left');
		var t = jQuery(parent).css('top');
		
		l = l.substr(0, l.length-2);
		t = t.substr(0, t.length-2);
		
		w = l*1 + (w / 2 - 27);
		h = t*1 + (h / 2 - 39);
		
		jQuery('#legend #'+id+'_legend').addClass('active');
		
		jQuery('#'+id+'_legend').css({
			position: 'absolute',
			left: w,
			top: h,
			zIndex: '1000000'
		});
		
	}
	else
	{		
		var w = document.getElementById(id).style.width;
		var h = document.getElementById(id).style.height;
	
		var l = document.getElementById(id).style.left;
		var t = document.getElementById(id).style.top;
		
		l = l.substr(0, l.length-2);
		t = t.substr(0, t.length-2);
		w = w.substr(0, w.length-2);
		h = h.substr(0, h.length-2);
		
		w = l*1 + (w / 2 - 27);
		h = t*1 + (h / 2 - 39);
		
		//alrt(w + ' ' + h);

		jQuery('#legend #'+id+'_legend').addClass('active');
		
		document.getElementById(id).className +=' active';
		
		//alert(document.getElementById(id).className + ' ' + id)
		
		with(document.getElementById(id + '_legend').style){
			position = 'absolute';
			left = w;
			top = h;
			zIndex = '1000000';
		}
		
	}
	
	
}

function manualInit(){
	try{
		
	jQuery('#legend img').each(function(){
		
		var src = jQuery(this).attr('src');
		src = src.replace(/\.png/, ".gif");
		jQuery(this).attr('src', src);
		
	});
		
	with(document.getElementById('cherkasy').style){
		left = '274px';
		top = '65px';
		height = '55px';
		width = '116px';
	}
	
	with(document.getElementById('chernigov').style){
		left = '308px';
		top = '8px';
		height = '57px';
		width = '95px';
	}
	/*
	with(document.getElementById('cherkasy').style){
		height = '57px';
		left = '308px';
		top = '8px';
		width = '95px';
	}
	*/

	with(document.getElementById('chernovci').style){
		height = '33px';
		left = '96px';
		top = '105px';
		width = '105px';
	}
	
	with(document.getElementById('dnepr').style){
		height = '55px';
		left = '392px';
		top = '94px';
		width = '147px';
	}
		
	with(document.getElementById('doneck').style){
		height = '76px';
		left = '523px';
		top = '88px';
		width = '94px';
	}
	
	with(document.getElementById('gitomir').style){
		height = '60px';
		left = '199px';
		top = '27px';
		width = '84px';
	}

	with(document.getElementById('harkov').style){
		height = '58px';
		left = '452px';
		top = '55px';
		width = '111px';
	}

	with(document.getElementById('herson').style){
		height = '56px';
		left = '337px';
		top = '143px';
		width = '143px';
	}

	with(document.getElementById('hmelnick').style){
		height = '63px';
		left = '152px';
		top = '55px';
		width = '68px';
	}
	
	with(document.getElementById('iv-frankovsk').style){
		height = '57px';
		left = '61px';
		top = '80px';
		width = '76px';
	}

	with(document.getElementById('kiev').style){
		height = '67px';
		left = '269px';
		top = '31px';
		width = '95px';
	}
	
	with(document.getElementById('kirovogradskiy').style){
		height = '48px';
		left = '276px';
		top = '94px';
		width = '150px';
	}	
	
	with(document.getElementById('krym').style){
		height = '67px';
		left = '376px';
		top = '187px';
		width = '171px';
	}	
	
	with(document.getElementById('luck').style){
		height = '43px';
		left = '92px';
		top = '17px';
		width = '79px';
	}	

	with(document.getElementById('lugansk').style){
		height = '65px';
		left = '555px';
		top = '65px';
		width = '88px';
	}
	
	with(document.getElementById('lvov').style){
		height = '55px';
		left = '36px';
		top = '49px';
		width = '103px';
	}
	
	with(document.getElementById('nikolaev').style){
		height = '59px';
		left = '292px';
		top = '124px';
		width = '113px';
	}

	with(document.getElementById('odessa').style){
		height = '98px';
		left = '204px';
		top = '125px';
		width = '130px';
	}

	with(document.getElementById('poltava').style){
		height = '54px';
		left = '360px';
		top = '55px';
		width = '118px';
	}

	with(document.getElementById('rovno').style){
		height = '52px';
		left = '130px';
		top = '17px';
		width = '94px';
	}
	
	with(document.getElementById('sumy').style){
		height = '61px';
		left = '386px';
		top = '8px';
		width = '92px';
	}

	with(document.getElementById('ternopol').style){
		height = '53px';
		left = '109px';
		top = '63px';
		width = '61px';
	}

	with(document.getElementById('vinnica').style){
		height = '56px';
		left = '194px';
		top = '75px';
		width = '95px';
	}

	with(document.getElementById('zakarpaty').style){
		height = '40px';
		left = '9px';
		top = '91px';
		width = '82px';
	}
	with(document.getElementById('zaporogie').style){
		left = '442px';
		top = '124px';
		height = '70px';
		width = '114px';
	}
	
	}
	catch(e){
		//alert(e);
	}
	
}

jQuery().ready(function(){
	
	//initImageMap()
	
	
	
	if(isIE)
	{
		manualInit();
	}

	/*css({
		height:'70px',
		left:442,
		top:'124px',
		width:'114px'
	});
	*/
	
	jQuery('a[region]').click(function(){
		
		var id = jQuery(this).attr('region');
		
		showInfo(id);
		
		return false;
		
	});
	
	jQuery('map area').each(function(){
		//alert(jQuery(this).attr('id'))
		
		/*
		var parent = jQuery(this).attr('parentNode');
		parent = jQuery(parent).attr('parentNode');
		var id = jQuery(parent).attr('id');
		*/
		
		var parent = jQuery(this).attr('parentNode');
		
		var id = jQuery(parent).attr('name');
		
		if(!document.getElementById(id))
		{
			jQuery('#map .' + id + ':first').attr('id', id);			
		}
		
		parent = '#' + id;
		
		
		jQuery(this).mouseover(function(){
			jQuery(parent).css('z-index','20000');
			jQuery(parent).addClass('active');
			jQuery(parent).css('opacity', 0);
			
			showLegend(id);
			
			jQuery(parent).animate({opacity: 1}, 100); 
			
		});
		
		jQuery(this).mousemove(function(){
			jQuery(parent).addClass('active');
			
			
		});
		
		jQuery(this).mouseout(function(){
			jQuery(parent).css('z-index','10000');
			if(jQuery(parent).attr('isActive') == 'yes')
			{
				return false;
			}
			jQuery(parent).removeClass('active');
			jQuery('#'+id+'_legend').removeClass('active');
			jQuery('#'+id+'_legend').css('z-index','0');
		});
		
		jQuery(this).click(function(){
			
			showInfo(id);
			
			return false;
			
		});
		

		
		
	});
	
});

