/*************************************************************/
// module prod javascript file
// (c) thomann - don't even think about copying, stealing or trying to understand this code
/*************************************************************/

var bew_artnr = false;
var helpText = '';
var blameText = '';
var helpTextMA = '';

var bewBlameOk = '';
var bewBlameNot = '';
var bewBlameNoText = '';
var bewBlameNoLogin = '';

var bewDetailState = 'detailed'; // ( detailed | compact )

var bewBoxRateInfo = '';
var bewLastRateInfoExakt = 0;

var rateInfo_1Kunde1Star = '';
var rateInfo_nKunde1Star = '';
var rateInfo_1KundenStar = '';
var rateInfo_nKundenStar = '';
var rateInfo_noText1Star = '';
var rateInfo_noTextnKunden = '';
var rateInfo_nonoText1Kunde = '';
var rateInfo_nonoTextnKunden = '';
var rateInfo_show1 = '';
var rateInfo_showN = '';

$(document).ready( function() {

    $('a#bewNoRate, a#bewRatingLinkButton')
    .click( function(e) {
        var $o = $(this).offset();
        var $BtnH = $(this).height();
        var noRateLeft = Math.round($o.left)-40;
        var $BoxNotYouH = $('#bewnotyou').height();
        var noRateTop1 = $o.top - $BoxNotYouH;
        $('#bewnotyou').css( { 'top': noRateTop1, 'left': noRateLeft} );
        var $BoxNotLogH = $('#bewnotloggedinbox').height();
        var noRateTop2 = $o.top - $BoxNotLogH;
        $('#bewnotloggedinbox').css( { 'top' : noRateTop2, 'left' : noRateLeft } );

        //send ajax, abhängig vom status layer anzeigen oder bov!
        var data = { ajax_type: 'newRateState', artnr: bew_artnr, sid: jsNCTrackingSID };
        $.post('prod_prodrateajax.html', data, function( res ) { 

            if ( res == 3 ) document.location.href='mythomann_prodrate.html?ratenr='+bew_artnr;
            if ( res == 2 ) {
                $('#bewnotyou').show();
            }
            if ( res == 1 ) {
                $('#bewnotloggedinbox').show();
            }
        } );
        return false;
    });

    $('body').append( $('#bewHelp') );
    $('body').append( $('#bewnotyou') );
    $('body').append( $('#bewnotloggedinbox') );
    $('body').append( $('#rateinfobox') );

    bindCommonHandlers();

    $('#bewShowAll, .bewShowAllTextLink')
        .click( function(e) {
            open_overlay( bew_artnr, 0, e );
            return false;
        });
    
    $('.bewRatingDetailCustomersDesc a')
        .click( function(e) {
            $('#rateinfobox').hide();
            var m = $(this).attr('rel').split('_');
            var exakt = m[0];
            var textOnly = m[2];

            if ( textOnly > 0 ) open_overlay( bew_artnr, exakt, e );
            
            return false;
        })
        .mouseenter ( function(e) {
            $rib = $('#rateinfobox');
            $('body').stopTime('rateInfo');
            $('#rateinfo-button',$rib).hide();
            
            var m = $(this).attr('rel').split('_');
            var exakt = m[0];
            var ratings = m[1];
            var textOnly = m[2];
            
            var showB = false;
            bewLastRateInfoExakt = exakt;

            if ( ratings > 0 ) {
                var helpText = '';
                if ( ratings == 1 && exakt == 1 ) {
                    helpText = rateInfo_1Kunde1Star;
                } else if ( ratings > 1 && exakt == 1 ) {
                    helpText = rateInfo_nKunde1Star.replace( /<%nKunden%>/, ratings );
                } else if ( ratings == 1 && exakt > 1 ) {
                    helpText = rateInfo_1KundenStar.replace( /<%nStar%>/, exakt );
                } else if ( ratings > 1 && exakt > 1 ) {
                    helpText = rateInfo_nKundenStar.replace( /<%nKunden%>/, ratings ).replace( /<%nStar%>/, exakt );
                }
                helpText = '<b>' + helpText + '</b><br><br>';
                
                var n = ratings - textOnly;
                if ( textOnly > 0 ) {
                    if ( n > 0 ) {
                        if ( n == 1 ) {
                            helpText = helpText + rateInfo_noText1Star;
                        } else {
                            helpText = helpText + rateInfo_noTextnKunden.replace( /<%nKunden%>/, n );
                        }
                        helpText = helpText + '<br><br>';
                    }
                    showB = true;
                } else {
                    if ( ratings > 1 ) {
                        helpText = helpText + rateInfo_noTextnKunden.replace( /<%nKunden%>/, n );
                    } else {
                        helpText = helpText + rateInfo_nonoText1Kunde;
                    }
                }

                $rib.css( { 'top': $(this).offset().top + $(this).height() + 2, 'left': $(this).offset().left - 13} ).show();
                $('#rateinfobox #rateinfo-content').html( helpText );
                $('#rateinfo-goldenStars',$rib).css( 'width', exakt*20 + '%' );
                if ( showB ) $('#rateinfo-button',$rib).show().html( textOnly > 1 ? rateInfo_showN.replace( /<%n%>/, textOnly ) : rateInfo_show1  );
                $rib.show();
            }
                
            return false;
        })
        .mouseleave( function(e) { rateinfoLinkBoxLeave(); });

    $('#rateinfobox')
        .mouseover( function() { $('body').stopTime('rateInfo'); })
        .mouseleave( function() { rateinfoLinkBoxLeave(); } );
        
    $('#rateinfo-button')
        .click( function( e ) {
            $('#rateinfobox').hide();
            open_overlay( bew_artnr, bewLastRateInfoExakt, e );
            return false;
        });
    $('#rateinfobox #rateinfo-close')
        .click( function() { $('#rateinfobox').hide(); });
        
        
        
        
    $('#prod-detailsWvf-detailLink')
        .mouseover( function() {
            var $d = $('#prod-detailsWvf-details');
            $d.show();
            
            $d.offset( { 'left':$(this).offset().left + $(this).width() - 5,
                         'top':$(this).offset().top + 10
                     } );
        } )
        .mouseout( function() {
            $('#prod-detailsWvf-details').hide();
        } );

    //all of the overlays, shown on the basket page
    $('#prod-articlediscount a').overlay({
        left: 100,
        top: '0',
        close: '.closeButton',
        onLoad: function( e ) {
            $('#prod-articlediscount-overlay').bgiframe();
        }
    });

    countdown( $('#timeConstraint .nc-countdown'), function() { console.log( 'ficken'); $('#prod-articlediscount').fadeOut(); } );

});

