function wo(link,ww,hh,title) {
	w=window.open(link,'',(ww ? 'width='+ww+',' : '')+(hh ? 'height='+hh+',' : '')+'toolbar=0,location=0,menubar=0,scrollbars=0,resizable=0,status=0');
	w.focus();
}

var _isDisableAjax = function () {
	
	if ($.browser.version < 8 && $.browser.msie) {
		$('body').addClass('no_ajax');
		return true;

	}
	else {
		return false;
	}
	

}




$(function(){

	$('#radioFlash').click(function () {
		wo(_link_player, 335, 100);
	});
	
	
	$(window).resize(function () {
		
		
		var _width = $(this).width() > 1000 ? $(this).width() : 1000;
	
		$('#left_wrapper, #center_wrapper, #right_wrapper').css('width', _width);
		//$('#body').css('width', _width);
		
	});
	
	
	if (!_isDisableAjax()) {
		historyPage.Init();
	}
	
	
	{	// Радио флеш

		$('.radio').flash({
			swf: _root + 'public/flash/playeradio.swf',
			width: 216,
			height: 55,
			id: 'object_' + $('.radio').attr('id'),
			flashvars: {
				XMLRadioURL : _root + 'Playlist/playeradio.xml',
				soundURL : 'http://streaming.telecom.by:8001/novoeradio-128kb',
				uniq : 'object_' + $('.radio').attr('id'),
				state : 'stop',
				refreshTime : 10000
			}
		});
		
		
	}

	{	// крутим диджеев в шапке
		if ($('.dj_item').length > 1) {
			
			setInterval(function () {
				
				
				var _curIndex = $('.dj_item').index($('.dj_item:visible')),
					_nextIndex = $('.dj_item').length <= _curIndex + 1 ? 0 : _curIndex + 1;
				
				$($('.dj_item').get(_curIndex)).fadeOut();
				$($('.dj_item').get(_nextIndex)).fadeIn();
				
			}, 5000);
		}
		
	}

	_initOnLoad();


});


