var headOff = new Array(0,0,0,0);
var seekVal='Поиск по сайту';
var loginEmail='e-mail';
var listUsers='';
var imgPath = 'img/';
var avaPath = 'uploads/avatars/';
var	wndW = wndH = 0;
var minis = new Array('mini_white.png','mini_blue.png','mini.png');
var cityH = 600;
var cityLocs = new Array('bg_antarctica.jpg', 'bg_spb.gif', 'bg_moscow.gif');
var miniCarNow = 0;
var currPlace = 0;
var posCurrPlaceX = 0;
var posCurrPlaceY = 0;
var forumTop = 0;
var forumLeft = 0;
var xsfTop = xsfLeft = 0;
var wlpPoint = new Array(0,0);
var cIndx = 0;
var io = 0;
var lockCurrPlace = 0;
var user_cities = new Array("Москва", "Санкт-Петербург");
var wherewego = new Array("В Москву?", "В Питер?");
var arrowsmoveon = new Array('moveonleft.png', 'moveonright.png');
var trafficlights = new Array('yaprobki_gre.jpg;#40b612', 'yaprobki_yel.jpg;#ffdd1f', 'yaprobki_red.jpg;#ff3300');
var trafficballs = new Array(4, 7, 10);
var trafficblabla = new Array('Город едет', 'Движение затруднено', 'Город стоит');
var miniKitShopBanners = new Array('banners/mp-kit-shop/kitshop.jpg;minipeople.printdirect.ru;MINIPeople Kit Shop', 'banners/mp-kit-shop/kitshop_and.jpg;minipeople.printdirect.ru;MINIPeople Kit Shop',
'banners/mp-kit-shop/watches.jpg;forum.minipeople.ru/index.php?/topic/11737-Эксклюзивное часовое предложение/;Эксклюзивное часовое предложение');

$(document).ready(function(){
	initMods();
	initBanners();
	initTrafficData();
	initMoveOn();
	initBlocksNavigation();

	/*
	$('.adv_contact a').mouseover(function(){
		$(this).css('text-decoration', 'none');
	});
	
	$('.adv_contact a').mouseout(function(){
		$(this).css('text-decoration', 'underline');
	});
	*/

	$('.block_link a, .mpopaque a, #minichanger, .adv_contact a, #minimap a, .minianchors a').live('mouseover', function(){
		$(this).css('text-decoration', 'none');
	});

	$('.block_link a, .mpopaque a, #minichanger, .adv_contact a, #minimap a, .minianchors a').live('mouseout', function(){
		$(this).css('text-decoration', 'underline');
	});

	$('#moveonrwing .moveontext').live('mouseover', function(){
		if ($('#lockPlace').val()=='1') {
			$(this).css('text-decoration', 'none');
		}
	});

	$('#moveonrwing .moveontext').live('mouseout', function(){
		if ($('#lockPlace').val()=='1') {
			$(this).css('text-decoration', 'underline');
		}
	});

	$('#moveonlwing .moveontext').live('mouseover', function(){
		if ($('#lockPlace').val()=='2') {
			$(this).css('text-decoration', 'none');
		}
	});

	$('#moveonlwing .moveontext').live('mouseout', function(){
		if ($('#lockPlace').val()=='2') {
			$(this).css('text-decoration', 'underline');
		}
	});

	$('#forum_text_link img').live('mouseover', function(){
		$(this).attr('src', imgPath+'forumlink_active.gif');
	});
	
	$('#forum_text_link img').live('mouseout', function(){
		$(this).attr('src', imgPath+'forumlink_idle.gif');
	});

	$('#mini_russia_lable img').mouseover(function(){
		$(this).attr('src', imgPath+'minirussia_active.gif');
	});
	
	$('#mini_russia_lable img').mouseout(function(){
		$(this).attr('src', imgPath+'minirussia_idle.gif');
	});

	$('#mini_world_lable img').mouseover(function(){
		$(this).attr('src', imgPath+'miniworld_active.gif');
	});
	
	$('#mini_world_lable img').mouseout(function(){
		$(this).attr('src', imgPath+'miniworld_idle.gif');
	});

	$('#mini_blogs_lable img').mouseover(function(){
		$(this).attr('src', imgPath+'miniblogs_active.gif');
	});
	
	$('#mini_blogs_lable img').mouseout(function(){
		$(this).attr('src', imgPath+'miniblogs_idle.gif');
	});

	$('#mini_gallery_lable img').mouseover(function(){
		$(this).attr('src', imgPath+'minigallery_active.gif');
	});
	
	$('#mini_gallery_lable img').mouseout(function(){
		$(this).attr('src', imgPath+'minigallery_idle.gif');
	});

	$('#mini_media_lable img').mouseover(function(){
		$(this).attr('src', imgPath+'minivideo_active.gif');
	});
	
	$('#mini_media_lable img').mouseout(function(){
		$(this).attr('src', imgPath+'minivideo_idle.gif');
	});

	$('#search_go').click(function(){
		if ($('#searchstring').val().length) {
			document.forms.funsiteSearch.submit();
		}
	});
	
	$('#funsiteSearch').submit(function(){
		if ($('#searchstring').val().length) {
			document.forms.funsiteSearch.submit();
		}
	});
	
	$('#minichanger').click(function(){
		mininiChanger();
	});

	if ($('#lockPlace').val()=='2') {
		$('#moveonright').css('opacity', '0.1');
		$('#moveonleft').css('opacity', '1');
		$('#moveonright').css('cursor', 'default');
		$('#moveonleft').css('cursor', 'pointer');
		$('#moveonrwing .moveontext').css('text-decoration', 'none');
		$('#moveonrwing .moveontext').css('color', '#191919');
		$('#moveonlwing .moveontext').css('color', '#fff');
		$('#moveonlwing .moveontext').css('text-decoration', 'underline');
	} else {
		$('#moveonright').css('opacity', '1');
		$('#moveonleft').css('opacity', '0.1');
		$('#moveonright').css('cursor', 'pointer');
		$('#moveonleft').css('cursor', 'default');
		$('#moveonrwing .moveontext').css('color', '#fff');
		$('#moveonlwing .moveontext').css('text-decoration', 'none');
		$('#moveonrwing .moveontext').css('text-decoration', 'underline');
		$('#moveonlwing .moveontext').css('color', '#191919');	
	}

	tp = $('#minianchorstop').attr('offsetTop');
	$('.minianchmarker').css({top: tp});

	$('.minianchors a').live('mouseover', function(){
		tp = $(this).attr('offsetTop')-4;
		$('.minianchmarker').animate({top: tp, speed: 'fast'});
	});

	$('#mininav').live('mouseout', function(e){
		var x = e.pageX;
		var y = e.pageY;
		
		//$('.accent_bold').html('x: ' + x + ' headOff[0]: ' + headOff[0] + ' y: ' + y + ' headOff[1]: ' + headOff[1] + ' headOff[2]: ' + headOff[2] + ' headOff[3]: ' + headOff[3]);
		
		if (x<headOff[0] || y<headOff[2] || x>headOff[1] || y>headOff[3]){
			tp = $('#minianchorstop').attr('offsetTop');
			$('.minianchmarker').animate({top: tp, speed: 'fast'});
		}

	});
	
	$(window).bind('resize', function() {
		initMods();
	});

});