var dropval = { 'filter-by': 'all', 'sort-by': 'helpful-asc', 'page' : 1 };


function triggerBEWdetails( a, context ) {
    var stem = context ? context : $('#bew_ov_content .bewEntry');
    var b = stem.find('.bewEntryWrapAnim');
    if ( a == 'show' ) b.show();
    if ( a == 'hide' ) b.hide();
    
    if ( a == 'slideup' ) b.stop( true, true ).slideUp( 500 );
    //if ( a == 'slidedown' ) b.stop( true, true ).slideDown( 500 );
    
    //if ( a == 'slideup' ) b.animate( { height: '0px' } , 1500 );
    if ( a == 'slidedown' ) {
        var h = '';
        b.each( function() {
            h = $(this).data('height') + 'px';
            b.animate( { height: h }, 500 );
        } );
    }
}

function setHeadPointer( p ) {
    $('#bew_ov_content .bewEntryHead').css( 'cursor', p );
}
function setHeadIcon( p ) {
    if ( p == 'block' ) $('#bew_ov_content .bewEntryBigButton').parent().css( 'width', '20px' );
    $('#bew_ov_content .bewEntryBigButton').css( 'display', p );
    if ( p == 'none' ) $('#bew_ov_content .bewEntryBigButton').parent().css( 'width', '0px' );
}
function rateinfoLinkBoxLeave() {
    $('body').stopTime('rateInfo').oneTime( 200, 'rateInfo', function() {
        $('#rateinfobox').hide();
    });
}



function open_overlay( ar, exact, e ){
    var data = {artnr: ar };

    if( exact ){
        jQuery.extend( data, { 'b_filter' : 'exact-'+exact } );
    }

    var yp = $('body').scrollTop();
    var t = yp;
    var xp = 200; 
    if( e ) {
        yp = e.pageY;
        xp = e.pageX;
    }else{
        yp += 300;
    }

    $('body').stopTime('ppra').oneTime( 600, 'ppra', function() {
        // element fade in 
        $('#bewFooter img').show();
    });

    try { pageTracker._trackPageview("/ajaxCallBewFull" ); } catch(e) {}
    $.post('prod_prodrateajax.html', data, function( res ) {
        $('body').ajaxLoad('unique_ajax_1', res, function( ) {
            $(this).css({'display': 'block', 'top': t+30 });
            // element fade out
            $('body').stopTime('ppra');
            $('#bewFooter img').hide();
            $('#bew_ov_wrapper').scrollTo( 0 );
        });
    }, 'html' );
}

