﻿

function smooth_box() {

}

function owk_smooth_box_create(i_width, i_height, i_title_height, i_close, i_title_padding_left, i_title_height_position, i_have_button, i_have_button_text, i_button_width, i_button_height) {
    on_resize();
    
    this.m_frame_width = i_width;
    this.m_frame_height = i_height;
    this.m_title_height = i_title_height;
    this.m_title_padding_left = i_title_padding_left;
    this.m_title_height_position = i_title_height_position;
    
    this.ancestor_create(new rectangle(0, 0, m_view_port_width, m_view_port_height), false, false, false);
    //this.m_div.style.background = "yellow"; 
    //this.m_div.innerHTML = "<img src="" width='" + m_view_port_width + "px' height='" + m_view_port_height  + "'/>dfdffsddsdfdsf ";    
    this.m_background_layer = new layer();
    this.m_background_layer.set_parent(this);
    this.m_background_layer.create(new rectangle(0, 0, m_view_port_width, m_view_port_height), true, false, false);
    this.m_background_layer.set_background(new color(0, 0, 0, 0));
    this.m_background_layer.set_opacity(60);
    
    this.m_iframe = document.createElement("iframe");
    this.m_iframe.frameBorder = '1';
    
    this.m_layer_title = new layer();
    this.m_layer_title.set_parent(this);
    this.m_layer_title.create(new rectangle(((m_view_port_width - i_width) / 2) - 2, ((m_view_port_height - i_height) / 2) - (i_title_height / 2), ((m_view_port_width - i_width) / 2) + i_width - 9 + 2, ((m_view_port_height - i_height) / 2) + (i_title_height / 2) + i_height), true, false, false);
    this.m_layer_title.set_background(new color(0, 0, 0, 0));
    this.m_layer_title.m_div.style.lineHeight = this.m_title_height_position;
    this.m_layer_title.m_div.style.paddingLeft = this.m_title_padding_left;

    this.m_layer_iframe = new layer();
    this.m_layer_iframe.set_parent(this);
    this.m_layer_iframe.create(new rectangle(((m_view_port_width - i_width) / 2) - 2, ((m_view_port_height - i_height) / 2), ((m_view_port_width - i_width) / 2) + i_width - 9 + 2, ((m_view_port_height - i_height) / 2) + i_height), true, false, false);
    this.m_layer_iframe.m_div.style.background = "white"; 
    this.m_layer_iframe.m_div.appendChild(this.m_iframe);
 
    var new_me = this;
    // var new_frame = this.m_iframe.style;

    //Créer le lien pour fermer
   // if (i_close) 
   
    this.m_close_button = new layer();
    this.m_close_button.set_parent(this);
    var padding_left = 3;
    var padding_top = 3;
        
    this.m_close_button.create(new rectangle((m_view_port_width - i_width) / 2 + i_width - 6 - padding_left, (m_view_port_height - i_height) / 2 - i_title_height + 2 + padding_top + (i_title_height / 2), (m_view_port_width - i_width) / 2 + i_width - padding_left, (m_view_port_height - i_height) / 2 - i_title_height + 10 + padding_top + (i_title_height / 2)), true, false, false);
    this.m_close_button.m_div.style.cursor = 'pointer';
    this.m_close_button.m_div.style.zIndex = 9999;
    this.m_close_button.m_div.onclick = function() {new_me.on_close();new_me.m_div.style.display = 'none';}

    this.m_have_button = i_have_button;
  
    this.m_button = document.createElement("BUTTON");
    var button_txt = document.createTextNode(i_have_button_text);
    this.m_button.appendChild(button_txt);
    this.m_button.style.position = 'absolute';
    this.m_button.style.width = i_button_width;
    this.m_button_width = i_button_width;
    this.m_button_height = i_button_height;    
    this.m_button.style.height = i_button_height;
    this.m_button.onclick = function() {new_me.on_hit_button(); }
    
    this.m_layer_iframe.m_div.appendChild(this.m_button);

    //alert("1"); new_frame.top = (m_view_port_height) / 2; new_frame.left = (m_view_port_width) / 2; alert("3");
    window.onresize = function() { try{if (new_me.visible()) { on_resize(); new_me.m_div.style.width = m_view_port_width; new_me.m_background_layer.style.width = m_view_port_width; new_me.m_background_layer.style.height = m_view_port_height; new_me.m_div.style.height = m_view_port_height; }}catch (e) { } }
    window.onscroll = function() { try { if (new_me.visible()) { new_me.place_object(); } } catch (e) { } }
}

