jQuery(document).ready(function() {

	jQuery('input[type=text]').focus(function(){
if(jQuery(this).val() == jQuery(this).attr('defaultValue'))
{
jQuery(this).val('');
}
});
 
jQuery('input[type=text]').blur(function(){
if(jQuery(this).val() == '')
{
jQuery(this).val(jQuery(this).attr('defaultValue'));
}
});

    //Added By AAXIS Offshore Team
    jQuery('#menutabs').pngFix();
    jQuery('#mainnav').pngFix();
    //Added End


    // *****************************************************
    //              Mega Menu  -   Main Nav
    // *****************************************************
    //On Hover Over
    function megaHoverOver() {
        jQuery(this).find('.sub').stop().fadeTo(200, 1).show(); //Find sub and fade it in
        (function(jQuery) {
            //Function to calculate total width of all ul's
            jQuery.fn.calcSubWidth = function() {
                rowWidth = 0;
                //Calculate row
                jQuery(this).find('ul').each(function() { //for each ul...
                    rowWidth += jQuery(this).width(); //Add each ul's width together
                });
            };
        })(jQuery);

        var pos = jQuery(this).parent().offset();
        var height = jQuery(this).parent().height();
        var popupHeight = jQuery(this).find('.sub').height();

        if (jQuery(this).find('.row').length > 0) { //If row exists...

            var biggestRow = 0;

            jQuery(this).find('.row').each(function() {	//for each row...
                jQuery(this).calcSubWidth(); //Call function to calculate width of all ul's
                //Find biggest row
                if (rowWidth > biggestRow) {
                    biggestRow = rowWidth;
                }
            });

            jQuery(this).find('.sub').css({
                'width': biggestRow,
                'top': (pos.top + height) + "px",
                'left': (pos.left) + "px"
            }); //Set width       
            jQuery(this).find('.row:last').css({ 'margin': '0' });  //Kill last row's margin

        } else { //If row does not exist...

            jQuery(this).calcSubWidth();  //Call function to calculate width of all ul's
            jQuery(this).find('.sub').css({
                'top': (pos.top + height) + "px",
                'left': (pos.left) + "px"
            });

        }
    }
    //On Hover Out
    function megaHoverOut() {
        jQuery(this).find('.sub').stop().fadeTo(400, 0, function() { //Fade to 0 opactiy
            jQuery(this).hide();  //after fading, hide it
        });
    }

    //Set custom configurations
    var config = {
        sensitivity: 100, // number = sensitivity threshold (must be 1 or higher)
        interval: 50, // number = milliseconds for onMouseOver polling interval
        over: megaHoverOver, // function = onMouseOver callback (REQUIRED)
        timeout: 150, // number = milliseconds delay before onMouseOut
        out: megaHoverOut // function = onMouseOut callback (REQUIRED)
    };

    jQuery('#topnav li .sub').css({ 'opacity': '0' }); //Fade sub nav to 0 opacity on default
    jQuery('#topnav li').hoverIntent(config); //Trigger Hover intent with custom configurations


});
// *****************************************************
//              Mega Menu  -   Header Nav (gray menu)
// *****************************************************
jQuery(document).ready(function() {

    function megaHoverOver() {
        jQuery(this).find('.sub').stop().fadeTo(50, 1).show();
        //Calculate width of all ul's
        (function(jQuery) {
            jQuery.fn.calcSubWidth = function() {
                rowWidth = 0;
                //Calculate row
                jQuery(this).find('ul').each(function() {
                    rowWidth += jQuery(this).outerWidth();
                });
                //Calculate row
                jQuery(this).find('dl').each(function() {
                    rowWidth += jQuery(this).outerWidth();
                });
            };
        })(jQuery);

        if (jQuery(this).find('.row').length > 0) { //If row exists...
            var biggestRow = 0;
            //Calculate each row
            jQuery(this).find('.row').each(function() {
                jQuery(this).calcSubWidth();
                //Find biggest row
                if (rowWidth > biggestRow) {
                    biggestRow = rowWidth;
                }
            });
            //Set width
            jQuery(this).find('.sub').css({ 'width': biggestRow });
            jQuery(this).find('.row:last').css({ 'margin': '0' });


        } else { //If row does not exist...

            jQuery(this).calcSubWidth();
            //Set Width
            jQuery(this).find('.sub').css({ 'width': rowWidth });


        }

        jQuery(this).find('.fixIE_bottom').stop().fadeTo(10, 1).show();
    }

    function megaHoverOut() {
        jQuery(this).find('.sub').stop().fadeTo(10, 0, function() {
            jQuery(this).hide();
        });
        jQuery(this).find('.fixIE_bottom').stop().fadeTo(10, 0, function() {
            jQuery(this).hide();
        });
    }


    var config = {
        sensitivity: 100, // number = sensitivity threshold (must be 1 or higher)    
        interval: 50, // number = milliseconds for onMouseOver polling interval    
        over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
        timeout: 50, // number = milliseconds delay before onMouseOut    
        out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
    };

    jQuery('ul#menutabs li .sub').css({ 'opacity': '0' });
    jQuery('ul#menutabs li').hoverIntent(config);
});

