﻿$.fn.minMainHeight = function () {
    var bodyHeight = $(window).height();
    $(this).css({
        'min-height': bodyHeight
    });
};



$.fn.averageHorizontal = function () {
    return this.each(function (i) {
        var ah = $(this).outerWidth();
        var ph = $('.average').outerWidth();
        var mh = (ph - ah) / 2
        $(this).css({
            'margin-right': mh
        });

    });
};
$.fn.averageContentHorizontal = function () {
    return this.each(function (i) {
        var ah = $(this).outerWidth();
        var ph = $('.container').outerWidth();
        var mh = (ph - ah - 200) / 2
        if (ph < 1025) {
            $(this).css({
                'margin-right': 0
            });
        }
        else {
            $(this).css({
                'margin-right': mh
            });
        }
    });
};

$.fn.sameHeights = function () {
    $(this).each(function () {
        var tallest = 0;
        $(this).children().each(function (i) {
            if (tallest < $(this).height()) { tallest = $(this).height(); }
        });
        $(this).children().css({ 'height': tallest });
    });
    return this;
};

$.fn.averageVertical = function () {
    return this.each(function (i) {
        var ah = $(this).outerHeight();
        var ph = $('.average').height();
        var mh = (ph - ah) / 2;
        $(this).css({
            'top': mh
        });
    });
};

$.fn.averageVertical2 = function () {
    return this.each(function (i) {
        var ah = $(this).height();
        var ph = $('.average').height();
        var mh = (ph - ah) / 2;
        $(this).css({
            'top': mh
        });
    });
};

$(document).ready(function () {
    if (!Modernizr.input.placeholder) {
        $("input").each(
    function () {
        if ($(this).val() == "" && $(this).attr("placeholder") != "") {
            $(this).val($(this).attr("placeholder"));
            $(this).focus(function () {
                if ($(this).val() == $(this).attr("placeholder")) $(this).val("");
            });
            $(this).blur(function () {
                if ($(this).val() == "") $(this).val($(this).attr("placeholder"));
            });
        }
    });
    }



    function addMega() {
        $(this).find(".submenu").stop().fadeTo('slow', 1).show();
    }

    function removeMega() {
        $(this).find(".submenu").stop().fadeTo('normal', 0, function () {
            $(this).hide();
        });

    }
    var megaConfig = {
        interval: 100,
        sensitivity: 2,
        over: addMega,
        timeout: 200,
        out: removeMega
    };

    $("ul.menu li ul.submenu").css({ 'opacity': '0' });
    $(".menu li").hoverIntent(megaConfig);

    function addSubMega() {
        $(this).find(".sub-sub-menu").stop().fadeTo('slow', 1).show();
    }

    function removeSubMega() {
        $(this).find(".sub-sub-menu").stop().fadeTo('normal', 0, function () {
            $(this).hide();
        });

    }
    var megaSubConfig = {
        interval: 100,
        sensitivity: 2,
        over: addSubMega,
        timeout: 200,
        out: removeSubMega
    };

    $("ul.submenu li ul.sub-sub-menu").css({ 'opacity': '0' });
    $(".submenu li").hoverIntent(megaSubConfig);


    //    var BGImageArray = ["bg_01.jpg", "bg_02.jpg", "bg_03.jpg"];
    //    var BGImage = BGImageArray[Math.floor(Math.random() * BGImageArray.length)]

    //    $("body").ezBgResize({
    //        img: "/Images/" + BGImage, // Relative path example.  You could also use an absolute url (http://...).
    //        opacity: 1, // Opacity. 1 = 100%.  This is optional.
    //        center: true // Boolean (true or false). This is optional. Default is true.
    //    });

    //    function megaHoverOver() {
    //        $(this).find(".sub").stop().fadeTo('fast', 1).show();
    //    }

    //    function megaHoverOut() {
    //        $(this).find(".sub").stop().fadeTo('fast', 0, function () {
    //            $(this).hide();
    //        });
    //    }


    //    var config = {
    //        sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)    
    //        interval: 100, // number = milliseconds for onMouseOver polling interval    
    //        over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
    //        timeout: 500, // number = milliseconds delay before onMouseOut    
    //        out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
    //    };

    //    $("ul#topnav li .sub").css({ 'opacity': '0' });
    //    $("ul#topnav li").hoverIntent(config);


});

/*
Class:    	dwFadingLinks
Author:   	David Walsh
Website:    http://davidwalsh.name | http://davidwalsh.name/fading-links-jquery-dwfadinglinks
Version:  	1.0.0
Date:     	10/08/2008
Built For:  jQuery 1.2.6

$(window).bind('load', function() {
$('a.fade').fadingLinks('#f00',1000);
});
*/

jQuery.fn.dwFadingLinks = function (settings) {
    settings = jQuery.extend({
        color: '#ff8c00',
        duration: 500
    }, settings);
    return this.each(function () {
        var original = $(this).css('color');
        $(this).mouseover(function () { $(this).animate({ color: settings.color }, settings.duration); });
        $(this).mouseout(function () { $(this).animate({ color: original }, settings.duration); });
    });
};

jQuery.fn.equalHeight = function () {
    var height = 0;
    var maxHeight = 0;

    // Store the tallest element's height
    this.each(function () {
        height = jQuery(this).outerHeight();
        maxHeight = (height > maxHeight) ? height : maxHeight;
    });

    // Set element's min-height to tallest element's height
    return this.each(function () {
        var t = jQuery(this);
        var minHeight = maxHeight - (t.outerHeight() - t.height());
        var property = jQuery.browser.msie && jQuery.browser.version < 7 ? 'height' : 'min-height';

        t.css(property, minHeight + 'px');
    });
};
