/***************************
**** CREATE: 19.05.2011 ****
****** VERSION: 1.0.0 ******
****** www.media5.com ******
***************************/

Cufon.replace(":header:not(.standartFont, .td_default_left :header)", { fontFamily: 'AvantGardeCTT' });
var shape_image, news_block, news_slide, menu_block, content, content_height;


$.fn.placeholder = function(){
	this.each(function(){
		$(this).attr('defaultvalue',$(this).val()).focus(function(){
			if($(this).val() == $(this).attr('defaultvalue'))
				$(this).val('');
		}).blur(function(){
			if($(this).val() == '')
				$(this).val($(this).attr('defaultvalue'));
		});
	});
}




$(function(){

	content = $('#content');
	content_height = content.outerHeight();
	$('.important').click(function(){
		var a = $('.important').find('a');
		popupSlider('show',a.attr('rel')+'?ajax=1');
		return false;
	});
	
	$('.linkpopup, #link_feedback, #depositcalc_link').click(function(){
		popupSlider('show',$(this).attr('rel')+'?ajax=1');
		$(window).scrollTop()=0;
		return false;
	});
	
	
	$('#popupBox_close').live('click',function(){
		popupSlider('hide','');
	});
});

function toggleList(){
	$('.news_list li h4.standartFont a').click(function(){
		
		if($(this).parents('.noToggleList').length) return false;
		
		var parent = $(this).parent().parent();
		var full_text = parent.children('.full_text');
		var short_text = parent.children('.short_text');
		
		if(full_text.length)
		{
			if(parent.is('.open_li'))
			{
				parent.removeClass('open_li');
				full_text.hide();
				short_text.show();
			} else {
				$('.news_list li.open_li h4.standartFont a').trigger('click');
				parent.addClass('open_li');
				full_text.show();
				short_text.hide();
			}
			return false;
		}
	});
}

function popupSlider(act,href){
	if(act == 'hide') 
	{
		$('#popupSlider, #exOverlay').hide();
		if($.browser.msie && $.browser.version == '6.0')
			$('#zindexie6').css('z-index','2000');
		return false;
	}
	
	$('#popupSlider').load(href);
	
	
	
	$('#popupSlider').show();
	$.ex['overlay']({background:"url('../images/popup_overlay_bg.png') repeat-x bottom left #71422b"});
	$('#sliderPopup').sliderCenter();
	
	if($.browser.msie && $.browser.version == '6.0')
		$('#zindexie6').css('z-index','1');
}

function correctContentHeight(height){
	if(height === 'close')
	{
		content.height('auto');
		return false;
	}
	height = (height || menu_block.height()+15);
	content.height(height < content_height ? content_height : height);
}

function slideImages(index, direction){
	var speed = 500;
	switch(direction){
		case 'next' :
			shape_image
				.filter(':visible')
				.animate({left:-640},speed,function(){
					$(this).hide();
				})
				.end()
				.eq(index)
				.css({left:640})
				.show()
				.animate({left:0},speed);
		break;
		case 'prev' :
			shape_image
				.filter(':visible')
				.animate({left:640},speed,function(){
					$(this).hide();
				})
				.end()
				.eq(index)
				.css({left:-640})
				.show()
				.animate({left:0},speed);
		break;
	}
}

function slideNews(index, direction){
	var speed = 500;
	var height = news_block.eq(index).height();
			var limit = 166;
			if($.browser.safari || $.browser.chrome || $.browser.opera) limit = 190;
			height = height < limit ? height : limit;
	switch(direction){
		case 'next' :
		
			news_block
				.filter(':visible')
				.animate({left:-320},speed,function(){
					$(this).hide();
				})
				.end()
				.eq(index)
				.css({left:320})
				.show()
				.animate({left:0},speed);
			news_slide.animate({height:height},speed);
		break;
		case 'prev' :
			news_block
				.filter(':visible')
				.animate({left:320},speed,function(){
					$(this).hide();
				})
				.end()
				.eq(index)
				.css({left:-320})
				.show()
				.animate({left:0},speed);
			news_slide.animate({height:height},speed);
		break;
	}
}

$(function() {
	if ($('.medals').length) {
		var medal_images = $('.medals tr img');
		var medal_values = $('.medals tr .value');
		var medal_values_arr = [];
		var max_medal_value = 0;
		var text,digit;

		medal_values.each(function() {
			text = $(this).text().replace(/ /g,"");
			digit = parseInt(text);
			medal_values_arr.push(digit);
			if (digit > max_medal_value)
			{
				max_medal_value = digit
			}
		});
		medal_images.each(function(index) {
			current_medal_size = medal_values_arr[index] * 100 / max_medal_value;
			$(this).css('width',(current_medal_size) + '%');
		});

	}
});

function addFileInfo(){
	var href = $(this).attr('href').split('.');	
	if($(this).parent().is('.list_files')) 
		$(this).after('<span class="file_info">Формат: '+href[href.length-1]+' (размер 1,82 мб)</span>');
}


