// Preload Image for contact form

pic1= new Image(48,48); 
pic1.src="http://xibitwebdesign.com/assets/images/check.png"; 


// SLIDER JS

$(document).ready(function(){
		
	$('dl').fademenu();

	$('#jplayer').jPlayer({ // Instantiate the plugin  
         ready: function () { // Executed when the plugin is ready  
             $(this).setFile("http://xibitwebdesign.com/assets/media/ding.mp3");   
             },
			 swfPath: "/assets/js"
    })  
    .jPlayerId("play", "bell")
});

$(function() {
		   
	$('#bell').click(function(e)
	  {
		//calculating offset for displaying popup message
		leftVal = e.pageX - 275 +"px";
		topVal  = e.pageY - 25  +"px"; 
		
		//add Loading Text
		$('#close-chat').text("Loading...");
		
		//show the popup message and hide with fading effect
		$('#bellpopup').css({left:leftVal,top:topVal})
			.show()
			.fadeOut(1500, function () {
				$('#close-chat').fadeIn(500, function () {
					$('#chat').slideDown(1500, function () {
						$('#close-chat').text("Close X");
						});
					});
				});
		
	});

	$('#close-chat').click(function(e)
	  {
	    //show the popup message and hide with fading effect
		$('#chat').slideUp(1500, function () {$('#close-chat').fadeOut(1500);});
		
	});

});


jQuery(function( $ ){
				
	//Easing equation for panel
	jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	};
	
	var target = $('#content').get(0);//the scrolled div
	
	// handle nav selection
    function selectNav() {
        $(this)
            .parents('dl:first')
                .find('a')
                    .removeClass('active')
                .end()
            .end()
            .addClass('active');
    }

    $('#slider').find('a').click(selectNav);
	
	/**
	 * restart the scroll position to ( 0, 0 ) (Firefox doesn't reset it)
	 * could use $(target).scrollTo( 0, {axis:'xy'));
	 * but this needs to be quick(synchronous), to reset before $.localScroll.hash() begins
	 */
	target.scrollLeft = target.scrollTop = 0;
	
	//scroll initially if there's a hash (#something) in the url 
	$.localScroll.hash({
		target: target, //could be a selector or a jQuery object too.
		axis:'xy',//the default is 'y'
		queue:true,
		duration:1500
	});
	
	var $last = $([]);//save the last link
	
	/**
	 * NOTE: In the former version of the demo, I called $('#navigation').localScroll()
	 * Now I want to also affect the >> and << links, so I'll use $.localScroll() instead
	 */
	$.localScroll({
		target: target, //could be a selector or a jQuery object too.
		axis:'xy',//the default is 'y'
		queue:true,
		duration:1300,
		easing:'easeOutQuart',
		hash:false,	
		onBefore:function( e, anchor, $target ){//'this' is the clicked link
			$last.removeClass('scrolling');
			$last = $(this).addClass('scrolling');
		}
	});
});



jQuery.extend( jQuery.easing,
{
	
	easeInOutExpo: function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	}

});

// CONTACT FORM

$(function() {
  $('.error').hide();
  $('input.text-input').css({backgroundColor:"#FFFFFF"});
  $('input.text-input').focus(function(){
    $(this).css({backgroundColor:"#FFDDAA"});
  });
  $('input.text-input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });

  $('textarea').css({backgroundColor:"#FFFFFF"});
  $('textarea').focus(function(){
    $(this).css({backgroundColor:"#FFDDAA"});
  });
  $('textarea').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });
  
  $(".button").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide('slow');
		
	  var name = $("input#name").val();
		if (name == "") {
      $("label#name_error").show('slow');
      $("input#name").focus();
      return false;
    }
		var email = $("input#email").val();
		if (email == "") {
      $("label#email_error").show('slow');
      $("input#email").focus();
      return false;
    }
		var messagebox = $("textarea#messagebox").val();
		if (messagebox == "") {
      $("label#messagebox_error").show('slow');
      $("textarea#messagebox").focus();
      return false;
    }
		
		var dataString = 'name='+ name + '&email=' + email + '&messagebox=' + messagebox;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "/assets/snippets/xibit/submit_contact.php",
      data: dataString,
      success: function() {
		$('#contactform').fadeOut(1500, function() {
			$('#contactform').html("<div id='message'></div>");
			$('#message').html("<h2>Contact Form Submitted!</h2>")
			.append("<p>We will be in touch soon.</p><img id='checkmark' src='/assets/images/check.png' />");
			$('#contactform').fadeIn(1500);
		});
      }
	  
     });
    return false;
	});
});
