


$.fn.GCgallerySlideshow = function()
{
    $('#info_galeria_tv_mask').css({ 
        opacity: '0.0'
    });

    $('#anounce_ramdom_pics_row2 img').hover( function(){
        $(this).css({ 
            opacity: '0.7'
        });
    },function(){
        $(this).css({ 
            opacity: '1.0'
        });
    });

    $('#anounce_ramdom_pics_row2 img').click( function(){

        var image = $(this).attr('alt');
        var id = $(this).attr('id');

        if( id != 'gallery_more_pics' ){

            $('#info_galeria_tv_mask').animate({
                opacity : '0.5'
            },500);

            $('#anounce_info_col2_row2 img').attr({
                src : image
            });

            $('#anounce_info_col2_row2 img').load( function(){
                $('#info_galeria_tv_mask').animate({
                    opacity : '0.0'
                },500);
            });

        }
    });


}

$.fn.GCgalleryLightBox = function()
{

    //    $('#summary_gallery').click(function(){
    //        $('#gallery_more_pics').click();
    //    });


    var path = $('#images_path').text();

    $('.light').lightBox({

        // Configuracao do overlay
        overlayBgColor: 		'#000',		// (string) Background color to overlay; inform a hexadecimal value like: #RRGGBB. Where RR, GG, and BB are the hexadecimal values for the red, green, and blue values of the color.
        overlayOpacity:			0.8,		// (integer) Opacity value to overlay; inform: 0.X. Where X are number from 0 to 9

        // Configuracao da navegacao
        fixedNavigation:		false,		// (boolean) Boolean that informs if the navigation (next and prev button) will be fixed or not in the interface.

        // Configuracao das imagens
        imageLoading:			path + 'light_load.gif',		// (string) Path and the name of the loading icon
        imageBtnPrev:			path + 'light_prev.gif',			// (string) Path and the name of the prev button image
        imageBtnNext:			path + 'light_next.gif',			// (string) Path and the name of the next button image
        imageBtnClose:			path + 'light_close.jpg',		// (string) Path and the name of the close btn
        imageBlank:				path + 'light_blank.gif',			// (string) Path and the name of a blank image (one pixel)

        // Configuracao do container da imagem
        containerBorderSize:	10,			// (integer) If you adjust the padding in the CSS for the container, #lightbox-container-image-box, you will need to update this value
        containerResizeSpeed:	400,		// (integer) Specify the resize duration of container image. These number are miliseconds. 400 is default.

        // Configuracao das strings. Por exemplo: Image 2 of 8. Pode-se alterar para "Imagem" e "de"
        txtImage:				'Imagem',	// (string) Specifica o texto para "Image"
        txtOf:					'de',		// (string) Specifica o texto para "of"

        // Configuracao da navegacao pelo teclado
        keyToClose:				'c',		// (string) (c = close) Letter to close the jQuery lightBox interface. Beyond this letter, the letter X and the SCAPE key is used to.
        keyToPrev:				'p',		// (string) (p = previous) Letter to show the previous image
        keyToNext:				'n',		// (string) (n = next) Letter to show the next image.

        // Nao alterar
        activeImage:			0,
        imageArray:				[]

    });


}


//gen.position.ricardo();

//Gentools.fernando();
//Gentools.position.ricardo();


//Gentools.isLoaded( function(){
//    alert( 'Carregou Document' );
//});

function openRecommendBox(id){
    
    d = document;

    var box_mask = d.createElement('div');
    box_mask.setAttribute('id', 'recommend_box_mask');
    box_mask.onclick = function(){
        removeRecommendBox();
    }

    // opacidade da mascara ---
    Gentools.setOpacity(box_mask,'0.5');


    // tamanho da mascara ---
    box_mask.style.height = Gentools.getDimensions(document).height+'px';


    // tamanho e posicionamento do box ---

    var box = d.createElement('div');
    box.setAttribute('id', 'recommend_box');

    Gentools.centralize(box,600,400);


    document.getElementsByTagName('body')[0].appendChild(box_mask);
    document.getElementsByTagName('body')[0].appendChild(box);



    // iframe teste ---

    var iframe = document.createElement('iframe');
    iframe.src = 'implement/pages/public_comercial_recommend.inc.php?id='+id;
    iframe.setAttribute('id','iframe-content');
    iframe.setAttribute('scrolling','auto');
    iframe.setAttribute('frameBorder',0); // frame'B' por causa do ie
    iframe.setAttribute('width','100%');
    iframe.setAttribute('height','100%');
    
    box.appendChild(iframe);

}

