$(document).ready(function()
{
	$("a[rel='lightbox']").colorbox();
    
    $("a[rel='lightboxLogin']").colorbox(
    {
        iframe: true,
        width: 1000,
        height: 600,
        scrolling: false
    });
    
    $('.innerfade').innerfade({
		speed: 750,
		timeout: 5000,
		type: 'random'
	});
    
    setTimeout(function()
    {
        $('#menu').lavaLamp(
        {
            speed: 400
        });
        $('#submenu').lavaLamp(
        {
            speed: 400
        });
    }, 500);
    
    
    
    $(".validateForm").validate({
        errorPlacement: function(error, element) {
			error.prependTo( element.parent().next() );
		},
		// set this class to error-labels to indicate valid fields
		success: function(label) {
			// set &nbsp; as text for IE
			label.html("&nbsp;").addClass("checked");
		}
    });     
    
    $('#blocks > li').mouseover(function()
    {
        $(this).children('.blocksText').children('a').addClass('active');
        $(this).children('.readMore').children('a').addClass('active');
    });
    
    $('#blocks li').mouseout(function()
    {
        $(this).children('.blocksText').children('a').removeClass('active');
        $(this).children('.readMore').children('a').removeClass('active');
    });
    
    $('#blocks > li').click(function()
    {
        location.href = $(this).children('.readMore').children('a').attr('href');
        return false;
    });
    
    $('#latestNews > li').mouseover(function()
    {
        $(this).children('.latestNewsText').children('a').addClass('active');
        $(this).children('.latestNewsLink').children('a').addClass('active');
    });
    
    $('#latestNews li').mouseout(function()
    {
        $(this).children('.latestNewsText').children('a').removeClass('active');
        $(this).children('.latestNewsLink').children('a').removeClass('active');
    });
    
    $('#latestNews > li').click(function()
    {
        location.href = $(this).children('.latestNewsLink').children('a').attr('href');
        return false;
    });
    
    activeBlock = 'a1';
    maxWidth = 860;
    minWidth = 50;
        
    $(".hrzAccordion li").hover(function()
    {
        $('.arrow').children('img').attr('src', 'images/crossOrange.png');
        $(this).children('div.arrow').children('img').attr('src', 'images/crossBlue.png');
        switch (this.id)
        {
            case 'a1':
                if (activeBlock == 'a2')
                {
                    $(this).animate({width: "860px"}, 400);
                }
                else if (activeBlock == 'a3')
                {
                    $(this).animate({width: "860px"}, 400);    
                    $('#a2').animate({width: "910px"}, 400);
                }
                activeBlock = this.id;
            break;
            case 'a2':
                if (activeBlock == 'a1')
                {
                    $('#a1').animate({width: minWidth+"px"}, 400); 
                }
                else if(activeBlock == 'a3')
                {
                    $(this).animate({width: "910px"}, 400);
                }
                activeBlock = this.id;
            break;
            case 'a3':
                if (activeBlock == 'a2')
                {
                    $('#a2').animate({width: "100px"}, 400);
                }
                else if(activeBlock == 'a1')
                {
                    $('#a1').animate({width: minWidth+"px"}, 400); 
                    $('#a2').animate({width: "100px"}, 400); 
                }
                activeBlock = this.id;
            break;
        }
    });
    
    $('#languages').mouseover(function()
    {
        $(this).css('height', '75px');
    });
    
    $('#languages').mouseout(function()
    {
        $(this).css('height', '24px');
    });
    
    var input = document.getElementsByTagName('input');
    for (var a=input.length-1; a >= 0; a--) 
    {
        if (input[a].type != 'text' || input[a].className != 'search') { continue; } // skips non-text inputs
        input[a].mask = input[a].value;
        input[a].onfocus = function() {
            if (this.value == this.mask) { this.value = ''; }
            $(this).css('color', '#737373');
        };
        input[a].onblur = function() {
            if (this.value == '') { $(this).css('color', '#cbcbcb'); this.value = this.mask;  }
        };
    }
    
});
