// start menu hover
$(function() {
		$('#navigation ul li').hover (
		function() {
			$(this).addClass('navhover');
			
		}, function() {
			
			 $(this).removeClass('navhover');
		}
	);
});

$(function() {
if ( $("#navigation ul li").hasClass("current") )
        $(this).addClass('navhover');
    });


// start slider

	jQuery(window).bind("load", function() {
			jQuery("div#sliderc").codaSlider()
		});

// start tooltip

/*
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 */



this.tooltip = function(){
	/* CONFIG */
		xOffset = -25;
		yOffset = -40;
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
	/* END CONFIG */		
	$(".tooltip").hover(function(e){
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;
		$("#tooltip").remove();
    });
	$(".tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};




// prepend the span tag to the photo gallery
$(function() {
	$(".gallery a, a.productImages").prepend("<span></span>");
});

// send the email
      // let's start the jQuery while I wait.
      // step 1: onload - capture the submit event on the form.
      $(function() { // onload...do
        $('#form').submit(function() {
          // now we're going to capture *all* the fields in the
          // form and submit it via ajax.
          
          // :input is a macro that grabs all input types, select boxes
          // textarea, etc.  Then I'm using the context of the form from 
          // the initial '#contactForm' to narrow down our selector
          var inputs = [];
          $(':input', this).each(function() {
            inputs.push(this.name + '=' + escape(this.value));
          })
          
          // now if I join our inputs using '&' we'll have a query string
          jQuery.ajax({
            data: inputs.join('&'),
            url: this.action,
            timeout: 2000,
            error: function() {
              console.log("Failed to submit");
            },
            success: function(r) { 
           if (r == 1) {
			   
			   $('form').slideUp('slow');
			   $('p#please').slideUp('slow');
			$("h1").after('<p id="success" style="display:none;">Your message was sent successfully! We will contact you as soon as possible. </p>');
	$('#success').slideDown('slow');
		   }
		   else {
			   alert(r)
		   }
				   
			 
			  
            }
          }) // checkout http://jquery.com/api for more syntax and options on this method.
          
          // re-test...
          // by default - we'll always return false so it doesn't redirect the user.
          return false;
        })
      })




  /**
 * Simple Water Mark
 * July 18, 2009
 * Corey Hart @ http://www.codenothing.com
 */
/**
 * @mainCSS: Default CSS class used if no metadata found
 */
;(function($){
    $.fn.simpleWaterMark = function(mainCSS){
        if (!mainCSS) mainCSS = 'non-404';
        return this.each(function(){
            var $obj = $(this), title = this.title, css = $.metadata && $obj.metadata().watermark ? $obj.metadata().watermark : mainCSS;

            // Add watermark to begin with
            if ($obj.val() == '' && title && title != '')
                $obj.addClass(css).val(title);

            // Run operations
            $obj.focus(function(){
                if ($obj.hasClass(css))
                    $obj.removeClass(css).val('');
            }).blur(function(){
                if ($obj.val() == '' && title && title != '')
                    $obj.addClass(css).val(title);
            }).parents('form').eq(0).submit(function(){
                if ($obj.hasClass(css))
                    $obj.val('');
            });

            // Clear fields on page unload
            $(window).unload(function(){
                if ($obj.hasClass(css))
                    $obj.removeClass(css).val('');
            });
        });
    };
})(jQuery);



      $(document).ready(function(){
	$('input[type=text], textarea').simpleWaterMark('watermark');
});

var default_content="";

$(document).ready(function(){

	checkURL();
	$('ul li a').click(function (e){

			checkURL(this.hash);

	});

	//filling in the default content
	default_content = $('#pageContent').html();


	setInterval("checkURL()",250);

});

var lasturl="";

function checkURL(hash)
{
	if(!hash) hash=window.location.hash;

	if(hash != lasturl)
	{
		lasturl=hash;

		// FIX - if we've used the history buttons to return to the homepage,
		// fill the pageContent with the default_content

		if(hash=="")
		$('#pageContent').html(default_content);

		else
		loadPage(hash);
	}
}


function loadPage(url)
{
	url=url.replace('#','');

	$('#loading').css('visibility','visible');

	$.ajax({
		type: "POST",
		url: "load_page.php",
		data: 'page='+url,
		dataType: "html",
		success: function(msg){

			if(parseInt(msg)!=0)
			{
				$('#pageContent').html(msg);
				$('#loading').css('visibility','hidden');
			}
		}

	});

}