function removeRecommendBox(){

    var box_mask = document.getElementById('recommend_box_mask');
    var box = document.getElementById('recommend_box');

    document.getElementById('recommend_box_mask').parentNode.removeChild(box_mask);
    document.getElementById('recommend_box').parentNode.removeChild(box);

}

function openContactBox(id){

    d = document;

    var box_mask = d.createElement('div');
    box_mask.setAttribute('id', 'contact_box_mask');
    box_mask.onclick = function(){
        removeContactBox();
    }

    // opacidade da mascara ---
    Gentools.setOpacity(box_mask,'0.5');


    // tamanho da mascara ---
    box_mask.style.height = Gentools.getDimensions(document).height+'px';


    // tamanho e posicionamento do box ---

    var box = d.createElement('div');
    box.setAttribute('id', 'contact_box');

    Gentools.centralize(box,600,400);


    document.getElementsByTagName('body')[0].appendChild(box_mask);
    document.getElementsByTagName('body')[0].appendChild(box);


    // iframe teste ---

    var iframe = document.createElement('iframe');
    iframe.src = 'implement/pages/public_comercial_contact.inc.php?id='+id;
    iframe.setAttribute('id','iframe-content');
    iframe.setAttribute('scrolling','auto');
    iframe.setAttribute('frameBorder',0); // frame'B' por causa do ie
    iframe.setAttribute('width','100%');
    iframe.setAttribute('height','100%');

    box.appendChild(iframe);

}

function removeContactBox(){

    var box_mask = document.getElementById('contact_box_mask');
    var box = document.getElementById('contact_box');

    document.getElementById('contact_box_mask').parentNode.removeChild(box_mask);
    document.getElementById('contact_box').parentNode.removeChild(box);

}

$.fn.GCinfoLinks = function()
{
    $('#info_mapa').click(function(){
        var canonical_url = $('#canonical_url').text();
        window.location = '/mapa/' + canonical_url;
    });

    $('#info_site').click( function(){
        var canonical_url = $('#canonical_url').text();
        window.location = '/site/' + canonical_url;
    });


    $('#info_skype').click( function(){
        var skype = $('#url_skype').text();
        window.location = 'callto:' + skype;
    });


    $('#info_indique').click(function(){

        //$.fn.GCpopupIndique();
        //$.fn.GCcallPopupIndiqueClicks();

        });

    $('#info_contato').click(function(){

        //$.fn.GCpopupContato();
        //$.fn.GCcallPopupContatoClicks();

        });

    $('#info_mapa, #info_skype, #info_indique, #info_site, #info_contato').hover(function(){
        $(this).css({
            opacity: '0.7'
        });
    },function(){
        $(this).css({
            opacity: '1.0'
        });
    });


}

$.fn.GCpopupPosition = function()
{
    
    var top = ($(window).height()/2) + $(window).scrollTop() - 200;

    $('#popup_indique').css({
        position: 'absolute',
        top: top + 'px',
        left: 280 + 'px'
        
    });

}