function loadpartial( page ) {
    if( page ) dropval['page'] = page;

    $('#bew_ov_wait').show();


    try { pageTracker._trackPageview("/ajaxCallBewPartial" ); } catch(e) {}
    $.post('prod_prodrateajax.html',  {artnr: bew_artnr, 'b_filter': dropval['filter-by'], 'b_order': dropval['sort-by'], 'b_type': 'partial', 'b_page': dropval['page']  } , function( res ) {
        /*$('#bew_boxmodel_bug').css('visibility','hidden'); //furs auslesen der höhen kurz ausschalten*/

        $('#bew_boxmodel_bug').html( res ); //übertragenen inhalt posten
        
        bindCommonHandlers(); //eventhandlers setzten
        if ( bewDetailState == 'compact' ) {
            setHeadPointer( 'pointer' ); //im compactmodus mousepointer modifizieren
            setHeadIcon( 'block' );
        }

        //im compactmodus NACH dem höhenauslesen alle bewertungsbodies per display:none verstecken
        if ( bewDetailState == 'compact' ) $('#bew_boxmodel_bug').prepend( '<style> #bew_ov_content .bewEntryWrapAnim {display: none; }</style>' );
        
        $('#bew_ov_wait').hide(); //warterädchen weg
        $('#bew_ov_wrapper').scrollTo( 0 ); //nach oben scrollen
        /*$('#bew_boxmodel_bug').css('visibility','visible'); //alles anzeigen*/
    }, 'html' );
}

function overlay_loaded() {
    var h = $(window).height()-140;
    if( h < 490 ) h = 490;
    var $b = $('#bew_overlay');
    $('div.ov-content-wrap', $b).css({'height': h+'px'});
    $('div#bew_ov_wrapper', $b).css({ 'overflow' : 'auto', 'height': (h-32-32)+'px'}); //two bars, one on the top one on the bottom now.....

    function dropdownChanged(id, val ) {
            dropval[ id ] = val;
            loadpartial( 1 );
    }


    bindCommonHandlers();

    $(document).ready( function() {
        var $b = $('#bew_overlay');

        $('#starDetail').addClass('bew_ov_starConfigActive');
        
        $('#bew_boxmodel_bug').scroll( function() {
                var x = $(this).offset().x;
                $('#bew_ov_sidebar').text( x );
        });

        $b.draggable({
                handle: '#bew_ov_top', containment: 'document', distance: 3, cursor: 'move'//,
                //start: function() {  $('#bew_ov_content').css('overflow', 'hidden');},
                //stop: function() { $('#bew_ov_content').css('overflow', 'auto'); },
                });
        $b.bgIframe();
                
        $('#starCompact')
            .click( function() {
                triggerBEWdetails( 'hide' );
                setHeadPointer( 'pointer' );
                setHeadIcon( 'block' );
                
                bewDetailState = 'compact';
                $(this).addClass('bew_ov_starConfigActive');
                $('#starDetail').removeClass('bew_ov_starConfigActive');        
                return false;
            });
        $('#starDetail')
            .click( function() {
                triggerBEWdetails( 'show' );
                setHeadPointer( 'auto' );
                setHeadIcon( 'none' );

                bewDetailState = 'detailed';
                $(this).addClass('bew_ov_starConfigActive');
                $('#starCompact').removeClass('bew_ov_starConfigActive');    
                return false;
            });
        
        $('#bew_ov_closeButton')
            .click( function() {
                $b.fadeToCompatible( 300, 0.0, function() {
                        $(this).css('display', 'none');
                    }
                );
            });
        $('#bew_ov_close', $b).click( function() {
            $b.fadeToCompatible( 300, 0.0, function() {
                    $(this).css('display', 'none');
                }
            );
        }).hover( function() { $(this).addClass('bew_ov_close_hover'); }, function() { $(this).removeClass('bew_ov_close_hover'); } );


        function bddshow ( $ft ) {
            var off = $('.bdd-dropdown', $ft).position().left;
            $('.bdd-list', $ft).css('left', off ).css('display', 'block').fadeTo( 200, 1.0 );
            $ft.data('lv', true);
        }
        function bddhide( $ft ){
            $('.bdd-list', $ft).fadeTo( 200, 0.0, function(){ $(this).css('display', 'none'); });
            $ft.data('lv', false);
        }

        $(document).click( function() {
            $('.bdd').each( function() { bddhide( $(this) ); } );
        });


        $('.bdd').each( function() {

            var $t         = $(this);
            var $dd_list = $('.bdd-list li', $t);

            $t.data('lv', false); // List Visible

            function setText( text ){
                $('.bdd-dropbox span', $t).html( text );
            }

            $dd_list
                .mouseenter( function() {
                    
                    if( $(this).attr('title') ){    // On first mouseover, store the title in data and remove it from attr. (suppresses the "title-text-box")
                        $(this).data('title', $(this).attr('title') );
                        $(this).attr('title','');
                    }

                })
                .hover( function() {
                    if( $(this).hasClass('bdd-noselect') ) return false;

                    $(this).addClass('bdd-item-hover');
                },
                function() {
                    $(this).removeClass('bdd-item-hover');
                })
                .click( function() {
                    if( $(this).hasClass('bdd-noselect') ) return false;
                    var cpy = $(this).clone();
                    var tmp = $('div', cpy).text();
                    if ( tmp.length > 20 ) {
                        tmp = tmp.substring( 0, 20 ) + '...';
                    }
                    $('div',cpy).text( tmp );
                    
                    setText( cpy.html() );
                    dropdownChanged( $t.attr('id'), $(this).data('title') );
                    bddhide( $t );
                });

            $('.bdd-dropdown', $t )
                .click( function(e) {
                    if($t.data('lv')){
                        bddhide( $t );
                    }else{
                        bddshow($t);
                        $('.bdd').not($t).each( function() { bddhide( $(this) ) } );
                    }
                    e.stopPropagation();
                    e.preventDefault();

                    return false;
                });
        });

    });

}

