jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
	return -c * ((t=t/d-1)*t*t*t - 1) + b;
};

$(document).ready(function () {

	$("a[href='#']").click(function(e){e.preventDefault()});

	$('#homeProductsWrapper ul').carouFredSel({
		visibleItems: 1,
		auto: {
			play: true,
			duration: 1500
		},
		scroll: {
			duration: 1500
		},
		prev: {
			button: '#prev'
		},
		next: {
			button: '#next'
		},
		pagination: {
			container: '#pagination'
		}		
	});	
	
	$('#recipesWrapper').carousel({
		loop: true
	});

	$('#country_list, #partner_country_list, .uniformSel').uniform();

	$("#contact_form").validate({
		rules: {
			name: {
				required: true
			},
			surname: {
				required: true
			},
			city: {
				required: true
			},			
			country_id: {
				required: true
			},
			state: {
				required: true
			},	
			zipcode: {
				required: true
			},								
			phone: {
				required: true
			},
			fax: {
				required: true
			},						
			email: {
				required: true,
				email: true
			},
			email_confirm: {
				required: true,
				email: true				
			},			
			note: {
				required: true
			},			
			privacy: {
				required: true
			}					    			    			    			    			
		}
	});
	
	$("#login_form").validate({
		rules: {
			username: {
				required: true
			},
			password: {
				required: true
			}					    			    			    			    			
		}
	});	

	if (!($('#firstLev li.active .secondLev').length)) {
		$('#secondNav').addClass('oneLev');
	}
	
	if ($('#secondNav').length == 0) {
		$('#header').addClass('pushDown');
	}
	
	if ($('.secondLev').length == 0) {
		$('#secondNav').addClass('oneLev');
	}
	
	if($('#firstLev li.active .secondLev').length) {
		$('#firstLev li.active').addClass('nobd');
	}
	
	$('#firstLev li a').each(function() {
		$(this).bind({
			click: function (e) {
				if($(this).siblings('.secondLev').length) {
	 				e.preventDefault();
					$('#secondNav').removeClass('oneLev');
					$('#firstLev li.subActive').removeClass('subActive');
					$('#firstLev .secondLev.active').removeClass('active');
					$(this).parent().addClass('subActive');
					$(this).siblings('.secondLev').addClass('active');
					$('#firstLev li.nobd').removeClass('nobd');
				}
			}
		});
	});
	
	$('#productList p, #openList').bind('click', function (e) {
		e.preventDefault();
		if ($('#openList').hasClass('closeList')) {
			$('#productList ul').slideUp(300);
			$('#openList').removeClass('closeList');		
		} else {
			$('#openList').addClass('closeList');
			$('#productList ul').slideDown(300);			
		}
	});
	
	var singleProductWidth = $('.product').width(); 
	var allProductWidth = singleProductWidth * $('.product').length;  
	
	$('#slider').width(allProductWidth);

	if($('.colorbox').length) {
		$('.colorbox').colorbox({
			onComplete: function () {
				initialize();
			}
		});
	}
	
	if($('#select_country').length) {
		$(document).keydown(function(e){
			switch (e.keyCode) {
				case 13:
					$('#select_country button').click();
					break;
			}   
		});
	}	

	if($.browser.msie && (parseInt($.browser.version, 10) < 8)) {
		$('#productList ul li:last-child').addClass('last-child');
	}
	
	$('#slider .product a img').bind({
		mouseenter: function () {
			$(this).animate({
				width: '320px',
				height: '270px',
				top: '0',
				left: '0'				
			}, 100);
		},
		mouseleave: function () {
			$(this).animate({
				width: '300px',
				height: '250px',
				top: '10px',
				left: '10px'
			}, 100);
		}		
	});
	
	$('a.nord').bind({
		mouseenter: function () { $(this).closest('ul').addClass('nordItalia'); },
		mouseleave: function () { $(this).closest('ul').removeClass('nordItalia'); }		
	});
	
	$('a.centro').bind({
		mouseenter: function () { $(this).closest('ul').addClass('centroItalia'); },
		mouseleave: function () { $(this).closest('ul').removeClass('centroItalia'); }		
	});
	
	$('a.sud').bind({
		mouseenter: function () { $(this).closest('ul').addClass('sudItalia'); },
		mouseleave: function () { $(this).closest('ul').removeClass('sudItalia'); }		
	});		

});

function initialize() {

	var latlng = new google.maps.LatLng(40.861148,14.283342);

	var myOptions = {
		zoom: 14,
		center: latlng,
		mapTypeId: google.maps.MapTypeId.ROADMAP,
		navigationControl: true,
		navigationControlOptions: {
			style: google.maps.NavigationControlStyle.ZOOM_PAN
		},
		mapTypeControl: false,
		scaleControl: true
	};

	var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

	var marker = new google.maps.Marker({
		position: latlng,
		map: map,
		title:"Centro Direzionale"
	});

	marker.setMap(map);
	
	var contentString = '<div id="infowindow"><p><strong>Bellaitalia</strong><br />Centro direzionale Isola E2 - 80143 Napoli, Italy</p></div>';

	var infowindow = new google.maps.InfoWindow({
	    content: contentString
	});

	if(!($.browser.msie && (parseInt($.browser.version, 10) < 7))) {	
		infowindow.open(map,marker);
	}
	
}