$.fn.GCpopupIndique = function()
{

    var html = '';

    html+='<div id="popup_indique">';
    html+='<div id="popup_close"></div>';
    html+='<div id="indique_container">';

    html+='<div id="indique_descr">Preencha e clique em "Enviar"</div>';

    html+='<div>Seu nome*:<input type="text" id="my_name" style="width: 120px;" /></div>';
    html+='<div>Seu e-mail*:<input type="text" id="my_email" style="width: 120px;" /></div>';

    html+='<div id="amigo_1">Amigo 1*:<input type="text" id="email_1" style="width: 130px;" /></div>';
    html+='<div>Amigo 2:<input type="text" id="email_2" style="width: 135px;" /></div>';
    html+='<div>Amigo 3:<input type="text" id="email_3" style="width: 135px;" /></div>';
    html+='<div>Amigo 4:<input type="text" id="email_4" style="width: 135px;" /></div>';

    html+='<div style="text-align:right; margin-right:10px; margin-top:10px;">';
    html+='<input id="indique_submit" type="image" src="../implement/pages/imgs/comercial/info_contato_submit.jpg" style="border:0px;" />';
    html+='</div>';


    html+='</div>';
    html+='</div>';


    $('body').append('<div id="popup_mask"></div>');

    var mask_width = $( window ).width();
    var mask_height = $( document ).height();
    
    $('#popup_mask').css({
        position: 'absolute',
        top: '0px',
        left: '0px',
        width: mask_width + 'px',
        height: mask_height + 'px',
        background: '#000',
        opacity: '0.2'
    });

    $('body').append(html);

    $('#popup_close').click(function(){
        $('#popup_mask').remove();
        $('#popup_indique').remove();
    });

    $.fn.GCpopupPosition();

}

$.fn.GCpopupIndiqueSubmit = function()
{

    var root_path = $('#conf_root_path').text();
    var id_anounce = $('#anounce_id').text();
    var site_name = $('#site_name').text();
    var my_name = $('#my_name').val();
    var my_email = $('#my_email').val();
    var email_1 = $('#email_1').val();
    var email_2 = $('#email_2').val();
    var email_3 = $('#email_3').val();
    var email_4 = $('#email_4').val();
    var url = window.location.href;


    if( $.fn.APIisNotEmpty(my_name) === false || $.fn.APIisNotEmpty(my_email) === false || $.fn.APIisNotEmpty(email_1) === false )
    {
        alert('Os campos "Seu Nome", "Seu e-mail" e "Amigo 1" s\u00E3o campos obrigat\u00F3rios!');
    }
    else if( $.fn.APIisEmail(my_email) === false )
    {
        alert('E-mail campo "Seu e-mail" \u00E9 incorreto!');
    }
    else if( $.fn.APIisEmail(email_1) === false )
    {
        alert('E-mail campo "Amigo 1" \u00E9 incorreto!');
    }
    else
    {

        if( $.fn.APIisNotEmpty(email_2) === true && $.fn.APIisEmail(email_2) === false)
        {
            alert('E-mail do campo "Amigo 2" \u00E9 incorreto!');
            return false;
        }

        if( $.fn.APIisNotEmpty(email_3) === true && $.fn.APIisEmail(email_3) === false)
        {
            alert('E-mail do campo "Amigo 3" \u00E9 incorreto!');
            return false;
        }

        if( $.fn.APIisNotEmpty(email_4) === true && $.fn.APIisEmail(email_4) === false)
        {
            alert('E-mail do campo "Amigo 4" \u00E9 incorreto!');
            return false;
        }


        $.ajax({
            url: root_path + 'implement/pages/public_comercial_pay_anounce_indique.inc.php',
            type: 'POST',
            data: 'my_name=' + my_name + '&my_email=' + my_email + '&email_1=' + email_1 + '&email_2=' + email_2 + '&email_3=' + email_3 + '&email_4=' + email_4 + '&id_anounce=' + id_anounce + '&site_name=' + site_name + '&url=' + url,
            success: function( code ){

                //alert( code );

                $('#popup_indique').remove();

            },
            error : function(){

                alert( 'erro' );

            }

        });

    }



}

$(document).ready(function(){

    $.fn.GCgallerySlideshow();
    $.fn.GCgalleryLightBox();

    //$.fn.GCcallPopupIndiqueClicks();

    $.fn.GCinfoLinks();
    

});