/* ********************************************************************
	* Description.......: JavaScript support Functions for jQuery - version 0.1
	* Created by........: Euro
	* Created date......: 06-04-2008
	* Modified by.......: Adriano Pezzella
	* Modified date.....: 07-10-2008
******************************************************************** */


/* Rollover any image ************************************************************** */
/* add the class=ro to img element and create a rollover image with the same name + _on.xxx */

	PEZ = {};

	PEZ.rollover =
	{
	 init: function()
	 {
		this.preload();
		
		$(".ro").hover(
		   function () { $(this).attr( 'src', PEZ.rollover.newimage($(this).attr('src')) ); },
		   function () { $(this).attr( 'src', PEZ.rollover.oldimage($(this).attr('src')) ); }
		);
	 },
	 
	 preload: function()
	 {
		$(window).bind('load', function() {
		   $('.ro').each( function( key, elm ) { $('<img>').attr( 'src', PEZ.rollover.newimage( $(this).attr('src') ) ); });
		});
	 },
	 
//	 newimage: function( src ) { return src.substring( 0, src.search(/(\.[a-z]+)/) ) + '_on' + src.match(/(\.[a-z]+)/)[0]; },
	 newimage: function( src ) { return src.replace('.gif','_on.gif').replace('.png','_on.png');},
	 oldimage: function( src ){ return src.replace(/_on/, ''); }	
};

function manualJQueryLaunch(){
    
/*  Rollover image init ******************************************************** */
	PEZ.rollover.init();



/* Popup Box  ************************************************************** */
$(document).ready(function(){

        $('.popInfo').each(function () {
            var duration = 100;
            var offDelay = 20;

            var offDelayTimer = null;

            var isReveal = false;
            var reveal = false;
            var popIt = $('.popIt', this);
            var popup = $('.popup', this).css('opacity', 0);

            $([popIt.get(0), popup.get(0)]).mouseover(function () {
                if (offDelayTimer) clearTimeout(offDelayTimer);
                if (isReveal || reveal) {
                    return;
                } else {
                    isReveal = true;

                    popup.css({
                        display: 'block'
                    }).animate({
                        opacity: 1
                    }, duration, 'swing', function() {
                        isReveal = false;
                        reveal = true;
                    });
                }
                return false;
            }).mouseout(function () {
                if (offDelayTimer) clearTimeout(offDelayTimer);
                offDelayTimer = setTimeout(function () {
                    offDelayTimer = null;
                    popup.animate({
                        opacity: 0
                    }, duration, 'swing', function () {
                        reveal = false;
                        popup.css('display', 'none');
                    });

                }, offDelay);

                return false;
            });			
			
        });


		/* Position the Popups 'top' for the Carrers page. */
		if ($(".pb2").length > 0) {
			$('.popup').each(function () {				   
				var topPos = $(this).height() + ($(this).height()/2-7)+'px';
				var padding =  "-"+($(this).height()/2-7)+'px';
				$(this).css({
					"top" : padding,
					"height" : topPos
				});
				/*alert ($(this).css("padding-top"));*/
			});
		};

});






/*  Form Input Field Value Swap   ************************************************************** */
    swapValues = [];
    $(".swap_value").each(function(i){
        swapValues[i] = $(this).val();
        $(this).focus(function(){
            if ($(this).val() == swapValues[i]) {
                $(this).val("");
            }
        }).blur(function(){
            if ($.trim($(this).val()) == "") {
                $(this).val(swapValues[i]);
            }
        });
    });



/* PNG Fix for IE6  ************************************************************** */
	 //$(document).pngFix(); 


	
/* site index flyout  ************************************************************** */
	$('.flyoutInfo').each(function () {
		var distance = 0;
		var time = 250;
		var hideDelay = 500;

		var hideDelayTimer = null;

		var beingShown = false;
		var shown = false;
		var trigger = $('.trigger', this);
		//var info = $('.popup', this).css('opacity', 0);
		var info = $('.sitemap', this).css('opacity', 0);


		$([trigger.get(0), info.get(0)]).mouseover(function () {
			if (hideDelayTimer) clearTimeout(hideDelayTimer);
			if (beingShown || shown) {
				// don't trigger the animation again
				return;
			} else {
				// reset position of info box
				beingShown = true;

				info.css({
					top: -137,
					left: -379,
					display: 'block'
				}).animate({
					top: '-=' + distance + 'px',
					opacity: 1
				}, time, 'swing', function() {
					beingShown = false;
					shown = true;
				});
			}

			return false;
		}).mouseout(function () {
			if (hideDelayTimer) clearTimeout(hideDelayTimer);
			hideDelayTimer = setTimeout(function () {
				hideDelayTimer = null;
				info.animate({
					top: '-=' + distance + 'px',
					opacity: 0
				}, time, 'swing', function () {
					shown = false;
					info.css('display', 'none');
				});

			}, hideDelay);

			return false;
		});
	});



/* flyout from checkbox  ************************************************************** */
	$(".inner").css("display","none");
	$(".checkit").click(function(){
		if ($(".checkit").is(":checked"))
		{
			$(".inner").show("500");
		}
		else
		{	   
			$(".inner").hide("500");
		}
	});
	




/* **** */
	
}

/* document ready ****************************************************************************************************** */
$(document).ready(function(){
    manualJQueryLaunch();

/* End doc ready */
});
/* /document ready ************************************************************** */