var _initOnLoad = function() {
	
	new Ya.share({ 
		'l10n'	: 'ru',
	    'element': 'ya_share', 
	    'elementStyle': { 
		    'type': 'button', 
		    'linkIcon': false, 
		    'border': false, 
		    'quickServices': ['vkontakte', 'facebook', 'twitter', 'lj'] 
	    }, 
	    'popupStyle': { 
	    	'copyPasteField': true ,
	    	'blocks' : {'Поделись с друзьями' : ['vkontakte', 'facebook', 'twitter', 'lj'] }
	    } 
	}); 
	
	$('.defvalue').defaultValue();
	
	{	// Время на флеше в новостях
		
		/*
		$('.scheduleBox .time').each(function () {

			$(this).flash({
				swf: _root + 'public/flash/time.swf',
				width: 82,
				height: 35,
				flashvars: {
					timeStamp: $(this).html()
				}
			});

		});
		*/
		
		
	}
	
	{	// плеер в контентной области
	
		$('.file_player').each(function () {
	
			var _id = Math.round(Math.random()* 1000);
			
			$(this).flash({
				swf: _root + 'public/flash/playercontent.swf',
				id: 'object_' + _id,
				width: 190,
				height: 48,
				wmode: 'transparent',
				flashvars: {
					soundURL: _root + 'download_files/' + $(this).html(),
					uniq: 'object_' + _id,
					state: 'stop'
				}
			});
			
			$(this).show();
					
		});
		
	}
	
	
	{	// Флеш банер на главной странице
		
		$('.banner_flash').flash({
			swf: _root + 'public/flash/banner.swf',
			width: 182,
			height: 274,
			flashvars: {
				XMLGalleryURL : _xml_banners,
				imagesURL : ''
			}
		});

		
	}
	
	
	{	// Флеш плеер в ТОП20
		
		$('.for_flash_player').click(function () {

			stopPlay();

			$(this).flash({
					swf: _root + 'public/flash/player_list.swf',
					id: 'object_' + $(this).attr('id'),
					width: 53,
					height: 52,
					wmode: 'transparent',
					flashvars: {
						soundURL: $(this).attr('file'),
						uniq: 'object_' + $(this).attr('id'),
						state: 'play'
					}
				});

			$(this).unbind('click');
			
		});
				
	}

	{	// Карусель на Новостях на титульной
		
		$('.newsBlock').bind('update', function () {
			
			if ($('.jcarousel-next', this).is('.jcarousel-next-disabled')) {
				$('.nextNews').addClass('disabled');
			}
			else {
				$('.nextNews').removeClass('disabled');
			}
			
			if ($('.jcarousel-prev', this).is('.jcarousel-prev-disabled')) {
				$('.prevNews').addClass('disabled');
			}
			else {
				$('.prevNews').removeClass('disabled');
			}
			
		});
		
		$('.newsBlock UL').jcarousel({
			scroll: 1,
			itemLoadCallback: function () {
				$('.newsBlock').trigger('update')
			},
			itemVisibleOutCallback: function () {
				$('.newsBlock').trigger('update');
			}
		});
		$('.nextNews').click(function () {
			$('.jcarousel-next', $('.newsBlock')).click();
			return false;
		})
		$('.prevNews').click(function () {
			$('.jcarousel-prev', $('.newsBlock')).click();
			return false;
		})
	}
	
	
	{	// Карусель в Акциях
		$('.otherLinks').bind('update', function () {

			if ($('.jcarousel-next', this).is('.jcarousel-next-disabled')) {
				$('.next').addClass('disabled');
			}
			else {
				$('.next').removeClass('disabled');
			}
			
			if ($('.jcarousel-prev', this).is('.jcarousel-prev-disabled')) {
				$('.prev').addClass('disabled');
			}
			else {
				$('.prev').removeClass('disabled');
			}
			
		});
		
		$('.otherLinks UL').jcarousel({
			scroll: 2,
			start: $($('.otherLinks LI')).index($('.otherLinks .current').parents('LI')),
			itemLoadCallback: function () {
				$('.otherLinks').trigger('update')
			},
			itemVisibleOutCallback: function () {
				$('.otherLinks').trigger('update')
			}
		});
		$('.next').click(function () {
			$('.jcarousel-next', $('.otherLinks')).click();
			return false;
		})
		$('.prev').click(function () {
			$('.jcarousel-prev', $('.otherLinks')).click();
			return false;
		})
	}
	
	
	
	
	
	
	
	$('.lastBlog span').click(function () {
		$(this).parents('.lastBlog').toggleClass('active');
		return false;
	})
	
	$('.contentSlider > span').click(function(){
		$(this).parents('.programDescription').toggleClass('active');
		return false;
	})
	
	
	$('.bestList li, .newList li').click(function(){
		if(!$(this).is('.active')){
		
			var _parent = $(this).parents('UL');	
		
			$('li.active .ratingControl', _parent).slideUp(200);
			$('li.active', _parent).removeClass('active');

			$('.ratingControl', this).slideDown(200);
			$(this).addClass('active');

		}
	})
	

	// $('.wrapper').addClass('fixedheight');
	// $('.scrollpane').jScrollPane({scrollbarWidth:27});
	
/*

	$('.scrollpane, .leftColumn .textBlock').jScrollPane({scrollbarWidth:27});
	$('.bestListOuter').jScrollPane({scrollbarWidth:27});
	$('.blog').jScrollPane({scrollbarWidth:27});
	
*/

	if ($('#dateSelect').length && _date_min && _date_max) {

		$('#dateSelect').show();
	
		$('#dateSelect').jdPicker({
			date_format:"dd MM YYYY",
			short_month_names: ["января", "февраля", "марта", "апреля", "мая", "июня", "июля", "августа", "сентября", "октября", "ноября", "декабря"],
			short_day_names : ["Вс", "Пн", "Вт", "Ср", "Чт", "Пт", "Сб"],
			month_names: ["Янв", "Фев", "Мар", "Апр", "Май", "Июнь", "Июль", "Август", "Сентябрь", "Октябрь", "Ноябрь", "Декабрь"],
			date_min: _date_min,
			date_max: _date_max,
			error_out_of_range: 'Дата выходит за рамки'
		});
	
		$('#dateSelect').change(function () {
			
			var month_names = ["января", "февраля", "марта", "апреля", "мая", "июня", "июля", "августа", "сентября", "октября", "ноября", "декабря"];
			var reg = /(\d{2}) (.*) (\d{4})/;
			var date = $(this).val().match(reg);
			
			for(var i in month_names) {
				if (month_names[i] == date[2]) {
					
					var _currMonthIndex = parseInt(i) + 1;
					var _date = date[3] + '-' + _currMonthIndex + '-' + date[1];
					break;
				}
			}
			
			document.location = _link_news + '?date=' + _date;
			
		})
		
	}

	
	// кликаем на первые пункты ТОПА
	$('UL.top LI:first, UL.pretendents LI:first').click();
	$('.defaultValue').defaultValue();
	

	if ($.browser.msie && $.browser.version == 6) {
		DD_belatedPNG.fix('.dj img');
	}
	
}


function deleteComment( idComment, target ) {
	
	$.post(_link_blogs, {'delete' : '1', 'idComment' : idComment}, function (data) {
		$(target).parents('.comment').remove();
	});

}

function editComment( idComment ) {
	var pattern=/record=\d*/gi;
	var temp = document.location.toString().match(pattern);
	var link = 'blogs/?edit=1&idComment=' + idComment + '&' + temp;
	//alert(_options.historyPageKey);
	historyPage.GoTo(link);//, _options.historyPageKey);
}


/* Голосование за композицию в TOP 20 */
function vote(link, _element) {

	if (!$(_element).is('disable')) {
		$(_element).addClass('disable');
		$.get(link);
	}

}

/* Получаем ссылку на флеш */
function getMovie(id) {
    return ($.browser.msie ? window : document)[id];
}


/* Callback для флеша, для остановки всех плееров */
function sendState(id) {

	$('object').each(function () {
		var _id = $(this).attr('id');
		if (_id && id != _id && typeof(getMovie(_id).getState) == 'function') {
			getMovie(_id).getState('stop');
		}
		//getMovie(_id).sendState('stop');
	})
	
}

var stopPlay = sendState;



function check_poll(_this) {

	if($(_this).serializeArray().length == 1) {
		alert('Необходимо выбрать хотя бы один ответ');
		return false;
	} 
	
	postForm(_this);
	return false;

}


