﻿(function ($) {
    $.fn.vAlignHeight = function () {
        return this.each(function (i) {
            var ah = $(this).outerHeight();
            var ph = $('.average').outerHeight();
            //            var mh = Math.ceil((ph - ah) / 2);
            var mh = (ph - ah) / 2;
            $(this).css({
                'margin-top': mh
            });
            //$('.text').html('Div yükseklik:' + ph + 'Resim Yükseklik' + ah + 'Sonuç:' + mh  );
        });
    };
    $.fn.vAlignHeight404 = function () {
        return this.each(function (i) {
            var ah = $(this).outerHeight();
            var ph = $(window).height();
            //            var mh = Math.ceil((ph - ah) / 2);
            var mh = (ph - ah) / 2;
            $(this).css({
                'margin-top': mh
            });
            //$('.text').html('Div yükseklik:' + ph + 'Resim Yükseklik' + ah + 'Sonuç:' + mh  );
        });
    };
    $.fn.vAlignWidth = function () {
        return this.each(function (i) {
            var ah = $(this).outerWidth();
            var ph = $('.average2').outerWidth();
            //            var mh = Math.ceil((ph - ah) / 2);
            var mh = (ph - ah) / 2;
            $(this).css({
                'margin-left': mh
            });
            //$('.text').html('Div yükseklik:' + ph + 'Resim Yükseklik' + ah + 'Sonuç:' + 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.equalHeights = function () {
        return this.each(function (i) {
            var totalWidth = $(this).outerWidth();
            var elementCount = $($(this) + 'li').size();
            var element = $($(this) + 'li');
            var elementWidth = totalWidth / elementCount;
            $($(this) + 'li').css({
                'height': elementWidth
            });
            $('.text').html('Div yükseklik:' + ph + 'Resim Yükseklik' + ah + 'Sonuç:' + mh);
        });
    };

    $.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');
        });
    };

})(jQuery);

function equalWidthFooter() {
    var totalWidth = $('.equalWidthFooter').outerWidth();
    var elementCount = $('.equalWidthFooter ul').size();
    var element = $('.equalWidthFooter ul');
    var elementWidth = totalWidth / elementCount;
    $('.equalWidthFooter ul').css({
        'width': elementWidth
    });

    //$('.textFooter').html('Div uzunluk:' + totalWidth + 'Eleman Sayısı' + elementCount + 'Sonuç:' + elementWidth);
}


//function equalHeightElement() {
//    var totalHeight = $('.equalHeightElement').height();
//    var elementCount = $('.equalHeightElement li').size();
//    var element = $('.equalHeightElement li');
//    var elementHeight = totalHeight / elementCount;
//    $('.equalHeightElement li').css({
//        'height': elementHeight
//    });
//}



//function subMenuCentered() {
//    var itemTotalWidth = 0;
//    var outer = $('.subMenu').outerWidth();
//    var count = $('.subMenu li').size();

//    $('.subMenu').find('li').each(function () {
//        itemTotalWidth += $(this).outerWidth();
//    });

//    var padding = (outer - itemTotalWidth) / 2;

//    $('.subMenu li:first-child').css({
//        'margin-left': padding
//    });

//    $('.text').html('Outer: ' + outer + ' count: ' + count + ' İtem Totol Width: ' + itemTotalWidth + ' padding: ' + padding);

//}


$(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"));
            });
        }
    });
    }
});


