$(function() {
	
	$('.productionlist li').hover(
		function() {
			var img=$('img',this);
			var src=img.attr('src');
			img.attr('srcorg',src);
			
			var srchover=src.substr(0,src.lastIndexOf('.'))+'hover.png';
			img.attr('src',srchover);
			
			$(this).addClass('active');
		},
		function() {
			$(this).removeClass('active');
			var img=$('img',this);
			var srcorg=img.attr('srcorg');
			img.attr('src',srcorg);
		}
	);	
/*
	$('div.navigation select:not(.select)').hide();
	$('div.navigation select:not(.select) option:first-child').attr('selected','selected');
	$('div.navigation input.submit').hide();

	$('div.navigation select#helper-tv').change(function() {
		switch ($(this).val()) {
			case 'helperBBK':
				$('div.navigation select:not(.select)').hide();
				$('div.navigation select#helperBBK').show();
				break;
			case 'helperDAEWOO':
				$('div.navigation select:not(.select)').hide();
				$('div.navigation select#helperDAEWOO').show();
				break;
			case 'helperELENBERG':
				$('div.navigation select:not(.select)').hide();
				$('div.navigation select#helperELENBERG').show();
				break;
			case 'helperJVC':
				$('div.navigation select:not(.select)').hide();
				$('div.navigation select#helperJVC').show();
				break;
			case 'helperLG':
				$('div.navigation select:not(.select)').hide();
				$('div.navigation select#helperLG').show();
				break;
			case 'helperPANASONIC':
				$('div.navigation select:not(.select)').hide();
				$('div.navigation select#helperPANASONIC').show();
				break;
			case 'helperPHILIPS':
				$('div.navigation select:not(.select)').hide();
				$('div.navigation select#helperPHILIPS').show();
				break;
			case 'helperPIONEER':
				$('div.navigation select:not(.select)').hide();
				$('div.navigation select#helperPIONEER').show();
				break;
			case 'helperROLSEN':
				$('div.navigation select:not(.select)').hide();
				$('div.navigation select#helperROLSEN').show();
				break;
			case 'helperSAMSUNG':
				$('div.navigation select:not(.select)').hide();
				$('div.navigation select#helperSAMSUNG').show();
				break;
			case 'helperSHARP':
				$('div.navigation select:not(.select)').hide();
				$('div.navigation select#helperSHARP').show();
				break;
			case 'helperSHIVAKI':
				$('div.navigation select:not(.select)').hide();
				$('div.navigation select#helperSHIVAKI').show();
				break;
			case 'helperSONY':
				$('div.navigation select:not(.select)').hide();
				$('div.navigation select#helperSONY').show();
				break;
			case 'helperTHOMSON':
				$('div.navigation select:not(.select)').hide();
				$('div.navigation select#helperTHOMSON').show();
				break;
			case 'helperTOSHIBA':
				$('div.navigation select:not(.select)').hide();
				$('div.navigation select#helperTOSHIBA').show();
				break;
			default:
				$('div.navigation select:not(.select)').hide();
				$('div.navigation input.submit').hide();
		}
	});

	$('div.navigation select:not(.select)').change(function() {
		$('div.navigation input.submit').show();
	});
*/
	$('div.navigation div.help dl dd p a').click(function() {
		$('div.manual').toggle(200);
		return false;
	});

	$('div.manual img.close').click(function() {
		$('div.manual').hide(200);
	});

	function answer () {
		var li = $(this);
		if (!$('#testing-load').length) {
			li.children('label').after('<img src="/i/loader.gif" width="16" height="16" alt="Загрузка" id="testing-load" style="margin: 0 0 0 10px;" />');
		};
		$.post(li.parent('ul').parent('form').attr('action'),{ answer: li.children('input').attr('value'), submit: "submit" }, function(data) {
			$('.testing').html($(data).find('.testing').html());
			$('#testing-load').remove();
		});
	};

	$('div.testing p.testing-btn A').live('click', function() {
		if ($(this).attr('href') != 'http://holder.su/partners/education.html') {
			if (!$('#testing-load').length) {
				$(this).after('<img src="/i/loader.gif" width="16" height="16" alt="Загрузка" id="testing-load" style="margin:5px auto 0;display:block;" />');
			};
			$.get($(this).attr('href'), function(data) {
				$('div.testing').html($(data).find('.testing').html());
				$('div.testing ul.testing-answers li:not(.disabled)').one('click',answer);
				$('#testing-load').remove();
			});
			return false;
		};
	});

	$('div.testing p.lesson-btn A').live('click', function() {
		if ($(this).attr('href') != 'http://holder.su/partners/education.html') {
			if (!$('#testing-load').length) {
				$(this).after('<img src="/i/loader.gif" width="16" height="16" alt="Загрузка" id="testing-load" style="margin:5px auto 0;display:block;" />');
			};
			var link = $(this).hasClass('testing-btn-go') ? 'http://holder.su/' + $(this).attr('href') : $(this).attr('href');
			$.get(link, function(data) {
				$('div.testing').html($(data).find('.testing').html()).removeClass('testing-lesson');
				$('div.testing ul.testing-answers li:not(.disabled)').one('click',answer);
				$('#testing-load').remove();
			});
			return false;
		};
	});

	$('.lessons-links li a').click(function(){
		var link = 'http://holder.su/' + $(this).attr('href');
		if(!$('div.lesson-frame').length) {
			popup = $('<div class="lesson-frame"><i class="lesson-shadow"></i><div class="lesson-canvas"></div></div>').appendTo('body');
		}
		$('div.lesson-frame').height($('#page').height());
		$('div.lesson-canvas').html('<p style="padding:10px;text-align:center;"><img src="/i/lightbox-loader.gif" width="32" height="32" alt="Загрузка" id="lesson-load" /></p>');
		$.get(link, function(data) {
			$('div.lesson-canvas').html($(data).find('.testing')).append('<i class="lesson-close"></i>');
			$('div.testing ul.testing-answers li:not(.disabled)').one('click',answer);
			if ($('#player').length > 0) {
				var swf = $('#player').attr('href');
				if (swf.substr(swf.length -3,3) == 'swf') {
					$('#player').flash({swf:swf,height:600,width:860,wmode:'transparent'});
				} else {
					flowplayer('player', '/f/flowplayer-3.2.2.swf', {clip: {autoPlay: false, autoBuffering: true, scaling: 'fit'}});
				};
			};
		});
		var closer = function() {
			$('div.lesson-canvas').remove();
			$('i.lesson-shadow').animate({opacity:0},300,function() {
				$('div.lesson-frame').remove();
			});
		};
		$(document).keydown(function(e) {
			if(e.which==27) {closer();}
		});
		return false;
	});

	$('i.lesson-shadow, i.lesson-close').live('click', function() {
		$('div.lesson-canvas').remove();
		$('i.lesson-shadow').animate({opacity:0},300,function() {
			$('div.lesson-frame').remove();
		});
		return false;
	});

	$('form[action="http://holder.su/partners/education/convert.html"]').submit(function(){
		var form = $(this);
		$('div.wlpeMessage').remove();
		$('ul.prizes').before('<div style="margin:10px 0;" class="wlpeMessage"><img src="/i/loader.gif" width="16" height="16" alt="Загрузка" /></div>');
		$.post(form.attr('action'), form.serialize() + '&submit=submit', function(data) {
			$('div.wlpeMessage').remove();
			$('ul.prizes').before($(data).find('div.wlpeMessage'));
			$('div.user-panel p.user-count strong').html($(data).find('div.user-panel p.user-count strong').html());
		});
		return false;
	});

	if ($('input[name="dob"]').length > 0) {
		$('input[name="dob"]').datepicker({dateFormat:'dd-mm-yy',altFormat: 'mm-dd-yy',changeMonth:true,changeYear:true,minDate: '-90Y', maxDate: '-1D',defaultDate: '-30y',yearRange: '1900:2010'});
	};
});
