	var videoListOffset=0;
	var videoListLimit=-822;
	var pageMain = 1;
	var pageChanges = 2;
	var pageNewPlaces = 3;
	var pageNewItems = 4;
	var pageNewQuests = 5;
	var pageOtherAbilitys = 6;
$(document).ready(function() {
	calcHeight();
	processWidth();
	$(".beginPlay").hover(function() {
		$(".button").addClass("button_hover");
	},function() {
		$(".button").removeClass("button_hover");
	})
	$(".videoUp").hide();
	$(".videoUp").hover(function() {
		$(".videoUp").addClass("arrow_hover");
	},function() {
		$(".videoUp").removeClass("arrow_hover");
	})
	$(".videoDown").hover(function() {
		$(".videoDown").addClass("arrow_hover");
	},function() {
		$(".videoDown").removeClass("arrow_hover");
	})

	$(".videoUp").click(function() {
		scrollVideoUp();
	});
	$(".videoDown").click(function() {
		scrollVideoDown();
	});
	
	$(".videoBorder").click(function() {
		var id=$(this).find(".vid").html();
		setVideo(id);
	});
	
	initShowers();
	initLightBox();
	initSwitcher()
	switch(thisPage) {
		case pageMain:
			setVideo(13005667);
			break;
		case pageChanges:
			setVideo(13006045);
			break;
		case pageNewPlaces:
			setVideo(13006022);
			break;
		case pageNewItems:
			setVideo(13006007);
			break;
		case pageNewQuests:
			setVideo(13006016);
			break;		
		case pageOtherAbilitys:
			setVideo(13006046);
			break;
	}

	//сворачивающиеся-разворачивающиеся дивы
	$('.collapse_spread_key').click(function () {
		var key = this;
		var collapse_spread_div=$(this).parent();
		$(collapse_spread_div).children('.collapse_spread').toggle('blind', { direction: 'vertical' }, 300,function(){
		calcHeight();
		});
		
	});
	$(".screenshot_map").hover(function() {
		$(this).find("img").show();
	},function () {
		$(this).find("img").hide();
	});
	$(".screenshot_man").hover(function() {
		$(this).find("img").show();
	},function () {
		$(this).find("img").hide();
	});
	$(".screenshot_actions").hover(function() {
		$(this).find("img").show();
	},function () {
		$(this).find("img").hide();
	});
	$(".screenshot_forums").hover(function() {
		$(this).find("img").show();
	},function () {
		$(this).find("img").hide();
	});	
	$(".screenshot_olimp").hover(function() {
		$(this).find("img").show();
	},function () {
		$(this).find("img").hide();
	});		
});

$(window).resize(function() {
	processWidth();
});

function processWidth() {
	var obj=getWindowSizes();

	var width = obj[0];

	if (width<1259) {
		//shrink
		if (width>1000) {
			$(".wrapper").css({'width':width+'px'});
		} else {
			$(".wrapper").css({'width':'1000px'});
		}
		$(".wrapper").addClass("shrink");
	
	} else {
		//unshrink
		$(".wrapper").css({'width':'1259px'});
		$(".wrapper").removeClass("shrink");	
	}
}
function getWindowSizes() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = $(window).width();
    myHeight = $(window).height();
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  //window.alert( 'Width = ' + myWidth );
  //window.alert( 'Height = ' + myHeight );
  return [myWidth,myHeight];
}
function setVideo(id) {
	$('.video').html(generateVideoHTML(id));
}

function generateVideoHTML(id) {
	//id == 13002434
	var videoWidth=414;
	var videoHeight=274;
	
	return '<object width="'+videoWidth+'" height="'+videoHeight+'"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id='+id+'&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=0&amp;show_portrait=0&amp;color=00adef&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id='+id+'&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=0&amp;show_portrait=0&amp;color=00adef&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="'+videoWidth+'" height="'+videoHeight+'"></embed></object>';
}

function scrollVideoUp() {
	videoListOffset=videoListOffset+274;
	if (videoListOffset >= 0) {
		videoListOffset = 0;
		$(".videoUp").hide();
	} else {
		$(".videoDown").show();
		$(".videoUp").show();	
	}
	$(".videoList").animate({top: videoListOffset+'px'},150);
}

function scrollVideoDown() {

	videoListOffset=videoListOffset-274;
	if (videoListOffset <= videoListLimit) {
		videoListOffset = videoListLimit;
		$(".videoDown").hide();
	} else {
		$(".videoDown").show();
			$(".videoUp").show();		
	}
	$(".videoList").animate({top: videoListOffset+'px'},150);
}

function initShowers() {
	$("#mainChanges, #newPlaces, #newItems, #newQuests, #newClasses, #otherAbilitys").hover(function() {
		if ($(this).find("a").html()) {
			$(this).addClass("colorBlue");
			$(this).removeClass("colorSnowBlue");
			var currentId = $(this).attr("id");
			$("."+currentId).show();
		}
	},function() {
		$(this).removeClass("colorBlue");
		$(this).addClass("colorSnowBlue");
		
		var currentId = $(this).attr("id");
		$("."+currentId).hide();
	})
}
function goToChanges() {
	window.location="changes.html";
}

function goToNewPlaces() {
	window.location="new_places.html";
}

function initLightBox() {
	$('.lightBoxed').lightBox();
}

function initSwitcher(){
	$(".subMenu .item").click(function() {
		$(".subMenu .item").removeClass("selected");
		$(this).addClass("selected");
		
		var contentItems = $(".contentItem");		
		$(contentItems).hide();
		var numSel = guideGetIndex($(".subMenu .item"), this);
		$(contentItems[numSel]).show();
		calcHeight();
	});
}

function guideGetIndex(arr, obj) {
  for(var i=0; i<arr.length; i++) {
    if (arr[i] == obj) return i;
  }
}

function calcHeight() {
	if (thisPage != pageMain) {
		var pos=$(".bottom_snow").position();
		var h=pos.top+160+647 ;
		$(".wrapper").css({'height':h+'px'});
	}
}