function CloseNotifybox( id ) {
    $('#'+id).hide();
    $('#bewBlameText').val('');
    $('#bewBlameStatus').hide();
}

function bindCommonHandlers() {

    $('.bewEntryHead').disableTextSelect();

    $('.bew_paging')
        .click( function( e ) {
            
            var page = $(this).attr('id').substr( 'bew_paging_'.length );
            loadpartial( page );

            e.preventDefault();

            return false;
        });

    $('.bewMoreLink') 
        .unbind('click')
        .bind( 'click', function() {
            if ( $( '.bewEntryBodyNotShow',$(this).parent() ).css( 'display' ) == 'none' ) {
                $( '.bewEntryBodyNotShow',$(this).parent() ).show();
                $( this ).hide();
                $( '.bewLess', $(this).parent() ).show();
                $(this).siblings('.bewEntryBodyShowPoints').hide();
            } else {
                $( '.bewEntryBodyNotShow',$(this).parent() ).hide();
                $( this ).hide();
                $( '.bewMore', $(this).parent() ).show();
                $(this).siblings('.bewEntryBodyShowPoints').show();
            }
            
            return false;
        });
        
    $('.bewEntryFootHelpBlame')
        .unbind( 'mouseenter mouseleave click' )
        .bind( 'mouseenter', function() {
            $(this).css( { 'background-position': '-100px -90px' } );
        })
        .bind( 'mouseleave', function() {
            $(this).css( { 'background-position': '-80px -90px' } );
        })
        .click( function() {
            $b = $(this);
            $(this).mouseout();
            $('#unzumutbarbox')
                .unbind( 'click' )
                .css({ 
//                        'top': ( $(this).offset().top - ( $('#unzumutbarbox').height() / 2 ) ),
                        'top': ( $(this).offset().top + $(this).height() ),
                        'left': ( $(this).offset().left - ( $('#unzumutbarbox').width() / 2 ) )
                    })
                .show();
                
            $('#unzumutbarbox input').unbind('click');
            
            $('#unzumutbarbox input#send')
                .click( function() {
                    $h = $('#unzumutbarbox');
                    if ( $('#bewBlameText').val().length == 0 ) {
                        return $('#bewBlameStatus').html( bewBlameNoText ).fadeIn( 'def' ).oneTime( 2000, function() { $(this).fadeOut(300); });
                    }

                    var rateid = 0;
                    var rateid_type = '';
                    var blame_text = $('#bewBlameText').val();
                    var t = $b.parents('.bewEntry').attr('rel').split('_');

                    rateid = t[2];
                    rateid_type = t[1];

                    var data = { ajax_type: 'blame', blame_text: blame_text, rateid: rateid, rateid_type: rateid_type, sid: jsNCTrackingSID };
                    $.post('prod_prodrateajax.html', data, function( res ) { 
                        if ( res == 1 ) {
                            $('#bewBlameStatus').html( bewBlameNoLogin ).fadeIn( 'def' ).oneTime( 2000, function() { $(this).fadeOut(300); });
                        }
                        if ( res == 2 ) {
                            $('#bewBlameStatus').html( bewBlameOk ).fadeIn( 'def' ).oneTime( 2000, function() {
                                $h.fadeOut(300);
                                $('#bewBlameText').val('');
                                $(this).hide();
                            });
                        }
                        if ( res == 3 ) {
                            $('#bewBlameStatus').html( bewBlameNot ).fadeIn( 'def' ).oneTime( 2000, function() { $(this).fadeOut(300); });
                        }
                    });
                });
            
            return false;
        });


    $('.bewParticipation')
        .unbind( 'click' )
        .bind( 'click', function() {
            var type = $(this).attr('rel');
            var rateid = 0;
            var rateid_type = '';
            
            var t = $(this).parents('.bewEntry').attr('rel').split('_');
            rateid = t[2];
            rateid_type = t[1];

            var $t = $(this);
            var data = { ajax_type: type, rateid: rateid, rateid_type: rateid_type, sid: jsNCTrackingSID };
            
             if ( !$(this).hasClass('clickedHighlightClass') ) {
    
                if( $(this).data('ajax_in_progress') ){
                    return false;
                }

                var $bobj = $(this).data('ajax_in_progress', true);
                try { pageTracker._trackPageview("/ajaxCallBewRate" ); } catch(e) {}

                $.post('prod_prodrateajax.html', data, function( res ) { 

                    $bobj.data('ajax_in_progress', false);

                    //using that awsum #bewHelp container for showing sum information to the user.
                    if ( res == 1 ) {
                        $t.addClass('clickedErrorClass').oneTime( 1000, function() {
                            $t.removeClass('clickedErrorClass');
                            $(this).removeClass('clickedHighlightClass'); 
                        });
                    }
                    if ( res == 2 ) {
                        $t.addClass('clickedHighlightClass');
                    }
                    if ( res == 3 ) document.location.href = 'mythomann_prodrate.html?ratenr='+bew_artnr;
                }, 'html' );
             }

             if ( $(this).siblings().hasClass('clickedHighlightClass') ) {
                $(this).siblings().removeClass('clickedHighlightClass');
             }

            return false;
        });

    $('.bewEntryHeadMa')
        .click( function() {
             var $o = $(this).offset();
             var $MaBtnW = $('.bewEntryHeadMa').width()/2;
             var $thoBoxW = $('#thoteambox').width()/2;
             $('#thoteambox').css( { 'top': $o.top + $(this).height(), 'left': $o.left + $MaBtnW - $thoBoxW} ).show();
        });
        
    $('#bew_ov_content .bewEntry .bewEntryHead')
        .click( function() {
            if ( bewDetailState == 'detailed' ) return; //nur im compactmodus brauchen wir irgendwelche clickgeschichten
            
            $this = $(this);
            $cont = $('#bew_ov_wrapper');

            //gibts eine schon offene bewetung?
            if ( $('body').data('open') ) {
                //klick auf die schon offene bewertung
                if ( $this[0] == $('body').data('open') ) {
                    triggerBEWdetails( 'hide', $this.parent() );
                    $this.find('.bewEntryBigButton').removeClass('bewEntryBigButtonMinus');
                                        
                    $('body').data( 'open', '' );
                    return false;
                } else {
                    //pfeil umschalten -> bigbutton
                    triggerBEWdetails( 'hide', $( $('body').data('open') ).parent() ); //andere schon offene bewertung zu machen
                    $( $('body').data('open') ).parent().find('.bewEntryBigButton').removeClass('bewEntryBigButtonMinus');
                }
            }
            //klick auf eine bewertung die nicht schon offen ist, diese bewertung auf, aber nicht die in der mutterseite
            triggerBEWdetails( 'show', $this.parent() );
            $this.find('.bewEntryBigButton').addClass('bewEntryBigButtonMinus');
            
            var o = 0;
            if ( $this.offset().top < $cont.offset().top || $this.parent().height() > $cont.height() )  { // head hängt übern oberen rand raus
                $cont.scrollTo( $this, 800, { offset: -10 } );
            } else if ( ( o = ( $this.offset().top + $this.parent().height() ) - ( $cont.offset().top + $cont.height() ) ) > 0 ) { // head hängt über unteren rand raus
                o = o + 15;
                $cont.scrollTo( '+=' + o + 'px', 800 );
            }

            $('body').data( 'open', $this[0] );
        });
}