// *****************************************************
//           Quick View Link - animation
// *****************************************************

jQuery(document).ready(function() {
    //Full Caption Sliding (Hidden to Visible)
    //
    function mouseOver() {
        jQuery('.cover', this).stop().animate({ top: '90px' }, { queue: false, duration: 500 });
    }
    function mouseOut() {
        jQuery('.cover', this).stop().animate({ top: '205px' }, { queue: false, duration: 500 });
    }
    var configForQuickViewMouseHover = {
        sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)    
        over: mouseOver, // function = onMouseOver callback (REQUIRED)    
        out: mouseOut // function = onMouseOut callback (REQUIRED)    
    };
    jQuery('#main .item dt, .item1, #main .item div').hoverIntent(configForQuickViewMouseHover);
});
// *****************************************************
//          Top Nav and Main Menu jQuery Hovering
// *****************************************************
//
//  Add class 'j-hover' to menu container elements
// 
jQuery(document).ready(function() {
    jQuery('#topnav li').hover(function() {
        jQuery(this).addClass('j-hover');
    }, function() {
        jQuery(this).removeClass('j-hover');
    });
});
jQuery(document).ready(function() {
    jQuery('#menutabs li').hover(function() {
        jQuery(this).addClass('j-hover');
    }, function() {
        jQuery(this).removeClass('j-hover');
    });
});
// *****************************************************
//          Resolve the popup z-index style.
// *****************************************************
jQuery(document).ready(function() {
    jQuery('#menutabs li.unit').hover(function() {
        jQuery('#headernav .menu').css("position","relative");
    }, function() {
        jQuery('#headernav .menu').css("position","");
    });
});
// *****************************************************
//      jQuery Modal Dialog/Popup
// *****************************************************
//
//   modal/popup windows
//      email signup, email opt out, product quick view
//
//      parameters:
//          overlay - overlay transparency (1 to 100%)
//          overlayClass - class of div to use for overlay.  Note: currently using default jqmOverlay
//          closeClass - class of "close" button or link in modal window.
//          trigger - The element that will trigger the display of the window.
//          modal - when TRUE - resticts input to only the dialog. When FALSE, clicking the overlay will close
//                     the dialog.
//      Callbacks:
//
jQuery(document).ready(function() {
    (function(jQuery) {
        jQuery.fn.positionCenter = function(options) {
            var pos = {
                sTop: function() {
                    return window.pageYOffset || document.documentElement && document.documentElement.scrollTop || document.body.scrollTop;
                },
                wHeight: function() {
                    return window.innerHeight || document.documentElement && document.documentElement.clientHeight || document.body.clientHeight;
                }
            };
            return this.each(function(index) {
                if (index == 0) {
                    var jQuerythis = jQuery(this);
                    var elHeight = jQuerythis.outerHeight();
                    var elTop = pos.sTop() + (pos.wHeight() / 2) - (elHeight / 2);
                    jQuerythis.css({
                        position: 'absolute',
                        margin: '0',
                        top: 45,//elTop,
                        left: ((jQuery(window).width() - jQuerythis.outerWidth()) / 2) + 'px'
                
				    });
                }
            });
        };
    })(jQuery);
});

