$(function(){$(document).pngFix();});
$(document).ready(function() {


	$.fn.colorbox.settings.contentCurrent = "{current} / {total}";
	$.fn.colorbox.settings.contentPrevious = "PREV";
	$.fn.colorbox.settings.contentNext = "NEXT";
	$.fn.colorbox.settings.modalClose = "CLOSE";
	
	$("a[rel='gallery']").colorbox({transition:"elastic"});

			
	// var hash = window.location.hash.substr(1);
	// 	var href = $('#nav a').each(function(){
	// 		var href = $(this).attr('href');
	// 		if(hash==href.substr(0,href.length-4)){
	// 			var toLoad = hash+'.php #content';
	// 			$('#content').load(toLoad)
	// 		}											
	// 	});
	// 	
	// $('#nav a').click(function(){
	// 		$('#nav a').css('color','#83bbe5');
	// 		$(this).css('color','#318ccb');					  
	// 		var toLoad = $(this).attr('href')+' #content';
	// 		$('#content').hide('normal', loadContent);
	// 		$('#container').append('<div id="load"></div>');
	// 		$('#load').fadeIn('normal');
	// 		window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-4);
	// 		function loadContent(){
	// 			$('#content').load(toLoad,'', hideLoader);
	// 		}
	// 		function hideLoader(){
	// 			$('#load').fadeOut('normal', showContent);
	// 		}
	// 		function showContent(){
	// 			$('#content').fadeIn('normal');
	// 		}
	// 		return false;
	// 	});
	
	$('#enter')
		.fadeIn('slow');
	
	$('.mission').fadeIn('slow');
	
	//How We Operate page functions
	
	$('#operate img.inactive')
		.css({opacity:0.33, filter:"alpha(opacity = 33)", zoom:1})
		.mouseover(function () {
			$(this).fadeTo('fast', 1);
			return false;
		})
		.mouseout(function () {
			$(this).fadeTo('fast', 0.4);
			return false;
		});
	
	
	// $('#operate img')
	// 		.fadeTo('slow', 0.33)
	// 		.mouseover(function () {
	// 			$(this).fadeTo('fast', 1);
	// 			return false;
	// 		})
	// 		.mouseout(function () {
	// 			$(this).fadeTo('fast', 0.4);
	// 			return false;
	// 		})
	// 		.click(function(){
	// 			$('#operate img').fadeTo('fast', 0.4).bind('mouseout',function () {
	// 				$(this).fadeTo('fast', 0.4);
	// 				return false;
	// 			});
	// 			$(this).fadeTo('fast', 1).unbind('mouseout');
	// 			return false;
	// 		});
	// 
	// 	$('.servicebutton').click(function(){
	// 		$('.op').hide();
	// 		$('.service').show('fast');
	// 	});
	// 	$('.traditionbutton').click(function(){
	// 		$('.op').hide();
	// 		$('.tradition').show('fast');
	// 	});
	// 	$('.experiencebutton').click(function(){
	// 		$('.op').hide();
	// 		$('.experience').show('fast');
	// 	});
	// 	$('.forecastingbutton').click(function(){
	// 		$('.op').hide();
	// 		$('.forecasting').show('fast');
	// 	});
	// 	$('.qualitybutton').click(function(){
	// 		$('.op').hide();
	// 		$('.quality').show('fast');
	// 	});
	// 	$('.sustainabilitybutton').click(function(){
	// 		$('.op').hide();
	// 		$('.sustainability').show('fast');
	// 	});
	// 	$('.sourcingbutton').click(function(){
	// 		$('.op').hide();
	// 		$('.sourcing').show('fast');
	// 	});
	// 	$('.logisticsbutton').click(function(){
	// 		$('.op').hide();
	// 		$('.logistics').show('fast');
	// 	});
	
	//Products page functions
	
	$('.productpics').cycle({  
		timeout: 4000,
	    speed:  1000 
	});
	
	$('#moreinfo').cycle({
	    prev:   '#prev',
	    next:   '#next',
	    timeout: 0
	});
	
	$('.shiftleft').click(function(){
	    $('#shifter').animate({
		 	left: "-850px"
		}, 400 );
		return false;
	});

	$('.shiftright').click(function(){
	    $('#shifter').animate({
		 	left: "0px"
		}, 400 );
		return false;
	});
	
	


	
	
	//Contact page functions
	$('#customerform').ajaxForm(function(data) {
		
		if (data==1){
			$('#error').empty().hide("fast");
			$('#output').hide("fast");
			$('#output').fadeIn("slow");
			$('#customerform').resetForm();
		}
		else if (data==2){
			$('#error').empty().hide("fast");
			$('#output').hide("fast");
			$('#error').fadeIn("slow").append("Favor de entrar su <strong>nombre</strong> y su <strong> dirección correo electrónico</strong>.");
		}
		else if (data==3)
		{
			$('#error').empty().hide("fast");
			$('#output').hide("fast");
			$('#error').fadeIn("slow").append("Favor de entrar una dirrección correo electrónico válida.");
		}
	});
	
	$('#supplierform').ajaxForm(function(data) {
		
		if (data==1){
			$('.superror').empty().hide("fast");
			$('.supoutput').hide("fast");
			$('.supoutput').fadeIn("slow");
			$('#supplierform').resetForm();
		}
		else if (data==2){
			$('.superror').empty().hide("fast");
			$('.supoutput').hide("fast");
			$('.superror').fadeIn("slow").append("Favor de entrar su <strong>nombre</strong> y su <strong> dirección correo electrónico</strong>.");
		}
		else if (data==3)
		{
			$('.superror').empty().hide("fast");
			$('.supoutput').hide("fast");
			$('.superror').fadeIn("slow").append("Favor de entrar una dirrección correo electrónico válida.");
		}
	});
	
	
	$('input[type="text"], textarea').addClass("idleField");
	$('input[type="text"], textarea').focus(function() {
		$(this).removeClass("idleField").addClass("focusField");
	    if (this.value == this.defaultValue){
	    	this.value = '';
		}
	    if(this.value != this.defaultValue){
	    	this.select();
	    }
	});
	$('input[type="text"], textarea').blur(function() {
		$(this).removeClass("focusField").addClass("idleField");
	    if ($.trim(this.value == '')){
	    	this.value = (this.defaultValue ? this.defaultValue : '');
		}
	});

	$('.customerform').click(function(){
		$('#supplier').fadeOut('fast', showCustomer);
		function showCustomer(){
			$('#customer').fadeIn('fast');
			$('.customerform').css('color', '#318ccb');
			$('.supplierform').css('color', '#83bbe5');
		}
		return false;
	});
	$('.supplierform').click(function(){
		$('#customer').fadeOut('normal', showsupplier);
		function showsupplier(){
			$('#supplier').fadeIn('fast');
			$('.supplierform').css('color', '#318ccb');
			$('.customerform').css('color', '#83bbe5');
		}
		return false;
	});
	
});
