var Spotlight={

    interval: 3000,
    fadeSpeed: 1000,

    init: function(){

        $('#spotlight li')
        .mouseenter(function(){
            window.clearInterval(Spotlight.timer);
        })
        .mouseleave(function(){
            window.clearInterval(Spotlight.timer);
            Spotlight.timer = window.setInterval('Spotlight.change("next")', Spotlight.interval);
        });
        
        Spotlight.timer = window.setInterval('Spotlight.change("next")', Spotlight.interval);

    },
    change: function(direction){

        var currentSpotlight = $('#spotlight li.active');

        if(direction == 'next'){
            if(currentSpotlight.next().length){
                nextSpotlight = currentSpotlight.next();
            }else{
                nextSpotlight = $('#spotlight li').first();
            }
        }else{
            if(currentSpotlight.prev().length){
                nextSpotlight = currentSpotlight.prev();
            }else{
                nextSpotlight = $('#spotlight li').last();
            }
        }


        $(currentSpotlight).fadeOut(Spotlight.fadeTime);

        nextSpotlight.fadeIn(Spotlight.fadeTime, function(){
            currentSpotlight.removeClass('active');
            nextSpotlight.addClass('active');
        });

    }

};

$(document).ready(function() {

    // INIT THE SPOTLIGHT
    Spotlight.init();
    $('#spotlight .next').click(function(){
        Spotlight.change('next');
        return false;
    });
    $('#spotlight .prev').click(function(){
        Spotlight.change('prev');
        return false;
    });

    // OPEN LINK IN NEW WINDOW
	$('a.new-window').click(function(){
		window.open(this.href);
		return false;
	});

    // LIGHTBOX
	$('a.lightbox').each(function(){
		$(this).lightBox();
	});
	$('.lightbox').each(function(){$(this).find('a').lightBox()});

    // AUTOINPUTY
    $('.autofill')
        .each(function(){
            $(this).data('value',$(this).val());
        })
        .change(function(){
            if($(this).val()!=$(this).data('value')){
                $(this).removeClass('autofill-default');
            }
        })
        .focus(function(){
            if($(this).val()==$(this).data('value')){
                $(this)
                    .val('')
                    .removeClass('autofill-default')
                ;
            }
        })
        .blur(function(){
            if($.trim($(this).val())==''){
                $(this)
                    .val($(this).data('value'))
                    .addClass('autofill-default')
                ;
            }
        })
        .addClass('autofill-default')
    ;
    $('form').submit(function(){
        $('.autofill',this).each(function(){
            if($(this).val()==$(this).data('value')){
                $(this).val('');
            }
        });
    });

	// MENU
	$('#menu area:not(.selected)').hover(function(){
		var id = $(this).attr('alt');
		$('#menu #blank').attr('src', base_dir + 'images/menu/' + id + '.gif')
	},function(){
		$('#menu #blank').attr('src', base_dir + 'images/blank.gif')
	});
	
	// GALLERY
	$('#gallery a').click(function(){		
		var photo = $(this).attr("href");

		$('#gallery a').removeClass("active-thumb");
		$(this).toggleClass("active-thumb");
		
		$('#pic-holder').append('<img class="pre-active" src="#" />');
		$('#pic-holder img.active').css("opacity", "0.3");

        $('#pic-holder img.pre-active').attr('src', photo).load(function() {
			
			$('#pic-holder img.active').fadeOut(500, function(){
				$(this).remove();
			});
			$('#pic-holder img.pre-active').fadeIn(500, function(){
				$(this).removeClass("pre-active").addClass("active");
			});
        });

        return false;



	});


});
