/*  Author:
    TAMER AYDIN - http://tamerayd.in
*/

function setPlaceholder(id) {
    if (id.val()=="" && id.attr("placeholder")!=""){
        id.val(id.attr("placeholder"));
        id.focus(function(){
            if (id.val()==id.attr("placeholder"))
                id.val("");
        });
        id.blur(function(){
            if (id.val()=="")
                id.val(id.attr("placeholder"));
        });
    }
}

function disableImgDrag(e) { //disable image dragging
    e.preventDefault();
}

window.onload = function (e) {
    var evt = e || window.event, imgs, i;
    if (evt.preventDefault) {
        imgs = document.getElementsByTagName('img');
        for (i = 0; i < imgs.length; i++) {
            imgs[i].onmousedown = disableImgDrag;
        }
    }
};

BV = {
    msie : false,
    webkit : false,
    ff : false,
    idevice : false, //iphone or ipad
    build : function () {
        if ($.browser.msie) {BV.msie=true}
        if ($.browser.webkit) {BV.webkit=true}
        if ($.browser.mozilla) {BV.ff=true}
        if ((navigator.platform.indexOf("iPhone") != -1) || (navigator.platform.indexOf("iPod") != -1) || (navigator.platform.indexOf("iPad") != -1)) {BV.idevice=true}
        if (!Modernizr.input.placeholder) {
            setPlaceholder($('.searchKeyword'));
        }
        $('aside.customLinks > a:last').css('margin','0px');
        $('nav a.active').each(function () {
            $(this).parent('li').prepend('<div class="lefttShadow"></div><div class="rightShadow"></div>');
        });
        $('div.contentContainer > div.rightSide > h1').prepend('<div class="tape top"></div><div class="tape bottom"></div>');
        $('div.contactMap').prepend('<div class="tape darker top"></div><div class="tape darker bottom"></div>');
        $('.field label').bind('click',BV.form.onClick);
        $('.field input,.field textarea').bind('focus',BV.form.onFocus);
        $('.field input,.field textarea').bind('blur',BV.form.onBlur);
        $('.scroll-pane').jScrollPane();
    },
    form : {
        onFocus : function () {
            $(this).siblings('label').hide();
        },
        onBlur : function () {
            if ($(this).val()=='')
                $(this).siblings('label').show()
        },
        onClick : function () {
            $(this).siblings('input,textarea').focus();
        }
    }
}

$(document).ready(function() {
    BV.build();
});
