﻿/// <reference path="../jquery-1.3.2-vsdoc.js" />


/**
*	Javascript Tools based on jquery
*/

$(document).ready(function() {


   // $("a.lightbox").lightBox();
    
	/* CALENDAR POPUP */
	
	$('.eventViewCalendar tbody td .event-link').each(function() {

		var link = $('.popup-link:first', $(this));
		var popup = $('.popup:first', $(this)).css('opacity', 0);

		link.mouseover(popupLinkMouseOver).mouseout(popupLinkMouseOut);
		popup.mouseover(popupLinkMouseOver).mouseout(popupLinkMouseOut);
	});
	function popupLinkMouseOver()
	{
		var parent = $(this).parent().get(0);
		var popup = $('.popup', parent);

		if (parent.hideDelayTimer)
			clearTimeout(parent.hideDelayTimer);

		// if its acutally animating than dont animate again
		if( $('.popup:animated', parent).size() )
			return false;
		
		// if its showen than dont show again
		if( $('.popup:visible', parent).size() )
			return false;
		
		$(popup).css({
			display: 'block',
			top: - (popup.height() + 20)
		}).animate({
			top: '-=10px',
			opacity: 1
		}, 200);
		
		return false;
	}
	function popupLinkMouseOut()
	{
		var parent = $(this).parent().get(0);;
		var popup = $('.popup', parent);

		if (parent.hideDelayTimer)
			clearTimeout(parent.hideDelayTimer);

		var actualIndex = $('.eventViewCalendar tbody td .event-link .popup').index(popup);

		// hide all other popups what
		// :animated - are not actualy animating (means they are hiding)
		$('.eventViewCalendar tbody td .event-link .popup:not(:eq(' + actualIndex + '))').css('opacity', 0);

		parent.hideDelayTimer = setTimeout(function () {
			popup.animate({
				top: '-=10px',
				opacity: 0
			}, 200, function () {
				popup.css('display', 'none');
			});
		}, 300);

		return false;
	}


	/* TWITTER - code moved to page because of different accounts */


	/* heroPlayerv23 PLAYER */
	
	if( $('#heroPlayerv23').size() )
	{
		$('#heroPlayerv23 li:not(.active)').css({
			display: 'block',
			opacity: 0
		});
/*
		var heroPlayerv23PlayerHeight = $('#heroPlayerv23 ul').height();
		$('#heroPlayerv23 ul li').each(function() {
			var h = $('.text', $(this)).height() + $('h2', $(this)).height() + 50;
			if( h > heroPlayerv23PlayerHeight)
				heroPlayerv23PlayerHeight = h;
		});
		$('#heroPlayerv23 ul').animate({ height: heroPlayerv23PlayerHeight });
		$('#heroPlayerv23 ul li').css('height', heroPlayerv23PlayerHeight);
*/
		var actualheroPlayerv23Page = 1;
		var autoplay = true;
		
		if($('#heroPlayerv23 li').size())
		{
			$('#heroPlayerv23 .nav').show();
			$('#heroPlayerv23 .nav div').text(actualheroPlayerv23Page + '/' + $('#heroPlayerv23 li').size() );

}
var actualHeroPage = 1;
var autoplay = true;

if ($('#heroPlayerv23 li').size() > 1) {
    $('#heroPlayerv23 #jsleft, #heroPlayerv23 #jsright').show();
}
		$('#heroPlayerv23 #jsleft').click(function() {
		    if ($('#heroPlayerv23 li:animated').size())
		        return false;
		    //if((actualHeroPage <= 1) || ($('#heroPlayerv23 li:animated').size()))
		    if (actualHeroPage <= 1) {
		        //return false;
		        actualHeroPage = $('#heroPlayerv23 li').size() + 1;
		    }
		    actualHeroPage--;
		    $('#heroPlayerv23 li').dequeue().stop();
		    $('#heroPlayerv23 li.active').animate({
		        opacity: 0
		    }, 500);
		    $('#heroPlayerv23 li').removeClass('active');
		    $('#heroPlayerv23 li:eq(' + (actualHeroPage - 1) + ')').addClass('active');
		    $('#heroPlayerv23 li.active').animate({
		        opacity: 1
		    }, 500);
		    return false;
		});
		$('#heroPlayerv23 #jsright').click(function() {
		    if ($('#heroPlayerv23 li:animated').size())
		        return false;
		    if (actualHeroPage >= $('#heroPlayerv23 li').size()) {
		        //return false;
		        actualHeroPage = 0;
		    }
		    actualHeroPage++;
		    $('#heroPlayerv23 li').dequeue().stop();
		    $('#heroPlayerv23 li.active').animate({
		        opacity: 0
		    }, 500);
		    $('#heroPlayerv23 li').removeClass('active');
		    $('#heroPlayerv23 li:eq(' + (actualHeroPage - 1) + ')').addClass('active');
		    $('#heroPlayerv23 li.active').animate({
		        opacity: 1
		    }, 500);
		    return false;
		});
		
		
		function heroPlayerv23PlayerAutoplay() {
			if(autoplay)
			{
				$('#heroPlayerv23 li').dequeue().stop();
				var old = actualheroPlayerv23Page;
				actualheroPlayerv23Page++;
				if(actualheroPlayerv23Page > $('#heroPlayerv23 li').size())
					actualheroPlayerv23Page = 1;
				$('#heroPlayerv23 li').removeClass('active');
				$('#heroPlayerv23 li:eq(' + (actualheroPlayerv23Page - 1) + ')').addClass('active');

				$('#heroPlayerv23 li:eq(' + (old - 1) + ')').animate({
					opacity: 0
				}, 400 );
				$('#heroPlayerv23 li.active').animate({
					opacity: 1
				}, 400 );

				$('#heroPlayerv23 .nav div').text(actualheroPlayerv23Page + '/' + $('#heroPlayerv23 li').size() );
			}
		}
		// timing, refresh in 5 seconds
		heroPlayerv23PLyaerTimeout = 2000;

		// if there is more than 1 iteim in heroPlayerv23 player than start it
		// start delay while all page is loaded + time for facebook component
		if($('#heroPlayerv23 li').size() > 1)
			setTimeout(function() {		
				document.heroPlayerv23PlayerTimer = setInterval(heroPlayerv23PlayerAutoplay, heroPlayerv23PLyaerTimeout);
			}, 2000);

		$('#heroPlayerv23').hover(function() {
			if(document.heroPlayerv23PlayerTimer)
			{
				clearInterval(document.heroPlayerv23PlayerTimer);
				document.heroPlayerv23PlayerTimer = null;
			}
			autoplay = false;
		}, function() {
			if($('#heroPlayerv23 li').size() > 1)
			{
				clearInterval(document.heroPlayerv23PlayerTimer);
				document.heroPlayerv23PlayerTimer = setInterval(heroPlayerv23PlayerAutoplay, heroPlayerv23PLyaerTimeout);
			}
			autoplay = true;
		});		
	}
	
/*
 *  check all input[type=text] elements,
 *  remember default value
 *  make onFocus, onBlur functions
 *  // make focus on first found input
 */
 
    $("input[type=text]").focus(function() {
        if( this.defVal == null ) {
            this.defVal = $(this).val();
        }
        if( this.value == this.defVal ) {
            this.value = "";
        }
    });
    $("input[type=text]").blur(function() {
        if( this.value == "" ) {
            this.value = this.defVal;
        }
    });
/*
    // select first input box
    if( $("input[type=text]")[0] ) {
        $("input[type=text]")[0].focus();
    }
*/
});


/* LASTFM PLAYER */
/* Still need to update the player with O2 Key */
function playStation() {
    playUrl("playlist/5443391/shuffle");
}
function playUrl(url) {
    window.open("http://www.last.fm/lastfminabox/popup?key=826c121615b9693e09a625470fed9162&station=" + url, 
                "lastFmInABoxPlayer", 
                "menubar=no,scrollbars=yes,width=750,height=600,toolbar=no");  
}
