/**
 * Arquivo responsavel pela chamada de todas as funcionalidades da Campanha MCPC 2010
 *
 * @author: 
 * @date: 10/05/2010
 *
 * Copyright(c) Todos os direitos reservados a TechNova
 */
 
if (window.console == null) window.console = { log: function(p) { } };

var self;

Cufon.replace( ".cufonReplace", {
	hover: true
});

var Actions = function()
{
	self = this;

	self.init();
}

Actions.fn = Actions.prototype;
Actions.fn.extend = jQuery.extend;
Actions.fn.extend(
{
    init: function () {
        // URL
        self.url = BASE_URL;

        // Função para realizar HOVER das imagens
        self.houverImage();

        // Função para exibir videos nas modais
        self.openModal();

        // Função pora ativar hover do player
        self.hoverManifest();

        self.hovers();

        // Flash do Adesometro
        setTimeout(function () {
            if ($("#adesometro").length)
                self.adesometro();
        }, 3000);
        if ($(".contentLogin").length) {
            self.hoverOk();
        }

    },

    houverImage: function () {
        var zIndex = "";

        $("div.userImage").hover(function () {
            var $this = $(this);

            zIndex = $this.css("z-index");

            $this.addClass("active");

            if ($this.css("position") != "absolute")
                $this.css({ "position": "relative", "z-index": "1000" });
            else
                $this.css({ "z-index": "1000" });

        }, function () {
            var $this = $(this);

            $this.removeClass("active");

            $this.css({ "z-index": zIndex });

        });
    },

    hoverManifest: function () {
        $("li.manifest a").hover(function () {
            $("a.bt_playMovie").addClass("active");
        }, function () {
            $("a.bt_playMovie").removeClass("active");
        });
    },

    hoverOk: function () {
        $("input.bt_ok").hover(function () {
            $(this).addClass("active");
        }, function () {
            $(this).removeClass("active");
        });
    },

    hovers: function () {
        $("input.btNext").hover(function () {
            $(this).addClass("active");
        }, function () {
            $(this).removeClass("active");
        });
    },

    adesometro: function () {
        var flashvars = {
            servico: window.BASE_URL + "WebForms/xmlContador.aspx",
            adesao: window.BASE_URL + "Adesao/Regulamento",
            jaDoou: window.JA_DOOU.toLowerCase(),
            abrir: "actions.adesometroControl( 'abrir' )",
            fechar: "actions.adesometroControl( 'fechar' )"
        },
		params = {
		    menu: "false",
		    scale: "noscale",
		    salign: "c",
		    align: "middle",
		    wmode: "transparent"
		},
		attributes = {};

        swfobject.embedSWF(window.BASE_URL + "_global/swf/contador_2010.swf", "contadorFlash", "435", "270", "7.0.0", null, flashvars, params, attributes);
    },

    adesometroControl: function (action) {
        var divAdesometro = $("#barMC div.mundoCaixa div#adesometro");

        if (action == "abrir")
            divAdesometro.addClass("active");
        else if (action == "fechar")
            setTimeout(function () { divAdesometro.removeClass("active"); console.log("fechou") }, 1000);
        else
            return false;
    },

    openModal: function () {
        $("a.bt_playMovie").click(function () {
            $.ajax({
                url: this.href,
                success: function (response) {
                    $(response).appendTo("body").modal({
                        buttonClose: ".btnFechar"
                    }, function () {
                        Cufon.replace("div#contModal .cufonReplace");
                        var flashvars = {
                            urlVideo: "nossoManifesto.flv",
                            trasparente: "false"
                        };
                        var params = {
                            menu: "false"
                        };
                        var attributes = {
                            visibility: "visible"
                        };
                        var url = $(".menu").is("li.manifest a")
                                    ? window.BASE_URL + "_global/swf/player_mens.swf" + "?time=" + new Date().getTime()
                                    : window.BASE_URL + "_global/swf/player_mens.swf" + "?time=" + new Date().getTime();

                        swfobject.embedSWF(url, "contVideo", "640", "385", "7.0.0", window.BASE_URL + "_global/js/swfobject/expressInstall.swf", flashvars, params, attributes);
                        //alert(url);
                    });

                }
            });
            return false;
        });

        $("li.manifest a").click(function () {
            //alert('dasdsa');
            $.ajax({
                url: this.href,
                success: function (response) {
                    $(response).appendTo("body").modal({
                        buttonClose: ".btnFechar"
                    }, function () {
                        Cufon.replace("div#contModal .cufonReplace");
                        var flashvars = {
                            urlVideo: "nossoManifesto.flv",
                            trasparente: "false"
                        };
                        var params = {
                            menu: "false"
                        };
                        var attributes = {
                            visibility: "visible"
                        };
                        var url = $(".menu").is("li.manifest a")
                                    ? window.BASE_URL + "_global/swf/player_mens.swf" + "?time=" + new Date().getTime()
                                    : window.BASE_URL + "_global/swf/player_mens.swf" + "?time=" + new Date().getTime();

                        swfobject.embedSWF(url, "contVideo", "640", "385", "7.0.0", window.BASE_URL + "_global/js/swfobject/expressInstall.swf", flashvars, params, attributes);
                        //alert(url);
                    });

                }
            });
            return false;
        });
        $("div.colModel a.imgTax").click(function () {
            var _src = $(this).attr("class").split(" ")[1];
            $.ajax({
                url: this.href,
                success: function (response) {
                    var resposta = $(response);

                    resposta.appendTo("body").modal({
                        buttonClose: ".btnFechar"
                    }, function () {
                        _src == "irpf"
							? _src = window.BASE_URL + "_global/img/graph/IRPF.jpg"
							: _src = window.BASE_URL + "_global/img/graph/IR_2007_papel.jpg";

                        $("img", resposta).attr("src", _src);
                        console.log($("img", resposta))
                    });

                }
            });
            return false;
        });
        $(".highlightSide a.player").click(function () {
            $.ajax({
                url: this.href,
                success: function (response) {
                    $(response).appendTo("body").modal({
                        buttonClose: ".btnFechar"
                    }, function () {
                        Cufon.replace("div#contModal .cufonReplace");
                        var flashvars = {
                            urlVideo: "entenda-o-mcpc.flv",
                            trasparente: "false"
                        };
                        var params = {
                            menu: "false"
                        };
                        var attributes = {
                            visibility: "visible"
                        };
                        var url = $(".menu").is("li.manifest a")
                                    ? window.BASE_URL + "_global/swf/player_mens.swf" + "?time=" + new Date().getTime()
                                    : window.BASE_URL + "_global/swf/player_mens.swf" + "?time=" + new Date().getTime();

                        swfobject.embedSWF(url, "contVideo", "640", "385", "7.0.0", window.BASE_URL + "_global/js/swfobject/expressInstall.swf", flashvars, params, attributes);
                        //alert(url);
                    });

                }
            });
            return false;
        });
        $("div.listNews .playVideo, div.listNews .btPlayer").click(function () {

            var endereco = $(this).attr("rel");

            //alert(endereco);

            $.ajax({
                url: this.href,
                success: function (response) {
                    $(response).appendTo("body").modal({
                        buttonClose: ".btnFechar"
                    }, function () {
                        Cufon.replace("div#contModal .cufonReplace");
                        var flashvars = {
                            urlVideo: endereco,
                            trasparente: "false"
                        };
                        var params = {
                            menu: "false"
                        };
                        var attributes = {
                            visibility: "visible"
                        };
                        /*var url = $(".menu").is("li.manifest a")
                        ? "_global/swf/player_mens.swf" + "?time=" + new Date().getTime()
                        : "../_global/swf/player_mens.swf" + "?time=" + new Date().getTime();*/

                        swfobject.embedSWF(window.BASE_URL + "_global/swf/player_mens.swf", "contVideo", "640", "385", "7.0.0", window.BASE_URL + "_global/js/swfobject/expressInstall.swf", flashvars, params, attributes);
                        //alert(url);
                    });

                }
            });
            return false;
        });
    }
});
$(function() {
    actions = new Actions();
//    if ($.browser.msie && $.browser.version == 6)
//        DD_belatedPNG.fix(".png24");
});