function initMods(){
	lft = 0;
	leftPos = 0;
	hWidth = $(window).width();
	if (hWidth>1200) {
		lft = (hWidth-1000)/2;
	}

	$('#roadtomini').css({left: lft});
	
	lockThePlace(0);
	var avatar = 'url('+avaPath+$('#avatarfile').val()+') top left repeat';
	$('#minipeople_avatars').css({background: avatar});

	/*
	if ($('#lockPlace').val()=='2') {
		$('#minieventspb').css({opacity: 0});
		$('#minieventspb_text').fadeOut();
	} else {
		$('#minieventmsk').css({opacity: 0});
		$('#minieventmsk_text').fadeOut();
	} */

	headOff[0] = parseInt($('#roadtomini').attr('offsetLeft')) + parseInt($('#mininav').attr('offsetLeft'));
	headOff[1] = parseInt($('#roadtomini').attr('offsetLeft')) + parseInt($('#mininav').attr('offsetLeft')) + parseInt($('#mininav').width());
	headOff[2] = 245;
	headOff[3] = 320;
	
}

function initBanners() {
	if (cIndx==undefined) cIndx = 0;
	
	var miniKitShopBannersTemp = miniKitShopBanners[cIndx].split(';');

	$('#bnrrotator').attr('href', 'http://' + miniKitShopBannersTemp[1]);
	$('#bnrrotator img').attr('src', miniKitShopBannersTemp[0]);
	$('#bnrrotator img').attr('alt', miniKitShopBannersTemp[2]);
	$('#bnrrotator img').attr('title', miniKitShopBannersTemp[2]);

	cIndx = cIndx==miniKitShopBanners.length-1 ? 0 : cIndx+1;
	setTimeout("initBanners()", 1800);
}

function mininiChanger() {
	var miniIndx = parseInt($('#lockMININow').val());

	miniIndx = miniIndx==minis.length-1 ? 0 : miniIndx+1;
	miniBackCSS = 'url('+imgPath+minis[miniIndx]+') 110px top no-repeat';

	$('#minini').css({background: miniBackCSS});
	$('#lockMININow').val(miniIndx);
}

