var subscribe;
var subscribeComplete;
var centerIFramePopin, closeIFramePopin;
var releaseState;
var testify, testimonies, close, sendToFriend;

$(function(){
    var getLeftPos= function ( w ) {
        var d= BOX.getDimensions();
        return ( ( ( d["viewportW"]- w )/ 2 )+ d["scrollW"] )+ "px";
    }
    var getTopPos= function ( h ) {
        var d= BOX.getDimensions();
        return ( ( ( d["viewportH"]- h )/ 2 )+ d["scrollH"] )+ "px";
    }
    centerIFramePopin= function ( params ) {
        var $ifp= $( "#iFramePopin" );
        
        var w= parseInt( $ifp.css( "width" ) );
        var h= parseInt( $ifp.css( "height" ) );
        
		if( (!params)&& (w== 2)&& (h== 2) ) {
			return;
		}
		
        if( params ) {
            w= params["width"]? params["width"] : w;
            h= params["height"]? params["height"] : h;
            if( params["width"]&& params["height"] ) {
                $ifp.css({
                    "width": params["width"],
                    "height": params["height"]
                });
            }
        }
        
        $ifp.css({
            "display": "block",
            "position": "absolute",
            "left": getLeftPos( w ),
            "top": getTopPos( h )
        });
        return false;
    };
    var openIFramePopin= function ( params ) {
        var $ifp= $( "#iFramePopin" );
        $ifp.attr( "src", params["url"] );
        centerIFramePopin( params );
        return false;
    };
    
    LOP.openIFramePopin = openIFramePopin;
    
    closeIFramePopin= function () {
        var $ifp= $( "#iFramePopin" );
        $ifp.attr( "src", "/_fr/_fr/minisites/men-expert2010/contest/vide.aspx" );
        $ifp.css({
            "display": "none",
            "position": "absolute",
            "border": "none",
            "left": "-999999em",
            "width": "2px",
            "height": "2px"
        });
    }
    releaseState= function () {
            subscribeComplete();
    }
    var sendMessageToFlash= function ( message ) {
        
                var t= $( "#LopMenDeos" ).get( 0 );
                try {
                    t[message]( data );
                } catch (e) {}
    }
    //alert('before subscribe');
    subscribe= function () {
        gState= "subscribe";
        openIFramePopin({
            "url": "/_fr/_fr/minisites/men-expert2010/register-newsletter.aspx",
            "width": 615,
            "height": 286
        });
    }
    subscribeComplete = function () {
        flashvars["user_logged"]= 1;
        sendMessageToFlash( flashvars["subscribe_call"] );
    }
    
    $( window ).resize(function(){
       //sself.parent.centerIFramePopin();
    });
});

testify = function() {
    LOP.openIFramePopin({
        'url': '/_fr/_fr/minisites/men-expert2010/testimonials-open/post.aspx',
        'width': 963,
        "height": 530
    });
    $('#iFramePopin').css('top', '238px');
};

testimonies = function() {
    LOP.openIFramePopin({
        'url': '/_fr/_fr/minisites/men-expert2010/testimonials-open/index.aspx',
        'width': 963,
        "height": 530
    });
    $('#iFramePopin').css('top', '238px');
};

close = function() {
    closeIFramePopin();
};

sendToFriend = function() {
    LOP.openIFramePopin({
        'url': '/_fr/_fr/minisites/men-expert2010/testimonials-open/send-to-friend.aspx',
        'width': 574,
        "height": 320
    });
    $('#iFramePopin').css('top', '238px');
};
