/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

function init(){
    jQuery.easing.custom = function (x, t, b, c, d) {
    var s = 1.70158;
    if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
    return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
    }
    jQuery("#loading_div").fadeOut(1000);
    jQuery('#body').css({
        backgroundPosition: '0px -220px'
    });
    jQuery("#curve").css({"z-index":"-1"});
    setTimeout(function(){
        jQuery('#nav').find("a:first").click();
    },1020);
    
    mainmenu();

    jQuery("#contact_send").click(function(){
        validate();
    });
    jQuery("#contact_clear").click(function(){
        clear_contact();
    });
    jQuery('#contact_us_table textarea').tabby();
        var badBrowser = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");
    if (badBrowser)
        jQuery('img[src$=.png]').each(function() {
            fixPNG(this)
        });
    //jQuery('a,input,button,textarea,img').attr("tabindex","-1");

    jQuery('#nav a:first').focus();

    jQuery('#nav a:last').bind('focus',function(){
        jQuery('#nav a:first').focus();
    })
    jQuery('body a').each(function(){
    if(jQuery(this).attr("class")=="highslide")
            jQuery(this).bind('focus',function(){
                jQuery('#nav a:first').focus();
            })
        })
    jQuery('body button').bind('blur',function(){
        jQuery('#nav a:first').focus();
    });
}

function contact_us_styling(){
    jQuery('#contact_us_table input,textarea').bind('focus',function(){
        jQuery(this).css({
            border:'2px solid #a59075'
        });
        jQuery(this).css({
            background:'#ffffff'
        });
        jQuery(this).css({
            margin:'0px'
        });
    })
    jQuery('#contact_us_table input,textarea').bind('blur',function(){
        jQuery(this).css({
            border:'1px solid #a59075'
        });
        jQuery(this).css({
            background:'#F7F6F1'
        });
        jQuery(this).css({
            margin:'1px'
        });
    })

}


function fixPNG(myImage)
{
    var arVersion = navigator.appVersion.split("MSIE")
    var version = parseFloat(arVersion[1]);
    if ((version >= 5.5) && (version < 7) && (document.body.filters))
    {
        var imgID = (myImage.id) ? "id='" + myImage.id + "' " : ""
        var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : ""
        var imgTitle = (myImage.title) ?
        "title='" + myImage.title  + "' " : "title='" + myImage.alt + "' "
        var imgStyle = "display:inline-block;" + myImage.style.cssText
        var strNewHTML = "<span " + imgID + imgClass + imgTitle
        + " style=\"" + "width:" + myImage.width
        + "px; height:" + myImage.height
        + "px;" + imgStyle + ";"
        + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
        + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>"
        myImage.outerHTML = strNewHTML
    }
}
function checkMail(valMail){
    var ismail=true;
    var filter =/^.+@.+..{2,3}$/;
    if (!filter.test(valMail))
        ismail=false
    return ismail;
}

function trim(str){
    var str=str.replace(new RegExp("^[\\s]+", "g"),"");
    str=str.replace(new RegExp("[\\s]+$", "g"), "");
    return str;
}


function validate() {
    jQuery("#validation_msg").slideUp();
    jQuery("#validation_msg").html('');
    err='';
    if (!trim(jQuery("#full_name").val())){
        err+="<li>Your full name.</li>";
    }
    if (!trim(jQuery("#country").val())){
        err+="<li>Which country you are from.</li>";
    }
    if (!checkMail(jQuery("#email").val())){
        err+="<li>Your E-mail Address.</li>";
    }
    if (!trim(jQuery("#subject").val())){
        err+="<li>The subject of your message.</li>";
    }
    if (!trim(jQuery("#message").val())){
        err+="<li>Your message or comment.</li>";
    }
    if (!trim(jQuery("#spam_input").val())){
        err+="<li>Matching the spam checker.</li>";
    }
    if (err>''){
        jQuery("#validation_msg").append("<div>There is missing info , please fill up the following fields:</div>");
        jQuery("#validation_msg").append("<ol>" + err + "</ol>");
        jQuery("#validation_msg").slideDown();
        return false;
    }
    else{
        jQuery("#validation_msg").slideDown();
        jQuery("#validation_msg").html("<div class='data'>please wait sending message</div>");
        jQuery("#contact_send").attr('disabled',true);
        jQuery("#contact_clear").attr('disabled',true);
        jQuery.ajax({
                        async:false,
                        type: "POST",
                        url: "__send_message.php",
                        data:"action=send"+"&full_name="+jQuery("#full_name").val()
                                            +"&email="+jQuery("#email").val()
                                            +"&subject="+jQuery("#subject").val()
                                            +"&message="+jQuery("#message").val()
                                            +"&country="+jQuery("#country").val()
                                            +"&spam_input="+jQuery("#spam_input").val(),
                        success: function(result){
                           var result=eval('(' + result + ')');
                           jQuery("#validation_msg").html(result.data);
                           jQuery("#validation_msg").slideDown();
                           jQuery("#contact_send").attr('disabled',false);
                           jQuery("#contact_clear").attr('disabled',false);
                           if(result.operation.match('success'))
                                clear_contact();
                           jQuery("#contact_reload_spam").click();
                        },
                        error: function(){
                            alert('Error loading');
                            jQuery("#validation_msg").slideUp();
                        }
          });

    }

}
function clear_contact()
{
    jQuery('#contact_us_table input,textarea').val('');
}

