﻿$.fn.inputPlaceholder = function() {
    var placeholderText = $(this).val();
    $(this).bind('focus', function() {
        if ($(this).val() == placeholderText) {
            $(this).val('');
        }
    });
    $(this).bind('blur', function() {
        if ($(this).val() == '') {
            $(this).val(placeholderText);
        }
    });
}

$(document).ready(function() {

    $(".cufon cufontext").hide();



    var wrapperHeight = $("#wrapper").outerHeight() + $("#topbar").outerHeight() + $("#header").outerHeight() - 25
    var footerHeight = $("#footer").outerHeight();

    if ($("#footer").length > 0) {
        function onResizeHandler() {
            if ($(window).height() > (wrapperHeight + footerHeight))
                $("#footer").css("margin-top", $(window).height() - wrapperHeight - footerHeight + "px").css('margin-bottom', '0px');
            else
                $("#footer").css("margin-top", "0px");
        }
        $(window).bind("load resize", function() {
            onResizeHandler();
        });
    }


    $('#searchbox input').inputPlaceholder();

    $('.slideheader a').live('click', function() {

        if (!$(this).hasClass('activeslider')) {
            $('.opencontent').slideUp('fast')
            $('.opencontent').removeClass('opencontent');
            $('.activeslider').removeClass('activeslider');
            $(this).addClass('activeslider');
            $('.slidecontent').eq($('.slideheader a').index(this)).slideDown('fast').addClass('opencontent');
        }
        else {
            $(this).removeClass('activeslider');
            $('.opencontent').slideUp('fast')
            $('.opencontent').removeClass('opencontent');
        }
        return false;

    });

    $('table.tablestyle').each(function() {
        if ($(this).find('th').size() == 0) {
            $(this).addClass('tableNoHeader');
        }
    });

    styleTables();

    //    $('.slcproduct').change(function() {
    //        if ($(this).val() > 0) {
    //            $('.singleprodparent').hide();
    //            $('.singleprodcont').hide();
    //            $('.singleprodcont').eq(($(this).val() - 1)).show();
    //        }
    //    });

    //    if ($('.singleprodparent').size() == 0) {
    //        $('.singleprodcont').eq(0).show();
    //    }
});


function styleTables() {
    $('table.tablestyle tbody tr:first-child').addClass('firstrow');
    $('table.tablestyle tbody tr:last-child').addClass('lastrow');
    $('table.tablestyle tbody td:first-child').addClass('firstcell');
    $('table.tablestyle tbody td:last-child').addClass('lastcell');
    $('table.tablestyle thead th:first-child').addClass('firstheadercell');
    $('table.tablestyle thead th:last-child').addClass('lastheadercell');
}


function mailTo(m, e, t) {
    if (!e) {
        e = 'borusan.com';
    }
    if (!t) {
        t = m + String.fromCharCode(64) + e;
    }
    document.write('<a href="mailto:' + m + String.fromCharCode(64) + e + '" class="contentlink">' + t + '</a>');
}

var blockLoading = { message: '<img src="' + webRoot + '/img/loader_progress.gif"/><br/>Yükleniyor...', overlayCSS: { backgroundColor: '#fff', opacity: '0.5', zIndex: 500 }, css: { border: '0px', backgroundColor: 'transparent', zIndex: 501} };
var blockLoadingPage = { message: '<div class="pleaseWait"></div>',
    overlayCSS: {
        backgroundColor: '#000',
        opacity: '0.4',
        zIndex: 1000
    },
    css: {
        zIndex: 1001,
        padding: 0,
        margin: 0,
        width: '30%',
        top: '40%',
        left: '35%',
        textAlign: 'center',
        color: '#fff',
        border: 'none',
        cursor: 'wait'
    }
};

function showPageLoader() { $.blockUI(blockLoadingPage); }
function hidePageLoader() { $.unblockUI(); }



function setLoading(target, message) {
   
    var targetObj = $(target);
    var opts;
    if (message != null) {
        opts = $.extend({}, { message: message }, blockLoading);
    } else {
        opts = $.extend({}, blockLoading);
    }
    targetObj.block(opts);
   
}

function resetLoading(target) {
    var targetObj = $(target);
    targetObj.unblock();
}

jQuery.fn.extend({
    scrollTo: function(speed, easing) {
        return this.each(function() {
            var targetOffset = $(this).offset().top;
            $('html,body').animate({
                scrollTop: targetOffset
            }, speed, easing);
        });
    }
});


function onlyLetter(e) {
        var InvalidChars = "!#/*{[()]},;%^><\\?+:='`|&-_";

        var keyCode = ($.browser.mozilla) ? e.which : event.keyCode;

        if (keyCode > 47 && keyCode < 58) {
            return false;
        }
        for (i = 0; i <= InvalidChars.length - 1; i++) {
            if (keyCode == InvalidChars.charCodeAt(i)) {
                return false;
            }
        }
}

