$(document).ready(function()
{
	swfobject.embedSWF("/swf/sun.swf", "sun", "190", "190", "9.0.0", "", {}, {wmode:'transparent'});
	swfobject.embedSWF("/swf/moon.swf", "moon", "220", "220", "9.0.0", "", {}, {wmode:'transparent'});
	swfobject.embedSWF("/swf/shnur.swf", "shnur", "220", "220", "9.0.0", "", false, {wmode:'transparent'});
	if ($('#hare-contact').size())
	{
		swfobject.embedSWF("/swf/hare_stand3.swf", "hare-contact", "300", "300", "9.0.0", "", {}, {wmode:'transparent'});
		swfobject.embedSWF("/swf/hipo.swf", "hipo-contact", "270", "270", "9.0.0", "", {}, {wmode:'transparent'});
	}
	if ($('#hare-product').size())
	{
		swfobject.embedSWF("/swf/hare_sit.swf", "hare-product", "300", "300", "9.0.0", "", {}, {wmode:'transparent'});
		swfobject.embedSWF("/swf/giraffe.swf", "giraff-product", "270", "270", "9.0.0", "", {}, {wmode:'transparent'});
		swfobject.embedSWF("/swf/frog.swf", "frog-product", "170", "170", "9.0.0", "", {}, {wmode:'transparent'});
	}
	if ($('#hare-index').size())
	{
		swfobject.embedSWF("/swf/hare_hand.swf", "hare-index", "190", "190", "9.0.0", "", {}, {wmode:'transparent'});
		swfobject.embedSWF("/swf/bee.swf", "bee-index", "220", "220", "9.0.0", "", {}, {wmode:'transparent'});
		swfobject.embedSWF("/swf/slon.swf", "slon-index", "150", "140", "9.0.0", "", {}, {wmode:'transparent'});
	}
	if ($('#hare-wall').size())
	{
		swfobject.embedSWF("/swf/hare_fly.swf", "hare-wall", "450", "450", "9.0.0", "", {}, {wmode:'transparent'});
	}
	latex();
	xhover();

});
$(window).load(function(){
	if ($('#hare-index').size())
	{
		indexMusic();
	}
});

function indexMusic ()
{
	type='day';
	if ($('body.night').size())
	{
		type='night';
	}
	
	musicPlay('/sound/'+type+'.mp3', 999);
}

function xhover ()
{
	$('.xhover').mouseover(function(){
		if ($(this).hasClass('z1') || $(this).hasClass('z2') || $(this).hasClass('z3'))
		{
			if ($(this).hasClass('z1'))
			{
				$(this).addClass('z1_hover');
				$(this).mouseout(function(){
					$(this).removeClass('z1_hover');
				});
			}
			if ($(this).hasClass('z2'))
			{
				$(this).addClass('z2_hover');
				$(this).mouseout(function(){
					$(this).removeClass('z2_hover');
				});
			}
			if ($(this).hasClass('z3'))
			{
				$(this).addClass('z3_hover');
				$(this).mouseout(function(){
					$(this).removeClass('z3_hover');
				});
			}
		}
		else
		{
			$(this).addClass('hover');
			$(this).mouseout(function(){
				$(this).removeClass('hover');
			});
		}
	});	
}

function contactForm ()
{
	error=0;
	$('div.form').removeClass('error');
	if (!$('input[name=name]').val() || $('input[name=name]').val()=='Ваше имя')
	{
		$('input[name=name]').parents('div.form.input').addClass('error');
		error=1;
	}
	if (!$('input[name=surname]').val() || $('input[name=surname]').val()=='Ваша фамилия')
	{
		$('input[name=surname]').parents('div.form.input').addClass('error');
		error=1;
	}
	if (!$('input[name=email]').val() || $('input[name=email]').val()=='Ваш Email')
	{
		$('input[name=email]').parents('div.form.input').addClass('error');
		error=1;
	}
	if (!$('textarea[name=text]').val() || $('textarea[name=text]').val()=='Ваше сообщение')
	{
		$('textarea[name=text]').parents('div.form.textarea').addClass('error');
		error=1;
	}
	if (!error)
	{
		return true;
	}
	return false;
}
function latex ()
{
	if ($('body.latex').size())
	{
		if ($.browser.msie && parseInt($.browser.version.substring(0,1))<7)
		{
			height=(Math.ceil($('#content').height()/122)*122)-$('#content').height()+34;
			$('#content').css('padding-bottom', height+'px');
		}
		else
		{
			var minus=0;
			if ($.browser.msie && parseInt($.browser.version.substring(0,1))==7)
			{
				minus=2;
			}
			
			height=Math.floor($('#content').height()/122-minus)*122-4;
			if (height<240)
			{
				height=240;
			}
			$('#content').height(height);
		}
	}
}
function slideMenu (i)
{
	$('a.menu').removeClass('active');
	$('ul.menu').slideUp();
	$('#info-menu-'+i).addClass('active');
	$('#info-ul-'+i).slideDown();
	$('#info-menu-'+i)[0].blur();
}
function changeTime ()
{
	if ($('body').hasClass('day'))
	{
		$('body').removeClass('day').addClass('night');
		$.cookie('daytype', 'night');
	}
	else
	{
		$('body').removeClass('night').addClass('day');
		$.cookie('daytype', 'day');
	}
	musicStop();
	indexMusic();
}

function getShop(id)
{
	$.post('/product/city', {'id':id}, function (data)
	{
		if (data.length)
		{
			html = '<ul>';
	
			for (x in data)
			{
				html = html + '<li>'+data[x]['name']+' - '+data[x]['adres']+'</li>';
			}
	
			html = html + '</ul>';
		}else{
			html = '';
		}
		
		$('#result_shop').html(html);
			
		
	}, 'json');
}
function confirmEmail(element){
	element.html('обработка…');
	element.load("/profile/confirm_send");
}
function showN (id)
{
	$('#' + id).css('display', '');
	musicPlay('/sound/hint.mp3', 1);
}
function hideN (id)
{
	$('#' + id).css('display', 'none');
}
function profileDelAvatar ()
{
	$('#profile-edit .avatar li a').parent().remove();
	$.post('/profile/delavatar', function(){
		$('#profile-edit .avatar img').attr('src', $('#profile-edit .avatar img').attr('src')+'&'+Math.random());
	});
}
function popup(url, width, height, param)
{
	
	if(!width){width=750;}
	if(!height){height=468;}

	var top=Math.ceil($(window).height()/2-Math.ceil(height/2));
	var left=Math.ceil($(window).width()/2-Math.ceil(width/2));
	
	
	if (url.indexOf('?')!=-1)
	{
		param='&'+param+'&_small';
	}
	else
	{
		param='?_small';
	}

	window.open(url+param, 'popup', 'top='+top+', left='+left+', width='+width+', height='+height);
}
function openFindMenu ()
{
	if ($('#find_div').css('display') == 'none')
	{
		$('#find_div').slideDown('slow');
	}
	else
	{
		$('#find_div').slideUp('slow');
	}
	
}

function findEvent (ev)
{
	if (ev.keyCode == 13)
	{
		findGo();
	}
}


function findGo ()
{
	id = $('#find_id').val();
	var link = '/contest/' + id + '/';
	window.location = link;
}