$(document).ready(function() {
	$('#newsletter .text input').each(function(){
        var value = $(this).parent().siblings('label').text();
        temp = value.split('*');
        if(!$(this).val()){
            $(this).val(temp[0]).addClass("light");
        }
    }); 
	$('#newsletter .text input').focus(function(){
		$(this).val('').removeClass("light");
	}); 
	
	$('a.top').fancybox({
	 'titleShow'       :    false, 
	 'cyclic'          :    true, 
	 'centerOnScroll'  :    true, 
	 'padding'         :    0, 
	 'overlayOpacity'  :    0.7, 
	 'overlayColor'    :    '#000'
	});
	
	$(".thumbs a").click(function() {
		var image = $(this).attr("id");
		$('.detail-image a:not(.top)').hide();
		$('.detail-image .top').removeClass('top');
		$('.'+image+':not(.top)').addClass('top').fadeIn();
		$(".thumbs a").removeClass("active"); 
		$(this).addClass("active");
		$('a.top').fancybox({
		 'titleShow'       :    false, 
		 'cyclic'          :    true, 
		 'centerOnScroll'  :    true, 
		 'padding'         :    0, 
		 'overlayOpacity'  :    0.7, 
		 'overlayColor'    :    '#000'
		});
		return false;
	});
		
	var bannerObj = $('#hero'), waitTime = 3000, fadeTime = 3000, previousImageId = 0, bannerImages = $('img', bannerObj);
	
	if( bannerImages.length > 1 ) { animateImages(1); }
	
	$(bannerImages).each(function(){
		if( $(this).attr('id') == 'bannerid-0' ) {
			$(this).addClass('banner-top');
		} else {
			$(this).hide().removeClass('hide');
		}
	});

	function animateImages(id) {
		var previousImage = $('#bannerid-'+previousImageId, bannerObj), image = $('#bannerid-'+id, bannerObj), nextImageId = id+1;
		if( id == (bannerImages.length-1) ) { nextImageId = 0; }
		if(image) {
			$(image).delay(waitTime).fadeTo(1,0,function(){
				$(previousImage).removeClass('banner-top');
				$(image).addClass('banner-top').fadeTo(fadeTime,1,function(){
					$(previousImage).fadeOut(1);
					previousImageId = id;
					animateImages(nextImageId);
				});
			});
		}
	}
         
});