var shareProvider = {
    'facebook': 'http://www.facebook.com/share.php?u=%SHARE_URL%',
    'twitter': 'http://twitter.com/share?url=%SHARE_URL%&text=%SHARE_DESC%',
    'meinvz': 'http://www.meinvz.net/Suggest/Selection/?u=%SHARE_URL%&desc=%SHARE_DESC%',
    'digg': 'http://digg.com/submit?url=%SHARE_URL%&title=%SHARE_DESC%&bodytext=',
    'google': 'http://www.google.com/bookmarks/mark?op=add&bkmk=%SHARE_URL%&title=%SHARE_DESC%',
    'misterwong': 'http://www.mister-wong.com/index.php?action=addurl&bm_url=%SHARE_URL%&bm_description=%SHARE_DESC%&bm_notice=',
    'myspace': 'http://www.myspace.com/Modules/PostTo/Pages/?u=%SHARE_URL%',
    'delicious': 'http://del.icio.us/post?url=%SHARE_URL%&title=%SHARE_DESC%&notes=',
    'blogger': 'http://www.blogger.com/blog_this.pyra?u=%SHARE_URL%&n=%SHARE_DESC%',
    'linkedin': 'http://www.linkedin.com/shareArticle?mini=true&url=%SHARE_URL%&title=%SHARE_DESC%&summary=%SHARE_DESC%&source=thomann.de',
    'hyves': 'http://hyves-share.nl/button/tip/?tipcategoryid=12&rating=5&title=%SHARE_DESC%&body=%SHARE_URL%',
    'bebo': 'http://www.bebo.com/c/share?Url=%SHARE_URL%&Title=%SHARE_DESC%',
    'mailto': 'mailto:?subject=%SHARE_DESC%&body=%SHARE_URL%',
    'favorite': true
};

