/* general scripts file for caffe torelli wp template */

// when loaded
$(document).ready(function () {

  // contact form submit
 /* $("#submit").click(function () { // ATTACH CLICK EVENT TO MYBUTTON
	  $.post("/wp/submitform.php",        // PERFORM AJAX POST
		$("#contactform").serialize(),      // WITH SERIALIZED DATA OF MYFORM
		function(data){                // DATA NEXT SENT TO COLORBOX
		  $.fn.colorbox({
			html:   data,
			open:   true,
			iframe: false            // NO FRAME, JUST DIV CONTAINER?
		  });
		},
		"html");
	});*/
	
	$("#submit").click(function () { 	
		$.ajax({
			type	: "POST",
			cache	: false,
			url		: "/wp/submitform.php",
			data	: $("#contactform").serializeArray(),
			success: function(data) {
				$.fancybox(data);
			}
		});
	
	});

  $('.point-red, .point-grn').hover(function () {
	  $(this).next().css('display','block');
  },function () {
	  $(this).next().css('display','none');
  });
  
  $("a.gallery-elem").fancybox();
  
  $('#home-panel-coffee').hover(function () {$(this).css('cursor','pointer'); }, function () {$(this).css('cursor','auto'); });  
  $("#home-panel-coffee").click(function () { window.location.href = "?page_id=8"; });

  $('#home-panel-machine').hover(function () {$(this).css('cursor','pointer'); }, function () {$(this).css('cursor','auto'); });  
  $("#home-panel-machine").click(function () { window.location.href = "?page_id=10"; });

  $('#home-panel-ms').hover(function () {$(this).css('cursor','pointer'); }, function () {$(this).css('cursor','auto'); });  
  $("#home-panel-ms").click(function () { window.location.href = "?page_id=107"; });

  $('#top-link-about').hover(function () {$(this).css('cursor','pointer'); }, function () {$(this).css('cursor','auto'); });  
  $("#top-link-about").click(function () { window.location.href = "?page_id=56"; });

  $('#top-link-ourcoffee').hover(function () {$(this).css('cursor','pointer'); }, function () {$(this).css('cursor','auto'); });  
  $("#top-link-ourcoffee").click(function () { window.location.href = "?page_id=6"; });  
  
  $('#top-link-fairtrade').hover(function () {$(this).css('cursor','pointer'); }, function () {$(this).css('cursor','auto'); });  
  $("#top-link-fairtrade").click(function () { window.location.href = "?page_id=101"; });  
  
  $('.coffee-to-shop-link').hover(function () {$(this).css('cursor','pointer'); }, function () {$(this).css('cursor','auto'); });  
  $(".coffee-to-shop-link").click(function () { window.location.href = "?page_id=19"; });  
    
  $('.machines-to-shop-link').hover(function () {$(this).css('cursor','pointer'); }, function () {$(this).css('cursor','auto'); });  
  $(".machines-to-shop-link").click(function () { window.location.href = "?page_id=19"; });  
    
  $('.ms-to-shop-link').hover(function () {$(this).css('cursor','pointer'); }, function () {$(this).css('cursor','auto'); });  
  $(".ms-to-shop-link").click(function () { window.location.href = "?page_id=19"; });  
    
  $('.page-item-12 a:first').attr("href","?page_id=107");  
  
  // facebook link
  $('#facebook').hover(function() {
 	$(this).css('cursor','pointer');
	$('#socialtext').text('Visit us on facebook.');
 	}, function() {
 	$(this).css('cursor','auto');
	$('#socialtext').text(' ');
  });
  
  $("#facebook").click(function () {
	    window.location.href = "http://www.facebook.com/pages/Caffe-Torelli/264522790252759";
  });
  
  // twitter link
  $('#twitter').hover(function() {
 	$(this).css('cursor','pointer');
	$('#socialtext').text('Follow us on twitter!');
 	}, function() {
 	$(this).css('cursor','auto');
	$('#socialtext').text(' ');
  });
  
  $("#twitter").click(function () {
	    window.location.href = "http://twitter.com/#!/CaffeTorelli";
  });
  

  // home page slider
  $(".home-slider-elem").css("display","none");
  $(".home-slider-elem:first").css("display","inline-block");
  
  function slider() {
	$(".home-slider-elem").each(function (i) {
	  if ($(this).css("display")=="inline-block") {
		  $(this).fadeOut('slow', function() {
        	 if ($(this).next().length != 0) $(this).next().fadeIn('slow');
			 else  {
				 $(".home-slider-elem:first").fadeIn('slow');
			 }
      	  });		  
		  return false;
	  }
	});
	window.setTimeout(function() {
 		slider();
	}, 10000);
	
  }
  
  slider();
 
});
