/*
 * VRC NETHERLANDS 1.0 // Feb/05/2010
 *
 */

$(document).ready(function() {		
	bindMenubar();
	bindCustomerDetails();
	if($('#play-video').length) bindPlayButton();
	
	$('.fancybox').fancybox({
		'autoDimensions': false,
		'width': 660,
		'height': 490,
		'overlayOpacity': 0.8		
	});
	
	$(".search-box label").inFieldLabels({fadeOpacity:0});
});

/* binding main-menu items */
function bindMenubar() {
	$('.menubar li ul').hide();
	$('.menubar li').hover(showDropdown, hideDropdown);
	$('#vrcheader_withoutBackground').hover(keepPopup, hidePopup);
	$('.message-container').hover(keepPopup, hidePopup);
};

function showDropdown() {
	if($(this).find('ul').length) {		
		var left_position = $(this).find('a').position().left;
		var top_position = $(this).find('a').position().top + 60;		
		var elem_width = $(this).find('a').width() + 10;
		
		$(this).find('ul').stop(clearQueue=true, gotoEnd=true);
		$(this).find('ul').addClass('dropdown');
		
		$(this).find('ul').css({
			left: left_position,
			top: top_position,
			width: elem_width
		});
		
		$(this).find('a:first').addClass('activeItem');
		$(this).find('ul').css('opacity', 0.8);		
		$(this).find('ul').slideDown('fast');
	};
};

function hideDropdown() {
	$(this).find('ul').stop(clearQueue=true, gotoEnd=true);
	$(this).find('a:first').removeClass('activeItem');
	$(this).find('ul').slideUp('fast');	
};

/* bind customers-page functionality */
var last_customer, isSame;

function bindCustomerDetails() {
	/*
	$('.customers ul li').click(showCustomerDetails);
	$('.customers ul li').hover(hoverCustomer, hoverOutCustomer);
	*/
	$('.customers').hover(showCustomerDetails, hideCustomerDetails);
};

function showCustomerDetails() {	
	/*
	if(last_customer) {
		last_customer.stop().animate({height:'20px'},1000);
		last_customer.removeClass('activeCustomer');
	};*/
	
	/*
	isSame = $(this).hasClass('activeCustomer');
	if(!isSame) {		
		if(last_customer) {
			last_customer.removeClass('activeCustomer');
			last_customer.find('.customer-data').slideUp('slow');
		} 
	};*/			
	
	$(this).addClass('activeCustomer');
	$(this).stop().animate({height:'230px'},1000);	
	last_customer = $(this);
};

function hideCustomerDetails() {		
	last_customer.stop().animate({height:'30px'},1000);
	last_customer.removeClass('activeCustomer');
};

/* flash popup */
var hidingPopup;

function showPopup(num) {		
	$('.message-container').fadeOut('fast');
		
	var message, left_position;
	left_position = $('.menubar').offset().left;	
	if(num==1) {
		message=$('.message1').html();
	};
	if(num==2) {
		message=$('.message2').html();
	};
	if(num==3) {
		message=$('.message3').html();
	};
	$('.message-container').html(message);
	$('.message-container').css('left', left_position);
	$('.message-container').css('opacity', 0.95);
	$('.message-container').slideDown();
	pageTracker._trackPageview(message);
};

function hidePopup() {
	hidingPopup = setTimeout("$('.message-container').fadeOut('fast');", 1000);
};

function keepPopup() {
	clearTimeout(hidingPopup);
};

/* pop-up video player */

function bindPlayButton() {	
	$("a#play-video").fancybox({ 
		'hideOnContentClick': true,
		'overlayOpacity': 0.8,
		'frameWidth': 872,
		'frameHeight': 486
	});
};

$(document).bind("contextmenu",function(e){
	alert('Download is free. Please contact our sales department');
	return false;
});
