$(document).ready(function() {	

$('#overlay').hide();
$('#bigIlu').hide();
$('#overlayWindow').hide();

var maxIdx = $('.items').children().length;

$("a#invite").click(function () {
      $('#phoneNum').css('color', '#fc0').css('font-weight', 'bold').css('text-shadow', '0 0 7px #e90').css('font-size','1.2em');
      $('#contactData').css('border-color', '#aaa');
});

if(jQuery().lavaLamp) {
if(IE == undefined) {
$(function() {
   $("#logotypes").lavaLamp({
   		fx: "backout",
        speed: 600,
        click: function(event, menuItem) {                
   }
});
});
}
}

$('#logotypes a').hover(
	function() {
		$('span',this).fadeIn(300);
},
	function() {
		$('span',this).hide(); //.fadeOut(150);
}
);

$('.scrollable').scrollable({
	size: 3,
	speed: 300
}).navigator();
$('.items').hover(
	function(event) {
		setTimeout("$('#zoomTooltip').fadeIn(200)", 100);	
		
		$(this).mousemove(function(event) {
			var posX = (event.pageX - 60) + 'px';	
			var posY = (event.pageY - 75) + 'px';
			
			$('#zoomTooltip').css('top',posY);
			$('#zoomTooltip').css('left',posX);
});
},
	function() { $('#zoomTooltip').fadeOut(50); }
);

$('.items').click(function() { $('#zoomTooltip').hide(); });

$('.arrow').mousedown(function() { $(this).css('top','52px'); });
$('.arrow').mouseup(function() { $(this).css('top','50px');	});

var IE/*@cc_on = @_jscript_version@*/;
if(IE == 5.7 ) {			
	$('.arrow').mousedown(function() { $(this).css('top','84px'); });
	$('.arrow').mouseup(function() { $(this).css('top','82px');	});
}

if(jQuery().draggable) {
	//$(".note").draggable();
	$("#overlayWindow").draggable();
	//$(".box").draggable({handle: 'h4'});
	//$("#bigIlu").draggable({'axis': 'y'});
}

$("#iluContainer").mousedown(function(event){ event.stopPropagation(); return false; });
$("#closeGadget").click(function() { $("#overlayWindow").fadeOut(100); });

$('#overlayWindow .oArrow').click(function(event) { event.preventDefault();});

$('#overlayWindow .prevPage').mousedown(function(event) { event.stopPropagation(); $(this).css('background-position','0 -1px'); });
$('#overlayWindow .prevPage').mouseup(function(event) { event.stopPropagation(); $(this).css('background-position','0 -37px'); });
$('#overlayWindow .prevPage').mouseover(function(event) { event.stopPropagation(); $(this).css('background-position','0 -37px'); });
$('#overlayWindow .prevPage').mouseleave(function(event) { event.stopPropagation(); $(this).css('background-position','0 -73px'); });

$('#overlayWindow .nextPage').mousedown(function(event) { event.stopPropagation(); $(this).css('background-position','-96px -1px'); });
$('#overlayWindow .nextPage').mouseup(function(event) { event.stopPropagation(); $(this).css('background-position','-96px -37px'); });
$('#overlayWindow .nextPage').mouseover(function(event) { event.stopPropagation(); $(this).css('background-position','-96px -37px'); });
$('#overlayWindow .nextPage').mouseleave(function(event) { event.stopPropagation(); $(this).css('background-position','-96px -73px'); });

$('.items a').click(function(event) { event.preventDefault(); showPicture(this); });

$('#overlayWindow .prevPage').click(function() { switchPicture(maxIdx,imgIdx,'left') });
$('#overlayWindow .nextPage').click(function() { switchPicture(maxIdx,imgIdx,'right') });
$('#formatDisk').click(function(event) { event.preventDefault(); $('#formatC').show(); });

if(jQuery().scrollTo) {
	$('#aboutSections a').click(function(event) {
		var aHref = this.getAttribute('href');
			event.preventDefault();
			$.scrollTo(aHref, 1000, {offset: -20});	
});	
	$('.backToList').click(function(event) {
		event.preventDefault();
		$.scrollTo($('header'), 700, {offset: -20});
	});
}

});

function showPicture(el,maxIdx) {
	
	$('#bigIlu').hide();
	$('#overlayWindow').fadeIn(350);
	$('#loading').fadeIn(750);
	 
	if(maxIdx == undefined) maxIdx = $('.items').children().length;	

	imgIdx = parseInt($(el).attr('id').split('_')[1]);
	var imgSrc = $(el).attr('href');
	
	if(imgIdx == 0) { 
		$('#overlayWindow .prevPage').css('opacity','0.3'); 
		$('#greyLeft').css('display', 'block'); 
		$('#overlayWindow .nextPage').css('opacity','1'); 
		$('#greyRight').css('display', 'none');
	}
	else if(imgIdx == (maxIdx - 1)) { 
		$('#overlayWindow .nextPage').css('opacity','0.3'); 
		$('#greyRight').css('display', 'block'); 
		$('#greyRight').parent().addClass('inactive');
		$('#overlayWindow .prevPage').css('opacity','1'); 
		$('#greyLeft').css('display', 'none'); 
		$('#greyLeft').parent().addClass('inactive');
	}
	else {
		$('#overlayWindow .nextPage').css('opacity','1'); 
		$('#greyRight').css('display', 'none');
	}

		
	$('#bigIlu').attr('src',imgSrc);
        
    $('#bigIlu').load(function(){  
     	$('#loading').hide();
     	$('#bigIlu').fadeIn(250); 
    });

}
function switchPicture(maxIdx,imgIdx,moveDirection) {
	
		$('.oArrow').css('opacity','1');
		$('.grey').css('display', 'none');

		switch(moveDirection) {
			case 'left':
				if(imgIdx > 0) {
					$('.grey').parent().removeClass('inactive'); 
					imgIdx--;
					var el = $('.items').children().get(imgIdx);
					showPicture(el);	
				} 
				if(imgIdx == 0) { 
					$('#overlayWindow .prevPage').css('opacity','0.3'); 
					$('#greyLeft').css('display', 'block'); 
					$('#greyLeft').parent().addClass('inactive'); 
				}
			break;
			
			case 'right':
				if(imgIdx < maxIdx-1) {
					$('.grey').parent().removeClass('inactive');	
					imgIdx++;
					var el = $('.items').children().get(imgIdx);
					showPicture(el);
					}
				if(imgIdx == (maxIdx-1)) { 
					$('#overlayWindow .nextPage').css('opacity','0.3'); 
					$('#greyRight').css('display', 'block'); 
					$('#greyRight').parent().addClass('inactive');	
				}
			break;				
}
}