// show flash video
$(document).ready(function() {
	$('#video-game a.play_video, #video-animation a.play_video, #video-animation span.ajax, #right-part a.animation').each(function () {
		$(this).click(function () {
			if (this.tagName.toLowerCase() == 'span') {
				pasteFlash($(this).parents('td').find('a:has(img)')[0], 720, 540);
			}
			else {
				pasteFlash(this, 6720, 540);
			}
			return false;
		});
	});

$(document).ready(function() {
	//settings
	var opacity = 1, toOpacity = 1, duration = 250;
	//set opacity ASAP and events
	$('.play_video').css('opacity',opacity).hover(function() {
			$(this).fadeTo(duration,toOpacity);
		}, function() {
			$(this).fadeTo(duration,opacity);
		}
	);
});

	$('#video-game a:has(img), #video-game span.ajax, a.game').each(function () {
		$(this).click(function () {
			if (this.tagName.toLowerCase() == 'span') {
				pasteFlash($(this).parents('td').find('a:has(img)')[0], 720, 540, $(this).attr('href'));
			}
			else {
				pasteFlash(this, 720, 540, $(this).attr('href'));
			}
			return false;
		});
	});

	$('#close-flash').click(function () {
		$('#shadow').click();
	});

	$('#shadow').click(function () {
		$('#shadow').fadeOut('normal');
		$('#flash-video-container').empty();
		$('#flash-video').hide();
		$('object, embed').css('visibility', 'visible');
	});

	function pasteFlash(a, width, height, href) {
		showShadow();
		$('#flash-video-container').html('<div></div>').find('div').flash('http://img.mail.ru/r/video2/uvpv3.swf?2', {width: '720', height: '540', paremeters: {movie: 'http://img.mail.ru/r/video2/uvpv3.swf?2', flashvars: 'movieSrc=' + href, allowFullScreen: 'true', devicefont: 'false', menu: 'false', allowScriptAccess: 'always' }});
		$('#flash-video').css('visibility', 'hidden').show().css({top: getYImage(height) + 'px', visibility: 'visible'});
	}

	function showShadow() {
		$('object, embed').css('visibility', 'hidden');
		$('#shadow').css('opacity', 0).height($('body').height()).show().animate({opacity:0.9}, 'normal');
	}

	function getYImage(height) {
		height = parseInt(height);
		var doc = document.documentElement, body = document.body;
		var scrollTop = (doc && doc.scrollTop || body && body.scrollTop || 0) - (doc.clientTop || 0);

		var ret = Math.floor(scrollTop + (windowHeight() - height) / 2);
		if (ret < 0)	ret = 0;

		var maxY = $(document.body).height() - height;
		if (ret > maxY) ret = maxY;

		return ret;
	}

	function windowHeight() {
		var height;
		if (window.innerHeight) {
			height = window.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) {
			height = document.documentElement.clientHeight;
		} else if (document.body) {
			height = document.body.clientHeight;
		}

		return height;
	}
});

// open video info
$(document).ready(function() {
	if ($('#video-game').length) {
		$('#video-animation, #video-game').mouseover(function () {
			$('#video-animation .hint, #video-game .hint').hide();
			$('.hint', $(this)).show();
		});

		$('#video-animation a, #video-game a, #video-animation .hint, #video-game .hint').click(function(e) {
			e.stopPropagation();
		});

		$(document).click(function() {
			$('#video-animation .hint, #video-game .hint').hide();
		});
	}
});
$(document).ready(function() {
	if ($('#video-game').length) {
		$('#video-animation, #video-game').mouseout(function () {
			$('#video-animation .hint, #video-game .hint').hide();
		} );

	}
});
$(document).ready(function() {
	if ($('#video-game').length) {
		$('#video-animation, #video-game').mousemove(function () {
			$('.hint', $(this)).show();
		} );

	}
});
// play mp3
$(document).ready(function() {
	$('#video-audio span.ajax').each(function() {
		$(this).click(function() {
			var hint = $('.hint', $(this).parent());

			$('.flash-container', hint.parent().parent()).html('<div></div>');

			$(this).parent().parent().find('.hint').not(hint).hide();
			hint.toggle();
			if ($('.info:visible', hint).length) {
			}
			else {
				var href = $('a', hint)[0].href;
				var bitsPath = href.split('/');
				var title = bitsPath[bitsPath.length - 1];
				$('.flash-container div', hint.parent()).flash("http://img.mail.ru/r/video2/player_v2.swf?2?autoplay=true&autoload=true&song_url=" + href +"&song_title=" + title, {width: 300, height: 15, paremeters: {bgcolor:'#000000'}});
			}

		});
	});
});



/*
	--------------------------------------------*/

$(document).ready(function() {
	switch(location.hash) 
	{
	    case '#h_gibberlings': 
	    $('#article div.h_gibberlings').slideToggle('slow'); 
	    break;
		
	    case '#h_orcs': 
	    $('#article div.h_orcs').slideToggle('slow'); 
	    break;

	    case '#h_kania': 
	    $('#article div.h_kania').slideToggle('slow'); 
	    break;
	
	    case '#h_mon': 
	    $('#article div.h_mon').slideToggle('slow'); 
	    break;


 	    case '#new_audio': 
	    $('#video-audio span.new_audio').each(function() {
			var hint = $('.hint', $(this).parent());
			$('.flash-container', hint.parent().parent()).html('<div></div>');
			$(this).parent().parent().find('.hint').not(hint).hide();
			hint.toggle();
			if ($('.info:visible', hint).length) {
			}
			else {
				var href = $('a', hint)[0].href;
				var bitsPath = href.split('/');
				var title = bitsPath[bitsPath.length - 1];
				$('.flash-container div', hint.parent()).flash("/media/swf/xspf_player_slim.swf?autoplay=true&autoload=true&song_url=" + href +"&song_title=" + title, {width: 300, height: 15, paremeters: {bgcolor:'#000000'}});
			}
	});
 
	    break;

	    case '#new_audio2': 
	    $('#video-audio span.new_audio2').each(function() {
			var hint = $('.hint', $(this).parent());
			$('.flash-container', hint.parent().parent()).html('<div></div>');
			$(this).parent().parent().find('.hint').not(hint).hide();
			hint.toggle();
			if ($('.info:visible', hint).length) {
			}
			else {
				var href = $('a', hint)[0].href;
				var bitsPath = href.split('/');
				var title = bitsPath[bitsPath.length - 1];
				$('.flash-container div', hint.parent()).flash("/media/swf/xspf_player_slim.swf?autoplay=true&autoload=true&song_url=" + href +"&song_title=" + title, {width: 300, height: 15, paremeters: {bgcolor:'#000000'}});
			}
	});
 
	    break;
	}
	 
	});
