$(function() {
    $('.slideshow').cycle({
	fx:			'fade',
	timeout:		6000,
	slideExpr:		'img',
	pager:			'#pager',
	pagerEvent:		'mouseover',
	pauseOnPagerHover:	true,
	before:			function() { $('#caption').text(this.alt); }
    });
	
	if ($().marquee) {
		$('marquee').marquee().mouseover(function () {
            $(this).trigger('stop');
        }).mouseout(function () {
            $(this).trigger('start');
        });
	}
    
    
	$('.channel-item').hover(
		function(e) {			
			var item = $(this);
			var top = 123;			
			var rel = item.attr('rel');// console.log(e);
			
			if ($.browser.msie) {
				top = 121;
			}
			
			_menu = item.find('.channel-menu');
			
			var width = _menu.outerWidth();
			
			//alert(width);
			
			if (rel == 1 || rel == 2) {
				_menu.css({top: top, left: 0});
			}
			if (rel == 5 || rel == 6) {
				_menu.css({top: top, right: 0, left: 'auto'});
			}
			if (rel == 3 || rel == 4) {
				_menu.css({top: top, left: '50%', marginLeft: '-'+(width/2)+'px'});
			}
			_menu.show(50);
		},function() {
			_menu.hide(50);
			$('.channel-item').removeClass('hover');
		}
	);	
    
	// Массив для хранения
	swaps = [];
	$("input[type=text]").each(function(i){
		swaps[i] = $(this).val();
		// Получение фокуса полем
		$(this).focus(function(){
			if ($(this).val() == swaps[i]) {
				$(this).val("");
			}
		// Потеря фокуса полем
		}).blur(function(){
			if ($.trim($(this).val()) == "") {
				$(this).val(swaps[i]);
			}
		});
	});

    $('a[href$=flv],a[href$=mp4],a[href$=mp3],a[href$=MP3], a[href*="youtube.com/watch"]').each(function() {

    	var self = $(this);
    	var src = '';
    	var title = self.text();
    	var href = '/'+self.attr('href');
    	var poster = $('img', self);

    	// Если видео с картинкой
    	if (poster.length > 0) {
    	    title = self.attr('title');
    	    src = poster.attr('src');
    	}

    	etitle = encodeURIComponent(title);

    	// Обернуть ссылку в DIV
    	self.wrap('<div class="player" />');

    	var template = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="640" height="480">'+
    			    '<param name="movie" value="images/player/player.swf" />'+
    			    '<param name="allowFullScreen" value="true" />'+
    			    '<param name="flashvars" value="controlbar=over&file='+href+'&image='+src+'&volume=30&title='+etitle+'" />'+
    			    '<!--[if !IE]>-->'+
    			    '<object type="application/x-shockwave-flash" data="images/player/player.swf" width="640" height="480" flashvars="controlbar=over&file='+href+'&image='+src+'&volume=30&title='+etitle+'" allowFullScreen="true">'+
    			    '<!--<![endif]-->'+
    			    '<p>Для просмотра ролика необходимо установить Flash-плеер</p>'+
    			    '<!--[if !IE]>-->'+
    			    '</object>'+
    			    '<!--<![endif]-->'+
    			'</object>';
    	self.before(template);

    	// Добавить подпись после ролика
    	self.after('<!--<p>'+title+'</p>-->');

    	// Удалить ссылку
    	//self.remove();
    	self.hide();
        });
    if (jQuery().prettyPhoto) {
        $("*[rel^='prettyPhoto']").prettyPhoto({
            //slideshow: 5000
            social_tools: ''
            ,counter_separator_label: '/'
            ,deeplinking: false
            ,opacity: 0.60
        });
    }

    realClock();

});

function realClock() {
    var time = new Date();

    var hour = time.getHours();
    if (hour < 10) hour = '0'+hour;

    var minute = time.getMinutes();
    if (minute < 10) minute = '0'+minute;

    var second = time.getSeconds();
    if (second < 10) second = '0'+second;

    $('#time').text(hour + ':' + minute + ':' + second);

    setTimeout("realClock()", 500);
}