function initMoveOn() {
	$('#moveonrwing .moveontext, #moveonright').click(function(){
		if ($('#lockPlace').val()=='1') {
			$('#lockPlace').val('2');
			/*
			$('#minieventspb').css({opacity: 0});
			$('#minieventspb_text').fadeOut();
			$('#minieventmsk').css({opacity: 1});
			$('#minieventmsk_text').fadeIn();
			*/
			cityarrId = 1;
			lockThePlace(1);
			newLocPos = "'(" + (lockCurrPlace-posCurrPlaceX) + "px" + " " + posCurrPlaceY + "px)'";

			$('#minini #leftwheel, #minini #rightwheel').animate({opacity: '0.5', speed: 'slow'});
			$('#minini #leftwheel, #minini #rightwheel').css({visibility:'visible'});
			$('#minini #leftwheel, #minini #rightwheel').animate({opacity: '1', speed: 'slow'});
		
			/*
			if (cityarrId==0) {
			$('#minieventmsk_text').fadeOut(100);
			$('#minieventmsk').animate({left:'-300px', opacity: 0},600);
			$('#minieventspb').animate({left:'760px', opacity: 1},600);
			$('#minieventspb_text').fadeIn(100);
			} else {
			$('#minieventspb_text').fadeOut(100);
			$('#minieventspb').animate({left:'-300px', opacity: 0},600);
			$('#minieventmsk').animate({left:'760px', opacity: 1},600);
			$('#minieventmsk_text').fadeIn(100);
			}
			*/

			$('#moveonright').animate({opacity: '0.1', speed: 'slow'});
			$('#moveonleft').animate({opacity: '1', speed: 'slow'});
			$('#moveonright').css('cursor', 'default');
			$('#moveonleft').css('cursor', 'pointer');
			$('#moveonrwing .moveontext').css('color', '#191919');
			$('#moveonrwing .moveontext').css('text-decoration', 'none');
			$('#moveonlwing .moveontext').css('color', '#fff');
			$('#moveonlwing .moveontext').css('text-decoration', 'underline');

			$('body').stop().animate({backgroundPosition: newLocPos}, 1000, function(){
				$('#minini #leftwheel, #minini #rightwheel').css({visibility:'hidden'});
			});
		}
	});
	
	$('#moveonlwing .moveontext, #moveonleft').click(function(){
		if ($('#lockPlace').val()=='2') {
			$('#lockPlace').val('1');

			/*
			$('#minieventspb').css({opacity: 0});
			$('#minieventspb_text').fadeOut();
			$('#minieventmsk').css({opacity: 1});
			$('#minieventmsk_text').fadeIn();
			*/

			cityarrId = 0;
			lockThePlace(1);
			newLocPos = "'(" + (lockCurrPlace-posCurrPlaceX) + "px" + " " + posCurrPlaceY + "px)'";

			$('#minini #leftwheel, #minini #rightwheel').animate({opacity: '0.5', speed: 'slow'});
			$('#minini #leftwheel, #minini #rightwheel').css({visibility:'visible'});
			$('#minini #leftwheel, #minini #rightwheel').animate({opacity: '1', speed: 'slow'});
		
			/*
			if (cityarrId==0) {
			$('#minieventmsk_text').fadeOut(100);
			$('#minieventmsk').animate({left:'-300px', opacity: 0},600);
			$('#minieventspb').animate({left:'760px', opacity: 1},600);
			$('#minieventspb_text').fadeIn(100);
			} else {
			$('#minieventspb_text').fadeOut(100);
			$('#minieventspb').animate({left:'-300px', opacity: 0},600);
			$('#minieventmsk').animate({left:'760px', opacity: 1},600);
			$('#minieventmsk_text').fadeIn(100);
			}
			*/

			$('#moveonright').animate({opacity: '1', speed: 'slow'});
			$('#moveonleft').animate({opacity: '0.1', speed: 'slow'});
			$('#moveonright').css('cursor', 'pointer');
			$('#moveonleft').css('cursor', 'default');
			$('#moveonrwing .moveontext').css('color', '#fff');
			$('#moveonrwing .moveontext').css('text-decoration', 'underline');
			$('#moveonlwing .moveontext').css('color', '#191919');
			$('#moveonlwing .moveontext').css('text-decoration', 'none');

			$('body').stop().animate({backgroundPosition: newLocPos}, 1000, function(){
				$('#minini #leftwheel, #minini #rightwheel').css({visibility:'hidden'});
			});
		}
	});
	
}

function lockThePlace(isMove){
	currPlace = parseInt($('#lockPlace').val());

	lockCurrPlace = (3800-(1900*(currPlace-1))-3800);
	posCurrPlaceX = (1900-$(window).width())/2;
	posCurrPlaceY = -65;

	if (isMove==0) {
		newLocPos = "'(" + (lockCurrPlace-posCurrPlaceX) + "px" + " " + posCurrPlaceY + "px)'"
		$('body').stop().animate({backgroundPosition: newLocPos}, 10);

		/* if (currPlace==2) {
			$('#minieventmsk').css({left:'760px'});
			$('#minieventspb').css({left:'-300px'});
		} else {
			$('#minieventmsk').css({left:'-300px'});
			$('#minieventspb').css({left:'760px'});
		} */
		
	}

}

