// * Arquivo responsável pelo JS do Site Brasiliense de coracao
// *
// * @author: CasaNova Comunicação
// * @date: 2011/06/13
// *
// * Copyright(c) Todos os direitos reservados a TAL
// 

if (window.console == null) window.console = { log: function(p) { } };

var _this;

var Functions = function()
{
	_this = this;
	
	_this.init();
}

Functions.fn = Functions.prototype;
Functions.fn.extend = jQuery.extend;
Functions.fn.extend(
{
    init: function () {
        if ($("div.plant").length)
            _this.zoomImg();
        if ($("div.sponsor").length)
            _this.changeTabs();

        if ($("div.press").length)
            _this.validateForm();
    },

    changeTabs: function () {
        $("ul.tabs li a").click(function () {
            var classe = $(this).attr("class");

            $(this).parent().addClass("active")
						.siblings("li").removeClass("active");
            $("div.text ." + classe).addClass("active")
										.siblings("div").removeClass("active");
            return false;
        });
    },
    zoomImg: function () {
        //$.noConflict();
        $("img.jqzoom").jqueryzoom({
            zoomWidth: 247,
            zoomHeight: 192,
            xzoom: 247, //zooming div default width(default width value is 200)
            yzoom: 192, //zooming div default width(default height value is 200)
            offset: 10, //zooming div default offset(default offset value is 10)
            position: "top" //zooming div position(default position value is "right")
        });
    },

    validateForm: function () {

        $("ul li input, ul li textarea").live("focus", function () {
            console.log("teste");
            $(this).removeClass("error");
            $("div.error").css("display", "none");            
            $("div.sucess").css("display", "none");
        });

        $(".btSend").click(function () {

            var isToSend = true;

            $("div.error").css("display", "none");
            $("div.sucess").css("display", "none");

            $("ul li input, ul li textarea").each(function () {

                var element = $(this).val();
                if (!element && $(this).attr("id") != "empresa") {
                    isToSend = false;
                    $(this).addClass("error");
                    $("div.error").css("display", "block");
                } else {
                    if ($(this).attr("id") == "email") {
                        var email = $(this).val();
                        if (email.search(/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,4}$/) === -1) {

                            isToSend = false;
                            $(this).addClass("error");
                            $("div.error").css("display", "block");                         
                        }                       
                    }
                }

            });
            return isToSend;
        });

    }

});

$( function()
{
	functions = new Functions();
	
});

$.fn.resetDefaultValue = function() {
    function _clearDefaultValue() {
        var _$ = $(this);
        if (_$.val() == this.defaultValue) { _$.val(''); }
    };
    function _resetDefaultValue() {
        var _$ = $(this);
        if (_$.val() == '') { _$.val(this.defaultValue); }
    };
    return this.click(_clearDefaultValue).focus(_clearDefaultValue).blur(_resetDefaultValue);
};

