$(function()
{
	$('.login-bar-button').click(function(){
		var bar     = $('.'+$(this).attr('target'));
		var visible = $('.login-bar:visible');
		
		if (visible.length)
		{
			visible.slideUp(function(){
				if (visible.get(0) !== bar.get(0)){
					bar.slideDown();
				}
			});
		}
		else
		{
			bar.slideDown();
		}

		return false;
	});

	$('.login-bar .close').click(function(){
		$('.fixed-height-container').css('height', 'auto');
		$('.login-bar:visible').slideUp();
	});
    
    $('.programme .more').click(function()
    {
        $(this).parent().find('.temp').slideToggle();
        return false;
    });


	// Make divs clickable
    $('.clickable:has(a[href])').click(function()
    {
        var location = $('a[href]', this).eq(0).attr('href');
        
        if (location !== undefined)
        {
        	window.location = location;
                window.status = location;
        }
        
    }).bind('mouseenter mouseleave', function()
    {            
        $(this).toggleClass('rollover');
    });

    
    $('.a-feature').mouseenter(function()
    {
        $('img', this).stop().animate({top:-(60)},120, 'easeOutQuart');
    }).mouseleave(function()
    {
        $('img', this).stop().animate({top:-(50)},120, 'easeInQuart');
    });

	$('.gallery_unstyled').addClass('gallery'); // adds new class name to maintain degradability
	
	
		
    jQuery('#newsticker').newsticker();

    // quickfix
    $('#newsticker a[href=#]').click(function(){ return false; }).css({ cursor: 'default' });

    
    // Toggle the paused class
    $('.quoteticker').bind('mouseenter mouseleave', function(){
        $(this).toggleClass('paused');
    });
  
    // Loop continously
    setInterval(function(){
        $('.quoteticker').each(function(){
            var current = $('div.speech-bubble-container:visible', this);

            if (current.parent().parent().hasClass('paused')){ 
                return;
            }

            current.fadeOut(function(){
                (current.next().length > 0 ? current.next() : current.siblings(':eq(0)')).fadeIn();
            });
        });
    }, 5000);

    $('.jobticker').bind('mouseenter mouseleave', function(){
        $(this).toggleClass('paused');
    });

    $('.jobticker .content .speech-bubble-list blockquote ul li').css("display","none");
    $(".jobticker .content .speech-bubble-list blockquote ul li").eq(0).fadeIn(1000);

    // Loop continously
    setInterval(function(){
	$('.jobticker .content .speech-bubble-list blockquote ul li').each(function(){
	  
          var current = $('.jobticker .content .speech-bubble-list blockquote ul li:visible');

	  if (current.parent().parent().hasClass('paused')){
                return;
          }

          current.fadeOut(function(){
		(current.next().length > 0 ? current.next() : current.siblings(':eq(0)')).fadeIn();
          });
	  
	});

    }, 3000);

    $('.jobticker .content .speech-bubble-list .quote-author ul li').css("display","none");
    $(".jobticker .content .speech-bubble-list .quote-author ul li").eq(0).fadeIn(1000);

    // Loop continously
    setInterval(function(){
	$('.jobticker .content .speech-bubble-list .quote-author ul li').each(function(){

          var current = $('.jobticker .content .speech-bubble-list .quote-author ul li:visible');

          current.fadeOut(function(){
		(current.next().length > 0 ? current.next() : current.siblings(':eq(0)')).fadeIn();
          });

	});

    }, 3000);

    /** charts opener */
    $('div.visitor-profile-chart .toggler').live('click', function(){
        var to_height = $('img', $(this).prev()).height();
        $(this).prev().height() === 335 ? $(this).prev().animate({height: to_height}) : $(this).prev().animate({height:335});
        $(this).toggleClass('opened');
        return false;
    });
    
    $('#copenhagen-wall a.watch, #copenhagen-wall div.cop-video-link a')
        .fancybox({
            frameWidth: 853,
            frameHeight: 508,
            hideOnContentClick:false,
            padding: 4
        });
    
    $('#voxpops-wall a.watch')
	.fancybox({
		frameWidth:560,
		frameHeight:350,
		hideOnContentClick:false
	});

	var searchBoxDefaultText = 'search';

	$('.search-input .search-field').focus(function(){
		if ($(this).val() === searchBoxDefaultText) {
			$(this).val('');
		}

		$(this).addClass('search-field-focused');
	}).blur(function(){
		if ( ! $(this).val().length) {
			$(this).val('search');
		}

		$(this).removeClass('search-field-focused');
	});

	$('.search-input input[type=submit]').click(function(){
		var input = $('.search-field');
		if (input.val() === searchBoxDefaultText) {
			input.val('').focus();
			return false;
		}		
	});	
});