jQuery(document).ready(function() {
    // onShow : show+make the window translucent
    // callback function for jqmodal
    var myOpenPNG = function(hash) {
        var maskWidth = jQuery(window).width();
        var maskHeight = jQuery(document).height();

        hash.o.css({
            position: 'absolute',
            height: maskHeight + 'px',
            width: maskWidth + 'px'
        });
        hash.o.fadeIn(5);
        hash.w.positionCenter().show();
        hash.w.bgiframe({ opacity: false });
    };


    // onClose : remove/hide the windows
    // callback function for jqmodal
    var myClosePNG = function(hash) {
        hash.w.hide();

        hash.o.fadeOut('1000');
        hash.o.remove();
    };

    // onShow : show+make the window translucent
    // callback function for jqmodal
    var myOpenGIF = function(hash) {
        var maskWidth = jQuery(window).width();
        var maskHeight = jQuery(document).height();

        hash.o.css({
            position: 'absolute',
            height: maskHeight + 'px',
            width: maskWidth + 'px',
            backgroundColor: '#f1f1f1'
        });
        hash.o.fadeIn('1000');
        hash.w.positionCenter().fadeIn('1000');
        hash.w.bgiframe({ opacity: true });
    };


    // onClose : remove/hide the windows
    // callback function for jqmodal
    var myCloseGIF = function(hash) {
        hash.w.fadeOut('1000');
        hash.o.fadeOut('1000');
        hash.o.remove();
    };
    //
    // jqmodal initialization
    //
    jQuery('#popupcontact').jqm({
        overlay: 50,
        trigger: '#recuperaClave',
        closeClass: 'popupclose',
        width: 495,
        height: 300,
        modal: true,
        onShow: myOpenGIF,
        onHide: myCloseGIF
    });
	jQuery('#EnviarAmigo').click(function()
	{
	jQuery("#error2").hide();
	jQuery("#exito2").hide();
	})
	
	
	jQuery('#popupamigo').jqm({
        overlay: 50,
        trigger: '#EnviarAmigo',
        closeClass: 'popupclose',
        width: 495,
        height: 300,
        modal: true,
        onShow: myOpenGIF,
        onHide: myCloseGIF
    });
	jQuery('#popcomentarios').jqm({
		overlay: 50,
		trigger: 'a.ex4Trigger',
		closeClass: 'popupclose',
		width: 495,
        height: 300,
		ajax: '@href',
		modal: true,
		target:'.popcomentarios_',
		toTop:true,
		onShow: myOpenGIF,
		onHide: myCloseGIF		
	});
    //
    // image preloader for popup graphics
    //
    (function(jQuery) {
        var cache = [];
        // Arguments are image paths relative to the current page.
        jQuery.preLoadImages = function() {
            var args_len = arguments.length;
            for (var i = args_len; i--; ) {
                var cacheImage = document.createElement('img');
                cacheImage.src = arguments[i];
                cache.push(cacheImage);
            }
        }
    })(jQuery)

    jQuery.preLoadImages('panel/images/ajax-loader.gif','images/popup_box_btm.png', 'images/popup_box_close_x.gif');
});


//
//   Used with controls.css
//
jQuery(document).ready(
    function() {
        jQuery('.bgiframe').bgiframe({ opacity: false });
    }

    );
//
//   Used with controls.css
//   
//      Show input fields with replaceable pale-gray text - aka 'watermark'.
//      Automatically replace the default text with blanks when the
//      user enters the field.
//
function popupOndocReady(modal,showDivId){
			 // onShow : show+make the window translucent
		    // callback function for jqmodal
		    var myOpenPNG = function(hash) {
		        var maskWidth = jQuery(window).width();
		        var maskHeight = jQuery(document).height();
		
		        hash.o.css({
		            position: 'absolute',
		            height: maskHeight + 'px',
		            width: maskWidth + 'px'
		        });
		        hash.o.fadeIn(5);
		        hash.w.positionCenter().show();
		        hash.w.bgiframe({ opacity: false });
		    };
		
		
		    // onClose : remove/hide the windows
		    // callback function for jqmodal
		    var myClosePNG = function(hash) {
		        hash.w.hide();
		
		        hash.o.fadeOut('1000');
		        hash.o.remove();
		    };
		    
		        // onShow : show+make the window translucent
		    // callback function for jqmodal
		    var myOpenGIF = function(hash) {
		        var maskWidth = jQuery(window).width();
		        var maskHeight = jQuery(document).height();
		
		        hash.o.css({
		            position: 'absolute',
		            height: maskHeight + 'px',
		            width: maskWidth + 'px',
		            backgroundColor: '#f1f1f1'
		        });
		        hash.o.fadeIn('1000');
		        hash.w.positionCenter().fadeIn('1000');
		        hash.w.bgiframe({ opacity: true });
		    };
		
		
		    // onClose : remove/hide the windows
		    // callback function for jqmodal
		    var myCloseGIF = function(hash) {
		        hash.w.fadeOut('1000');
		        hash.o.fadeOut('1000');
		        hash.o.remove();
		    };
		    
		    jQuery(showDivId).jqm({
		        overlay: 50,
		        closeClass: 'popupclose',
		        width: 495,
		        height: 300,
		        modal: modal,
		        onShow: myOpenGIF,
		        onHide: myCloseGIF
		    });
		 jQuery('.jqmOverlay').remove();
		 jQuery(showDivId).jqmShow();
	}
	


/*jQuery(window).bind("beforeunload", function(event) {
	var n = window.event.screenX - window.screenLeft;     
	var b = n > document.documentElement.scrollWidth-20;    
	if(b && window.event.clientY < 0 || window.event.altKey)     
	{
        jQuery.get(contextPath + "/timeout.jsp");
	}
});*/