function owk_smooth_box_show_url(i_url, i_title, i_width, i_height, i_title_height, i_close, i_title_padding_left, i_title_height_position) {

    this.m_frame_width = i_width;
    this.m_frame_height = i_height;
    this.m_title_height = i_title_height;
    this.m_title_padding_left = i_title_padding_left;
    this.m_title_height_position = i_title_height_position;

    this.m_iframe.src = i_url;
    this.place_object();
    this.set_visible(true);
    
    if(isIE())
    {
        this.m_iframe.style.width = i_width;
        this.m_iframe.style.height = i_height;
    }
    else 
    {
        this.m_iframe.style.width = "100%";
        this.m_iframe.style.height = "100%";
    }

    this.m_layer_title.m_div.innerHTML = "<b style='font-family:Arial, Helvetica, Sans-Serif;'>" + i_title + "</b>";
}

function owk_smooth_box_place_object() 
{
    try 
    {
        on_resize();

        var scroll_top = scroll_top_value();

        var add_pixel = 0;
        if(isIE())
        {
        //    add_pixel = 10;
        }

        var add_for_button = 0;
        if (this.m_have_button == true) 
        {
            add_for_button = 50;
        }
        
        this.m_layer_iframe.m_div.style.top = (m_view_port_height - this.m_frame_height) / 2 + this.m_title_height / 2;
        this.m_layer_iframe.m_div.style.left = (m_view_port_width - this.m_frame_width) / 2;
        this.m_layer_iframe.m_div.style.width = this.m_frame_width;
        this.m_layer_iframe.m_div.style.height = this.m_frame_height + add_for_button;

        this.m_button.style.top = this.m_frame_height + 10; //;this.m_frame_height + 50;
        this.m_button.style.left = this.m_frame_width - this.m_button_width - 10;
        
        var padding_left = 3;
        var padding_top = 3;

        this.set_region(new rectangle(0, scroll_top, m_view_port_width, (scroll_top + m_view_port_height)));
        this.m_background_layer.set_region(new rectangle(0, 0, m_view_port_width, m_view_port_height));

        this.m_layer_title.set_region(new rectangle(((m_view_port_width - this.m_frame_width) / 2) - 1, ((m_view_port_height - this.m_frame_height) / 2) - (this.m_title_height / 2), ((m_view_port_width - this.m_frame_width) / 2) + this.m_frame_width - 9 + add_pixel, ((m_view_port_height - this.m_frame_height) / 2) + (this.m_title_height / 2) + this.m_frame_height + 1 + add_for_button));
        this.m_close_button.set_region(new rectangle((m_view_port_width - this.m_frame_width) / 2 + this.m_frame_width - 6 - padding_left, (m_view_port_height - this.m_frame_height) / 2 - this.m_title_height + 2 + padding_top + (this.m_title_height / 2), (m_view_port_width - this.m_frame_width) / 2 + this.m_frame_width - padding_left, (m_view_port_height - this.m_frame_height) / 2 - this.m_title_height + 10 + padding_top + (this.m_title_height / 2)));
        this.m_close_button.set_visible(i_close);
        this.m_close_button.m_div.style.zIndex = 99999;
        
        
    }
    catch (e) { }
}

function owk_smooth_box_set_title_background_color(i_background_color) {
    this.m_layer_title.set_background(i_background_color);
}

function owk_smooth_box_set_text_title_color(i_color) {
    this.m_layer_title.m_div.style.color = "#" + i_color.rgb_to_hex();  
}

function owk_smooth_box_load_close_button_patterns(i_url) {
    this.m_close_button.load_image(i_url);
}

function owk_smooth_box_on_close(i_url) {
    
}

function owk_smooth_box_on_resize() {
    
}

function owk_on_hit_button() {
    alert("hehehe");
}


smooth_box.prototype = new layer;
smooth_box.prototype.create = owk_smooth_box_create;
smooth_box.prototype.ancestor_create = owk_layer_create;
smooth_box.prototype.show_url = owk_smooth_box_show_url;
smooth_box.prototype.set_title_background_color = owk_smooth_box_set_title_background_color;
smooth_box.prototype.set_text_title_color = owk_smooth_box_set_text_title_color;
smooth_box.prototype.load_close_button_patterns = owk_smooth_box_load_close_button_patterns;
smooth_box.prototype.on_close = owk_smooth_box_on_close;
smooth_box.prototype.on_hit_button = owk_on_hit_button;
smooth_box.prototype.on_resize = owk_smooth_box_on_resize;
smooth_box.prototype.place_object = owk_smooth_box_place_object;