function initTrafficData() {
	probki_city = '';
	probki_balls = '';
	probki_balls_text = '';
	probki_info = '';
	probki_info_text = '';

	if ($('#track').html()!='') {
	
	if ($('#track').text().substr(0,6)!='Пробки'){
		probki_city = 'В Москве';
		probki_balls = $('#track').html();
		probki_balls_text = $('#track div h2 b').text().substr(2);
		probki_info = $('#track div em a').text().split(' ');
	
		for (i=0;i<probki_info.length;i++) {
			if (i<probki_info.length-1){
				probki_info_text += probki_info[i]+'<br />';
			} else {
				probki_info_text += probki_info[i];
			}
		}
	
	} else {
		probki_city = 'В Москве';
		probki_balls = $('#track').html();
		probki_balls_text = $('#track').text().substr(7, ($('#track').text().length-8));
	}
	
	if (parseInt(probki_balls)>0) {
		for (i=0;i<trafficballs.length;i++) {
			if (parseInt(probki_balls)<trafficballs[i]) {
				custTraffStyle = trafficlights[i].split(';');
				$('#yaprobki').css('background', 'url(img/'+custTraffStyle[0]+') top left no-repeat');
				$('#yaprobki_ball').css('color', custTraffStyle[1]);
				probki_info_text = trafficblabla[i];
				break;
			}
		}
	} else {
		probki_balls = '0';
		probki_balls_text = 'баллов';
		custTraffStyle = trafficlights[0].split(';');
		$('#yaprobki').css('background', 'url(img/'+custTraffStyle[0]+') top left no-repeat');
		$('#yaprobki_ball').css('color', custTraffStyle[1]);		
		probki_info_text = 'Дороги свободны!';
	}

	$('#yaprobki_text').html(probki_info_text);
	//$('#yaprobki_city').html('В Москве');
	$('#yaprobki_ball').html(probki_balls);
	$('#yaprobki_ball_label').html(probki_city + ' ' + probki_balls_text);
	
	}
}

function initBlocksNavigation() {
	$('.gointo a, .post_active a, .post_idle a').live('mouseover', function(){
		$(this).css('text-decoration', 'none');
	});

	$('.gointo a, .post_active a, .post_idle a').live('mouseout', function(){
		$(this).css('text-decoration', 'underline');
	});

	$('.playmedia_idle img').live('mouseover', function(){
		$('.playbtn img').attr('src', 'img/play001.png');
		$('.playmedia_active').attr('class', 'playmedia_idle');		
		$(this).parent().attr('class', 'playmedia_active');
		$('.playmedia_active .playbtn img').attr('src', 'img/play002.png');
	});
	
	$('.post_idle').live('mouseover', function(){
		$(this).parent().children('.post_active').children('.footer_active').attr('class', 'footer_idle');
		$(this).parent().children('.post_active').attr('class', 'post_idle');
		$(this).attr('class', 'post_active');
		$(this).children('.footer_idle').attr('class', 'footer_active');
	});

	$('.playmedia_idle[vid]').live('mouseover', function(){
		//$('#vid0').html($('.postdata[vid='+$(this).attr('vid')+']').html());
		$('#mini_media .full_info .postdata').attr('class', 'postdata idle');
		$('#mini_media .full_info .postdata[vid='+$(this).attr('vid')+']').toggleClass('postdata active');				
	});
	
	$('.post_idle[rssid]').live('mouseover', function(){
		$('#mini_world .full_info .postdata').attr('class', 'postdata idle');
		$('#mini_world .full_info .postdata[rssid='+$(this).attr('rssid')+']').toggleClass('postdata active');		
	});

	$('.post_idle[galid]').live('mouseover', function(){
		$('#mini_gallery .full_info .postdata').attr('class', 'postdata idle');
		$('#mini_gallery .full_info .postdata[galid='+$(this).attr('galid')+']').toggleClass('postdata active');		
	});

	$('.post_idle[bid]').live('mouseover', function(){
		$('#mini_blogs .full_info .postdata').attr('class', 'postdata idle');
		$('#mini_blogs .full_info .postdata[bid='+$(this).attr('bid')+']').toggleClass('postdata active');		
	});

	$('.post_idle[tid]').live('mouseover', function(){
		$('#mini_russia .full_info .postdata').attr('class', 'postdata idle');
		$('#mini_russia .full_info .postdata[tid='+$(this).attr('tid')+']').toggleClass('postdata active');
	});
	
}