$(function() {

    var share_url  = window.globals.share_url;
    var share_desc = window.globals.share_desc;

    if( share_url ) {

        var $prod_social = $('#prod-social');

        $prod_social.bind('clickoutside', function(e){
            var $this = $(this);
            if( e.target.id != 'prod-social-share' && $this.is(':visible') && !$this.is(':animated') ) {
                $this.toggle(400);
            }
        });

        $('#prod-social-share').click( function() {
            $prod_social.toggle(400);
        });

        $('#social-favorite', $prod_social).click( function() {
            if(window.sidebar){ // Firefox
                window.sidebar.addPanel(share_desc, share_url,'');
            } else if(document.all){ //IE
                window.external.AddFavorite(share_url, share_desc);
            }   
        });

        $('textarea, input',$prod_social).click( function() {
            $(this).select();
        } );
        $('textarea, input',$prod_social).bind( 'copy', function(e) {
            e.stopPropagation();
        } );
    
        $('li.social-link', $prod_social).click( function() {
    
            try { pageTracker._trackPageview("/socialBookmarking" ); } catch(e) {}
        
            var $this = $(this);
            var id    = $this.attr('id');

            var m = id.match(/social-(.*)/);

            if( m && m[1] ) {
        
                var provider = m[1];
                if( shareProvider[ provider ] != undefined ) {

                    var url = shareProvider[ provider ];
                    
                    url = url.replace('%SHARE_URL%', encodeURIComponent(share_url) );
                    url = url.replace('%SHARE_DESC%', encodeURIComponent(share_desc) );

                    var _win =  window.open(url, provider,'toolbar=no,width=600,height=550,status=no,scrollbars=yes,resizable=yes,menubar=no,,screenx=0,screeny=0');

                    if( provider == 'mailto' ) {
                        if (_win && _win.open && !_win.closed) _win.close();
                    }
                }
            }
        
        });
    }
});

