$(document).ready(function(){
	$(".menu li a.ml").click(function(){
		$(".menu li a.ml").removeClass("active");												 
		$(this).addClass("active");										 
		$(".sl").hide();
		$(this).siblings(".sl").fadeIn('fast');
	});

    var activeClass = 'dropdown-active', showingDropdown, showingMenu, showingParent;

    var hideMenu = function() {
    	if(showingDropdown) {
    		showingDropdown.removeClass(activeClass);
    		showingMenu.hide();
    	}
    };

    $('a.links').each(function() {
    	var dropdown = $(this);
    	var menu = dropdown.next('#footer_links'), parent = dropdown.parent();  
    	var showMenu = function() {
    		hideMenu();
    		showingDropdown = dropdown.addClass('dropdown-active');

    		showingMenu = menu.show();
    		showingParent = parent;
    	};

    	dropdown.bind('mouseenter',function(e) {
    		showMenu();
            $(this).parent().parent().addClass('current');
    	}).bind('click',function(){return false;})

    	dropdown.bind('focus',function() {
    		showMenu();
    	});
    });

  $(document).click(function(e) {
    if ($(e.target).is('#footer_links, #footer_links *'))  return true;
    else $('#footer_links').fadeOut('fast');
  }); 
  
	$(function () {
		var sel_cat = $("div.tabs ul.tab_nav li.switch a.selected").attr('href');
		$('div'+sel_cat).fadeIn();
		
		$('div.tabs ul.tab_nav li.switch a').click(function () {
		var sel_cat = $("div.tabs ul.tab_nav li.switch a.selected").attr('href');	
		var catid = $(this).attr('href');
			$('div'+sel_cat).hide();		
			$('a.selected').removeClass('selected');
			$('div'+sel_cat).fadeOut();
			$(this).addClass('selected');
			$('div'+catid).fadeIn();
		return false;
		});
	});
	
  $('#geo_box').each(function(){
		var ie = $.browser.msie && $.browser.version < 9 ? true : false,
			allShadows = $('img.shadow',this)
			.css({display:'none'}),
			activeId, activeShadow,
			messageBox = $('div.message-box',this),
			messageBoxCountry = messageBox.find('div.country-name'),
			messageBoxPercent = messageBox.find('div.percent strong'),
			documentObj = $(document),
			geoBoxOffset = $(this).offset();
		messageBox.find('*').each(function(){this.geoBoxFlag = true;});
		messageBox[0].geoBoxFlag = true;
		
		if($.browser.msie && $.browser.version == 6){
			allShadows.each(function(){
				var img = $(this),
					src = img.attr('src'),
					imgStyle = img.attr('style');
				imgStyle = imgStyle ? imgStyle : '';
				img.attr('style','background:"none";filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'+src+'",sizingMethod="crop");' + imgStyle)
				.attr('src',src.replace(/geo-block\/.*$/,'geo-block/blank.gif'));
			});
			$('img.countries',this).each(function(){
				var img = $(this),
					src = img.attr('src'),
					imgStyle = img.attr('style');
				imgStyle = imgStyle ? imgStyle : '';
				img.attr('style','background:"none";filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'+src+'",sizingMethod="crop");' + imgStyle)
				.attr('src',src.replace(/geo-block\/.*$/,'geo-block/blank.gif'));
			});
		}
		
		$('area',this).each(function(){
			var elem = $(this),
				country = elem.attr('alt'),
				percent = elem.attr('title');
				
			elem.attr('alt','');
			elem.attr('title','');
			
			
			if(percent == 'est'){
			
			percent = 'Brest region: <span style="font-size:14px;">1250-1400</span> euro<br/>';
			percent += 'Vitebsk region: <span style="font-size:14px;">1000-1150</span> euro<br/>';
			percent += 'Gomel region: <span style="font-size:14px;">1300-1450</span> euro<br/>';
			percent += 'Grodno region: <span style="font-size:14px;">1250-1400</span> euro<br/>';
			percent += 'Minsk region: <span style="font-size:14px;">1200-1250</span> euro<br/>';
			percent += 'Mogilev region: <span style="font-size:14px;">1250-1340</span> ';
			
			}
			
			if(percent == 'lt'){
			percent = 'Brest region: <span style="font-size:14px;">900-950</span> euro<br/>';
			percent += 'Vitebsk region: <span style="font-size:14px;">780-1000</span> euro<br/>';
			percent += 'Gomel region: <span style="font-size:14px;">900-950</span> euro<br/>';
			percent += 'Grodno region: <span style="font-size:14px;">850-900</span> euro<br/>';
			percent += 'Minsk region: <span style="font-size:14px;">750-950</span> euro<br/>';
			percent += 'Mogilev region: <span style="font-size:14px;">750-900</span>  ';	
			}

			if(percent == 'lv'){
			percent = 'Brest region: <span style="font-size:14px;">650-900</span> euro<br/>';
			percent += 'Vitebsk region: <span style="font-size:14px;">550-900</span>  euro<br/>';
			percent += 'Gomel region: <span style="font-size:14px;">700-900</span>  euro<br/>';
			percent += 'Grodno region: <span style="font-size:14px;">550-900</span>  euro<br/>';
			percent += 'Minsk region: <span style="font-size:14px;">650-900</span>  euro<br/>';
			percent += 'Mogilev region: <span style="font-size:14px;">700-900</span>  ';		
			}
			
			if(percent == 'pl'){
			percent = 'Brest region: <span style="font-size:14px;">850-900</span>  euro<br/>';
			percent += 'Vitebsk region: <span style="font-size:14px;">1150-1200</span>  euro<br/>';
			percent += 'Gomel region: <span style="font-size:14px;">1150-1230</span>  euro<br/>';
			percent += 'Grodno region: <span style="font-size:14px;">850-900</span>  euro<br/>';
			percent += 'Minsk region: <span style="font-size:14px;">1000-1100</span>  euro<br/>';
			percent += 'Mogilev region: <span style="font-size:14px;">1100-1150</span>  ';		
			}
			
			if(percent == 'chx'){
			percent = 'Brest region: <span style="font-size:14px;">900-950</span>  euro<br/>';
			percent += 'Vitebsk region: <span style="font-size:14px;">1000-1150</span>  euro<br/>';
			percent += 'Gomel region: <span style="font-size:14px;">1200-1350</span>  euro<br/>';
			percent += 'Grodno region: <span style="font-size:14px;">900-950</span>  euro<br/>';
			percent += 'Minsk region: <span style="font-size:14px;">1000-1050</span>  euro<br/>';
			percent += 'Mogilev region: <span style="font-size:14px;">1150-1700</span>  ';		
			}
			
			if(percent == 'aust'){
			percent = 'Brest region: <span style="font-size:14px;">1050-1200</span>  euro<br/>';
			percent += 'Vitebsk region: <span style="font-size:14px;">1350-1400</span>  euro<br/>';
			percent += 'Gomel region: <span style="font-size:14px;">1400-1480</span>  euro<br/>';
			percent += 'Grodno region: <span style="font-size:14px;">1100-1210</span>  euro<br/>';
			percent += 'Minsk region: <span style="font-size:14px;">1380-1400</span>  euro<br/>';
			percent += 'Mogilev region: <span style="font-size:14px;">1430-1450</span>  ';	
			}
			
			if(percent == 'frnc'){
			percent = 'Brest region: <span style="font-size:14px;">1500-1900</span>  euro<br/>';
			percent += 'Vitebsk region: <span style="font-size:14px;">2500-2700</span>  euro<br/>';
			percent += 'Gomel region: <span style="font-size:14px;">2500-2700</span>  euro<br/>';
			percent += 'Grodno region: <span style="font-size:14px;">1550-2000</span>  euro<br/>';
			percent += 'Minsk region: <span style="font-size:14px;">2350-2500</span>  euro<br/>';
			percent += 'Mogilev region: <span style="font-size:14px;">2500-2700</span>  ';		
			}
			
			if(percent == 'germ'){
			percent = 'Brest region: <span style="font-size:14px;">950-1050</span>  euro<br/>';
			percent += 'Vitebsk region: <span style="font-size:14px;">1100-1200</span>  euro<br/>';
			percent += 'Gomel region: <span style="font-size:14px;">1220-1250</span>  euro<br/>';
			percent += 'Grodno region: <span style="font-size:14px;">950-1060</span>  euro<br/>';
			percent += 'Minsk region: <span style="font-size:14px;">1200-1220</span>  euro<br/>';
			percent += 'Mogilev region: <span style="font-size:14px;">1200-1240</span>  ';	
			}
			
			if(percent == 'gol'){
			percent = 'Brest region: <span style="font-size:14px;">1100-1150</span>  euro<br/>';
			percent += 'Vitebsk region: <span style="font-size:14px;">1350-1400</span>  euro<br/>';
			percent += 'Gomel region: <span style="font-size:14px;">1400-1450</span>  euro<br/>';
			percent += 'Grodno region: <span style="font-size:14px;">1100-1150</span>  euro<br/>';
			percent += 'Minsk region: <span style="font-size:14px;">1150-1400</span>  euro<br/>';
			percent += 'Mogilev region: <span style="font-size:14px;">1150-1400</span>  ';		
			}
			
			if(percent == 'isp'){
			percent = 'Brest region: <span style="font-size:14px;">2700-2750</span>  euro<br/>';
			percent += 'Vitebsk region: <span style="font-size:14px;">3000-3200</span>  euro<br/>';
			percent += 'Gomel region: <span style="font-size:14px;">3150-3250</span>  euro<br/>';
			percent += 'Grodno region: <span style="font-size:14px;">2700-2780</span>  euro<br/>';
			percent += 'Minsk region: <span style="font-size:14px;">3000-3050</span>  euro<br/>';
			percent += 'Mogilev region: <span style="font-size:14px;">3050-3100</span> ';		
			}
			
			elem[0].country = country ? country : '';
			elem[0].percent = percent ? percent : 0;
			this.geoBoxFlag = true;
		}).mouseenter(function(e){
			documentAnimation = false;
		   	messageBox.stop();
			var elem = $(this),
				elemName = elem.attr('id').split('-'),
				country = elem[0].country,
				percent = elem[0].percent;
			elemName = elemName[1];
			activeId = '#area-shadow-' + elemName;
			
			if(activeShadow && $(activeId)[0] != activeShadow[0]){
				if(ie){
					activeShadow.css({display:'none'});
				}
				else {
					activeShadow.animate({opacity:0},200,function(){
						$(this).css({display:'none'});
					});
				}
			};
			
			messageBoxCountry.html(country);
			messageBoxPercent.html(percent);
			
			if(ie){
				activeShadow = $(activeId).stop().css({display:'block'});
				messageBox.css({
					display:'block',
					left:(0+ documentObj.scrollLeft() - geoBoxOffset.left - 122) + 'px',
					top:(0+ documentObj.scrollTop() -  geoBoxOffset.top - messageBox.height() - 5) + 'px'
				});
			}
			else {
				activeShadow = $(activeId).stop().css({display:'block'}).animate({opacity:1},200,function(){
					$(this).css({opacity:'auto'})
				});
				messageBox.css({
					display:'block',
					left:(0+ documentObj.scrollLeft() - geoBoxOffset.left - 122) + 'px',
					top:(0+ documentObj.scrollTop() -  geoBoxOffset.top - messageBox.height() - 5) + 'px'
				})
				.animate({opacity:1},200,function(){
					$(this).css({opacity:'auto'});
				});
			}
			
			if(e) e.stopPropagation();
			
		}).mousemove(function(e){
			messageBox.css({
				left:(e.clientX + documentObj.scrollLeft() - geoBoxOffset.left - 122) + 'px',
				top:(e.clientY + documentObj.scrollTop() -  geoBoxOffset.top - messageBox.height() - 5) + 'px'
			});
		}).click(function(){return false;});
		
		messageBox.mouseenter(function(e){
			
			documentAnimation = false;
			
			messageBox.css({
				left:(e.clientX + documentObj.scrollLeft() - geoBoxOffset.left - 122) + 'px',
				top:(e.clientY + documentObj.scrollTop() -  geoBoxOffset.top - messageBox.height() - 5) + 'px'
			});
			
			if(e) e.stopPropagation();
			
		});
		
		var documentAnimation = false;
		
		documentObj.mouseover(function(e){
			if(!e.target.geoBoxFlag && !documentAnimation && activeShadow){
				activeShadow.stop();
				messageBox.stop();
				documentAnimation = true;
				if(ie){
					activeShadow.css({display:'none'});
					messageBox.css({display:'none'});
					messageBoxCountry.html('');
					messageBoxPercent.html('');
					documentAnimation = false;
				}
				else {
					activeShadow.animate({opacity:0},200,function(){
						$(this).css({display:'none'});
					});
					messageBox.animate({opacity:0},200,function(){
						$(this).css({display:'none'});
						messageBoxCountry.html('');
						messageBoxPercent.html('');
						documentAnimation = false;
					});
				}
			};
		});
		
	});
   
   $('div.slider ul').each(function(i){
		var parent = $(this);
		var li = parent.children('li');
		var parentWidth = 0;
		var liLength = li.length;
		for(var i=0;i<liLength;i++){
			li[i].objWidth = li.eq(i).width()+ parseInt(li.eq(i).css('padding-left')) + parseInt(li.eq(i).css('padding-right'));
			li.eq(i).css({position:'absolute',left:parentWidth + 'px',top:0});
			parentWidth += li[i].objWidth;
		};
		parent.css({width:parentWidth});
		var setInt;
		var k = 0;
		function scrollObj(){
			var speed = li[k].objWidth/0.05;
			li.not(li.eq(0)).animate({left:'-=' + li[k].objWidth},speed,'linear');
			li.eq(0).animate({left:'-=' + li[k].objWidth},speed,'linear',function(){
				li.eq(k).css({left:(parentWidth - li[k].objWidth)+'px'});
				if(k < liLength - 1)
					k++;
				else {
					k = 0;
				};
				scrollObj()
			});
			
		};
		scrollObj();
		parent.mouseenter(function(){
			clearTimeout(setInt);
			li.stop();
		});
		parent.mouseleave(function(){
			var left = -1 * parseInt(li.eq(k).css('left'));
			var speed = (li[k].objWidth - left)/0.05;
			li.not(li.eq(0)).animate({left:'-=' + (li[k].objWidth - left)},speed,'linear');
			li.eq(0).animate({left:'-=' + (li[k].objWidth - left)},speed,'linear',function(){
				li.eq(k).css({left:(parentWidth - li[k].objWidth)+'px'});
				if(k < liLength - 1)
					k++;
				else {
					k = 0;
				};
				scrollObj()
			});
		});
	});
});
