//document.domain="thegoldmusic.com";

/* Current Wirefeed being display */

var img = new Array();
var l = new Array();
var t = new Array();
var a = new Array();

var cn = new Array();
var cl = new Array();

var stageImages = new Array();

var path = '?';
var movieSrc = "publicidad/flash/banner3_300x250.swf";
var movieWidth = "494";
var movieHeight = "216";
var altImgSrc = '';
var altLinkURL = '';
var windowMode = "opaque";

var itemTotal = 0;
var itemCounter = 0;
var currentItem = 0;
var currentColor = 0;
var newsInterval = 5000;
var firstItemInnerHTML = '';

/* Multimedia tab selection */
var mult = '';
var cTab = '';

/* Stage rotation */
var currentStage = 0;
var rotateTime = 5000;
var timeoutId = null;

// load events
function loadEvents()
{
    //loadAd();
    //timeoutId = setTimeout( 'rotateStage();', rotateTime );
    x2 =  document.getElementById( 'fe' );
    y2 = x2.getElementsByTagName( 'li' );
    itemTotal = y2.length;
    itemCounter = 0;
    currentItem = 0; 
    firstItemInnerHTML = y2[0].innerHTML;
    setTimeout('cAlpha( 0 );', newsInterval );
}

// load Ad still on alpha
function loadAd(){
    var oScript = document.createElement("script");
    oScript.setAttribute("src",'http://www.thegoldmusic.com');
    document.getElementById('ad').appendChild( oScript );
}

// news ticker rotation
function rotateW()
{
    if (currentItem < itemTotal-1 ) currentItem++;
    else currentItem = 0;
    x = document.getElementById( 'fe' );
    y = x.getElementsByTagName( 'li' );
    if (currentItem == 0) y[ 0 ].innerHTML = firstItemInnerHTML;
    else y[ 0 ].innerHTML = y[ currentItem ].innerHTML;
    cAlpha( 1 );
}

// alpha fading and out for news ticker
function cAlpha( dir )
{
    var cArray = new Array ( '#3B3B3B', '#3B3B3B', '#3B3B3B', '#B5D4EB', '#FFF' );
    x = document.getElementById( 'fe' );
    y = x.getElementsByTagName( 'li' );
    a = y[0].getElementsByTagName( 'a' );
    if ( ( dir == 0 ) && ( currentColor < cArray.length ) )
    {
        a[0].style.color = cArray[ currentColor++ ];
        setTimeout( 'cAlpha( 0 );', 75 );
        
    }
    else if ( ( dir == 1 ) && ( currentColor >= 0 ) )
    {
        a[0].style.color = cArray[ currentColor-- ];
        setTimeout( 'cAlpha( 1 );' , 75 );
    }
    else
    {
        if (dir == 1){    
            currentColor = 0;
            setTimeout( 'cAlpha( 0 );', newsInterval );
        }
        else{
            currentColor = 4;
            rotateW();
        }
    }
}
// Open photo album popup
function openPhotoAlbum(albumid)
{
    var ourl = '/content/photoalbum4.jhtml?chid=' + chid + '&schid=' + schid + '&secid=' + secid + '&cid=' + albumid;
    if(schid!=null && schid==11529)
       window.open(ourl,'photopopup','left=3, top=3, screenx=3, screeny=3, scrollbars=no, width=770, height=600');
    else
       window.open(ourl,'photopopup','left=3, top=3, screenx=3, screeny=3, scrollbars=no, width=770, height=585');
    return false;
}

// Open video player popup
function openVideoLink(cid)
{
    if (vidcr == 'US') {
            var ourl = '/rdt.dyn?trt=503&rid=' + cid + '&requrl=/content/videoplayer.jhtml?cid=' + cid;
            location.href = ourl;
        }
        else {
            var child;
            if (child != undefined) {child.close; } 
            var left = 3; 
            var top = 0;
            var width = 786;
            var height = 593;
            var ourl = 'http://www.thegoldmusic.com/rdt.dyn?trt=503&rid=' + cid + '&requrl=http://www.thegoldmusic.com/content/video.jhtml?cid=' + cid;
            if ( navigator.appName.indexOf('Microsoft') != -1 )
            {
        left = window.screenLeft + ( window.document.body.clientWidth/2 - width/2 );
        top = 0;
            }
            else
            {
        left = window.screenX + ( window.outerWidth/2 - width/2 );
        top =  0;
            } /* endif */
            child = window.open(ourl,'videopopup','left=' + left + ',top=' + top + ',screenx=' + left + ',screeny=' + top + ',scrollbars=yes,width=' + width + ',height=' + height);        
        }
}
function loadFlashStage()
{
}
function resizeHeaderComponents()
{
}

function resizeBuscar(minWidth,curWidth)
{
}

function resizeIconDiv(minWidth,curWidth)
{
}

function setChannelLinkPadding(minWidth,curWidth)
{
}

function getElementsByClassName(oElm, strTagName, oClassNames){
            var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
            var arrReturnElements = new Array();
            var arrRegExpClassNames = new Array();
            if(typeof oClassNames == "object"){
                        for(var i=0; i<oClassNames.length; i++){
                                    arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames[i].replace(/\-/g, "\\-") + "(\\s|$)"));
                        }
            }
            else{
                        arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames.replace(/\-/g, "\\-") + "(\\s|$)"));
            }
            var oElement;
            var bMatchesAll;
            for(var j=0; j<arrElements.length; j++){
                        oElement = arrElements[j];
                        bMatchesAll = true;
                        for(var k=0; k<arrRegExpClassNames.length; k++){
                                    if(!arrRegExpClassNames[k].test(oElement.className)){
                                                bMatchesAll = false;
                                                break;
                                    }
                        }
                        if(bMatchesAll){
                                    arrReturnElements.push(oElement);
                        }
            }
            return (arrReturnElements)
}
if(typeof Array.prototype.push != "function"){
            Array.prototype.push = ArrayPush;
            function ArrayPush(value){
                        this[this.length] = value;
            }
}


             months = new Array(13);
             months[0] = 'enero';
             months[1] = 'febrero';
             months[2] = 'marzo';
             months[3] = 'abril';
             months[4] = 'mayo';
             months[5] = 'junio';
             months[6] = 'julio';
             months[7] = 'agosto';
             months[8] = 'septiembre';
             months[9] = 'octubre';
             months[10] = 'noviembre';
             months[11] = 'diciembre';
             today = new Date();
             tmonth = months[today.getMonth()];
             tdate = today.getDate();
             tyear = today.getYear();
             if (tyear <= 199) {
             tyear +=1900
             }
             
function setDates() {
            var tdates = getElementsByClassName(document,'*','tdate');
            for (x=0; x<tdates.length; x++) { tdates[x].innerHTML = tdate + ' '; }
            var tmonths = getElementsByClassName(document,'*','tmonth');
            for (y=0; y<tmonths.length; y++) { tmonths[y].innerHTML = tmonth + ' '; }
            var tyears = getElementsByClassName(document,'*','tyear');
            for (z=0; z<tyears.length; z++) { tyears[z].innerHTML = tyear + ' '; }
}

function lang(en, es) {
    //default output (using english text)
    var def = en; 

    //If b_language has not been defined, assign default value
    if (typeof b_language == 'undefined') {
        document.write(def)
    } else {
        var b_lang = b_language.toLowerCase();
        if (b_lang.substring(0,2) == 'es') {
            //spanish
            document.write(es);
        } else if (b_lang.substring(0,2) == 'en') {
            //english
            document.write(en);
        } else {
            //default
            document.write(def);
        }
    }
}

/**
 * New modules for 2009
 */
(function($){
    $.fn.searchWidget = function(params){
        var params = $.extend({
            wrapperId: 'search',
            hotLinks: []
        }, params);
        
        var jTabs = $('#'+params.wrapperId+' .search_tabs li');
        var jForm = $('#'+params.wrapperId+' form');
        var jSearchInput = $('#'+params.wrapperId+' .search_input_val');
        var jSubmitBuscar = $('#'+params.wrapperId+' .search_input_btn.buscar');
        var jSubmitUniclave = $('#'+params.wrapperId+' .search_input_btn.uniclave');
        var jLinks = $('#'+params.wrapperId+' .search_links ul li');
        
        // reset the form
        jForm[0].reset();
        
        // tabs behavior
        jTabs.each(function(){
            
            $(this).click(function(){
                jTabs.each(function(){
                    $(this).removeClass("active");
                });
                $(this).addClass("active");
                
                // select radio
                $(this).find('input').attr('checked', true);
                
                // hide uniclave if not thegoldmusic.com or internet
                if( jForm.find('#search_type_internet').attr('checked')
                    || jForm.find('#search_type_site').attr('checked') ) {
                    jSearchInput.removeClass('search_input_val_extended');
                    jSubmitUniclave.show();
                    $('#'+params.wrapperId+' .search_input').find('span').show();
                } else {
                    jSubmitUniclave.hide();
                    $('#'+params.wrapperId+' .search_input').find('span').hide();
                    jSearchInput.addClass('search_input_val_extended');
                }
                
                // Submit form if something in text field
                if( jQuery.trim( jSearchInput.attr('value') ) != '' ) {
                    execSubmit();
                } // Submit for if video tab checked http://www.thegoldmusic.com/content/channel.jhtml?chid=1964
                else if( jForm.find('#search_type_video').attr('checked') ){
                    location.href = 'videos.asp';
                    return false;
                }
                jSearchInput.focus();
                return false;
            });
        });
        
        // Popular links behavior
        jLinks.each(function(){
            $(this).click(function(){
                jSearchInput.attr( 'value', $(this).find('a').attr('alt') );
                jForm.find('#is_clicked_link').val('yes');
                execSubmit();
            });
        });

        
        jSubmitBuscar.click(function (){
            execSubmit();
        });
        
        jSearchInput.keypress(function (e){
            if(e.keyCode == 13) {
                execSubmit();
                return false;
            }
        });
        
        jSubmitUniclave.click(function () {
            jForm.find('#search_type_uniclave').attr('checked', true);
            execSubmit();
        });
        
        function execSubmit() {
			
			if( jForm.find('#search_type_site').attr('checked') ) {
                location.href = 'DESCARGAS.ASP?search_type=temamusical&query=' + encodeURIComponent( jSearchInput.attr('value') );
                return false;
            }
			
            if( jForm.find('#search_type_compras').attr('checked') ) {
                location.href = 'http://comparaprecios.thegoldmusic.com/search.phpuuuu?Search=Buscar&topcat_id=&form_keyword=' + encodeURIComponent( jSearchInput.attr('value') );
                return false;
            }
            if( jForm.find('#search_type_foros').attr('checked') ) {
                location.href = '/buscar/buscar_resultados.jhtml?base=0&locale=0&pgsz=10&schid=12&type=basic&search_type=foros&query=' + encodeURIComponent( jSearchInput.attr('value') ) + '&gooch=foros&goosite=http://foro.thegoldmusic.com';
                return false;
            }
            if( jForm.find('#search_type_video').attr('checked') ) {
                location.href = '/video/buscar.jhtml?query=' + encodeURIComponent( jSearchInput.attr('value') );
                return false;
            }
            jForm[0].submit();
        }

    };
})(jQuery);



// build hot links
function writePopularSearchLinks( randArLinks ) {
    if( randArLinks.length > 0 ) {
        var arLinkObjs = randArLinks[Math.floor( Math.random() * randArLinks.length )];
        for( var i=0; i<arLinkObjs.length; i++ )
            document.write('<li'+ ((i==0)? ' class="f"' : '') +'><a href="javascript:void(0);" alt="'+ arLinkObjs[i].searchStr +'">'+ arLinkObjs[i].dispName +'</a></li>');
    }
}

// write featured show
function writeFeaturedShow( randArShows ) {
    if( randArShows.length > 0 ) {
        var showObj = randArShows[Math.floor( Math.random() * randArShows.length )];
        document.write('<a class="x bttm" href="'+ showObj.url +'">'+ showObj.title +'<img src="'+ showObj.imgUrl +'" alt=""></a><p>'+ showObj.description +'</p>');
    }
}

function printDate(){
    months = new Array(13);
    months[0] = 'Enero';   
    months[1] = 'Febrero'; 
    months[2] = 'Marzo';   
    months[3] = 'Abril';   
    months[4] = 'Mayo';    
    months[5] = 'Junio';   
    months[6] = 'Julio';   
    months[7] = 'Agosto';  
    months[8] = 'Septiembre';
    months[9] = 'Octubre';   
    months[10] = 'Noviembre';
    months[11] = 'Diciembre';
    today = new Date();      
    tmonth = months[today.getMonth()];
    tdate = today.getDate();          
    tyear = today.getYear();          
    if (tyear <= 199) {               
        tyear +=1900;                 
    }                                 
    document.write(tdate + " " + tmonth + " " + tyear);
} 

// On dom ready
$(function(){
    var mouseIsOverShowsYTele = false;
    $("#shows_tele_title").mouseover(function() {
        if( $('#shows_tele_popup').css('display') == 'none' ){            
            var winHeight  = $(window).height();
            var elDistFromTop = $('#mo_television').position().top + 40;
            var elHeight = $('#shows_tele_popup').height();
            var elBottomDistFromTop = elDistFromTop + elHeight;            
            if( (elBottomDistFromTop - $(window).scrollTop()) > winHeight ) {
                var offsetHeight = elDistFromTop;
                if( winHeight > elHeight )
                    offsetHeight = elBottomDistFromTop - winHeight;
                $.scrollTo( '#w', 800, {offset:offsetHeight} );
            }
            $('#shows_tele_popup').fadeIn();
        }
    });
    /*$("#shows_tele_title").mouseleave(function() {
        var fadeDelayed = function(){ if( !mouseIsOverShowsYTele ) $('#shows_tele_popup').fadeOut(); };
        setTimeout( fadeDelayed, 500);
        mouseIsOverShowsYTele = false;
        
    });*/
    $("#shows_tele_popup").mouseenter(function() {
        mouseIsOverShowsYTele = true;
    });
    $("#shows_tele_popup").mouseleave(function() {
        mouseIsOverShowsYTele = false;
        var fadeDelayed = function(){ if( !mouseIsOverShowsYTele ) { $('#shows_tele_popup').fadeOut(); } };
        setTimeout( fadeDelayed, 1500);
    });
    $("#shows_tele_close").click(function() {
        mouseIsOverShowsYTele = false;
        $('#shows_tele_popup').fadeOut();
    });
    
    $("#moreCitiesLink").click(function() {
        if( $('#moreCities').css('display') == 'none' ){
            $(this).addClass('less');
            $('#showcaseCities').slideUp('slow');
            $('#moreCities').slideDown('slow');
        } else {
            $(this).removeClass('less');            
            $('#moreCities').slideUp('slow');
            $('#showcaseCities').slideDown('slow');
        }
    });
    
    $('#header_content2 .search_input_val').focus();
    
});

/*
 *    thegoldmusic Customizable Links Widget 1.0
 *
 *    author: Luciano Araujo <laraujo@us.thegoldmusic.com>
 *    description: The Customizable Links Widget allows the user
 *    to arrange some pre-defined external or internal links.
 *
 *    Built with jQuery library
 *    http://jquery.com
 *
 */

CLW = {

    /**
     * Property: params
     * {object Array} the customizable parameters passed into the widget
     */
    params: { renderTo: 'custLinksWidget',      // div ID to render the CWL to
              arLinks:  []                      // an array of link objects to be displayed
            },
    
    /**
     * Property: hideShowPnlDivId
     * {String} the id of the div that controls the open and close of the edit panel
     */
    hideShowPnlDivId: 'hideShowCLWPnl',
    
    /**
     * Property: carouselDivName
     * {String} the name of the div that wraps the carousel
     */
    carouselDivName:'clwCarouselDiv',
    
    /**
     * Property: carouselUlName
     * {String} the name of the ul that wraps the carousel items
     */
    carouselUlName:'clwCarouselUl',
    
    /**
     * Property: userOrder
     * {Array} an array of link IDs ordered by the user's preference
     */
    userOrder: null,
    
    /**
     * Property: cookieName
     * {String} the name of the cookie where the link order is saved
     */
    cookieName: 'thegoldmusicCLWOrder',
    
    /**
     * Property: imagePath
     * {String} the url path of where the icon images reside
     */
    imagePath: 'publicidad/lotuyo/',

    /**
     * Property: cookieOptions
     * {Obj} holds some setting options for the cookie
     */
    cookieOptions: { path: '/', expires: 365 },
    
    /**
     * Property: mouseOverSortPnl
     * {Boolean} Flag that holds weather the user mouse if over the sorting panel.
     */
    mouseOverSortPnl: false,
    
    /**
     * Method: initialize
     * Parameters:
     * params - {Object}
     *
     */
    initializeObj: function( params ) {
        this.params = $.extend( this.params, params);
        
        this.loadLinksOrder();
        this.writeInitialMarkup();
        this.drawCarousel(true);
        this.drawSortable();
    },
    
    /**
     * Method: loadLinksOrder
     * Parameters: none
     */
    loadLinksOrder: function(){
        var cookieVal = $.cookie(this.cookieName);
        if( cookieVal != null ) {
            this.userOrder = cookieVal.split(',');
            this.sanitizeUserOrder();
        }
        else {
            this.userOrder = Array();
            for( var i=0; i<this.params.arLinks.length; i++ )
                this.userOrder.push( this.params.arLinks[i].id );
        }
    },
    
    /**
     * Method: sanitizeUserOrder
     * Parameters: none
     */
    sanitizeUserOrder: function(){
        var sanitizedUserOrder = Array();
        for( var i=0; i<this.userOrder.length; i++ ) {
            linkObj = this.getLinkObjById( this.userOrder[i] );
            if( linkObj != null )
                sanitizedUserOrder.push( linkObj.id );
        }
        for( var j=0; j<this.params.arLinks.length; j++ ) {
            if( !this.isInArray( this.params.arLinks[j].id, sanitizedUserOrder ) )
                sanitizedUserOrder.push( this.params.arLinks[j].id );
        }
        this.userOrder = sanitizedUserOrder;
    },
    
    /**
     * Method: isInArray     
     */
    isInArray: function( value, array ){
        for( var i=0; i<array.length; i++ ) {
            if( array[i] == value )
                return true;
        }
        return false;
    },
    
    /**
     * Method: saveLinksOrder
     * Parameters: none
     */
    saveLinksOrder: function(){
        var arNewOrder = Array();
        var arLis = $('.sortableLinkLiItems');
        for( var i=0; i<arLis.length; i++ ) {
            arNewOrder.push( arLis[i].id );
        }
        this.userOrder = arNewOrder;
        $.cookie(this.cookieName, this.userOrder, this.cookieOptions);
    },
    
    /**
     * Method: writeInitialMarkup
     * Parameters: none
     */
    writeInitialMarkup: function(){
        // write the carousel div
        $('#'+this.params.renderTo).html('<div id="'+ this.carouselDivName +'" class="carousel portalExtLinksCarousel"><ul id="'+ this.carouselUlName +'"></ul></div>');
                
        // write sortable div
        var htmlMarkup = '';
        htmlMarkup += '<div id="linkSortingPanel" class="linkSortingPanel">';
        htmlMarkup += '<div class="linkSortingDesc"><h3>Organizar<img src="page_images/NOMETA_arrows.gif"></h3><p>Selecciona la orden de tus sitios arrastrando y soltando los iconos.</p></div>';
        // first column
        htmlMarkup += '<div class="linkSortingLabels">';
        for( var i=1; i<=(this.params.arLinks.length/2); i++ )
            htmlMarkup += '<div>'+i+'</div>';
        htmlMarkup += '</div>';
        htmlMarkup += '<ul id="linkSortingListOne" class="connectedLinkSortingList"></ul>';
        // second column
        htmlMarkup += '<div class="linkSortingLabels">';
        for( var j=(this.params.arLinks.length/2)+1; j<=this.params.arLinks.length; j++ )
            htmlMarkup += '<div>'+j+'</div>';
        htmlMarkup += '</div>';
        htmlMarkup += '<ul id="linkSortingListTwo" class="connectedLinkSortingList"></ul>';
        // end
        htmlMarkup += '<div style="clear:both;"></div><div id="linkSortingSave" class="linkSortingSave">&nbsp;</div></div>';
        $('#'+this.params.renderTo).after( htmlMarkup );
        
        var env = this;
        $("#linkSortingSave").click(function() {
            env.processSaveAction();
        });
        
        $('#'+this.hideShowPnlDivId).click( this.toggleSortingPanel );
        
        $('#linkSortingPanel').mouseleave(function() {
            var fadeDelayed = function(){ if( !env.getMouseOverSortPnl() && ($('#linkSortingPanel').css('display') != 'none') ) { env.toggleSortingPanel(); } return false; };
            setTimeout( fadeDelayed, 1500);
            env.setMouseOverSortPnl(false);
            return false;
        });
        $('#linkSortingPanel').mouseenter(function() {
            env.setMouseOverSortPnl(true);
            return false;
        });
    },
    
    getMouseOverSortPnl: function(){
        return this.mouseOverSortPnl;
    },
    
    setMouseOverSortPnl: function(flag){
        this.mouseOverSortPnl = flag;
    },
    
    /**
     * Method: drawCarousel
     * Parameters: none
     */
    drawCarousel: function(newCarousel){
        var ulElement = $('#'+this.carouselUlName);
        ulElement.empty();
        var ulContents = '';
        var linkObj = null;
        for( var i=0; i<this.userOrder.length; i++ ) {
            linkObj = this.getLinkObjById( this.userOrder[i] );
            if( linkObj != null ) {
                var arDispName = linkObj.data.name.split(' ');
                var dispName = linkObj.data.name;
                if( arDispName.length > 1 && arDispName[0].length > 2 ) dispName = dispName.replace( ' ', '<br />' );
                ulContents = ulContents + '<li id="'+ linkObj.id +'"><a href="'+ linkObj.data.url +'" target="_blank"><img src="'+ this.imagePath+linkObj.id+'_icon.gif" /><br />'+ dispName +'</a></li>';
            }
        }        
        ulElement.html(ulContents);
        if( newCarousel )
            $("div.portalExtLinksCarousel").carousel( { loop: true,
                                                        dispItems: 4,
                                                        nextBtn: "<div><div>&nbsp;</div></div>",
                                                        prevBtn: "<div><div>&nbsp;</div></div>" } );
        
    },
    
    /**
     * Method: drawSortable
     * Parameters: none
     */
    drawSortable: function(){
        var linkObj = null;
        // first list
        var ulElementOne = $('#linkSortingListOne');
        ulElementOne.empty();
        var ulContentsOne = '';        
        for( var i=0; i<(this.userOrder.length/2); i++ ) {
            linkObj = this.getLinkObjById( this.userOrder[i] );
            if( linkObj != null )
                ulContentsOne = ulContentsOne + '<li class="ui-state-default sortableLinkLiItems" id="'+ linkObj.id +'"><img src="'+ this.imagePath+linkObj.id+'_icon_sm.gif" /><span>'+ linkObj.data.name +'</span></li>';
        }        
        ulElementOne.html(ulContentsOne);
        // second list
        var ulElementTwo = $('#linkSortingListTwo');
        ulElementTwo.empty();
        var ulContentsTwo = '';        
        for( var j=(this.userOrder.length/2); j<this.userOrder.length; j++ ) {
            linkObj = this.getLinkObjById( this.userOrder[j] );
            if( linkObj != null )
                ulContentsTwo = ulContentsTwo + '<li class="ui-state-default sortableLinkLiItems" id="'+ linkObj.id +'"><img src="'+ this.imagePath+linkObj.id+'_icon_sm.gif" /><span>'+ linkObj.data.name +'</span></li>';
        }        
        ulElementTwo.html(ulContentsTwo);
        
        $("#linkSortingListOne, #linkSortingListTwo").sortable({
            connectWith: '.connectedLinkSortingList',
            placeholder: 'linkSortingPlaceholder'
        });
        
        // receive
        $('#linkSortingListOne').bind('sortreceive', function(event, ui){
            $("#linkSortingListOne li:last-child").prependTo("#linkSortingListTwo");
        });
        $('#linkSortingListTwo').bind('sortreceive', function(event, ui){
            $("#linkSortingListTwo li:first-child").appendTo("#linkSortingListOne");
        });
    },
    
    /**
     * Method: getLinkObjById
     * Parameters:
     * id - the ID of the link to retrieve the object
     */
    getLinkObjById: function(id){
        for( var i=0; i<this.params.arLinks.length; i++ ) {
            if( this.params.arLinks[i].id == id )
                return this.params.arLinks[i];
        }
        return null;
    },
    
    toggleSortingPanel: function(){
        if( $('#linkSortingPanel').css('display') == 'none' ){
            var winHeight  = $(window).height();
            var elDistFromTop = $('#mo_lotuyo').position().top + 40;
            var elHeight = $('#linkSortingPanel').height();
            var elBottomDistFromTop = elDistFromTop + elHeight;            
            if( (elBottomDistFromTop - $(window).scrollTop()) > winHeight ) {
                var offsetHeight = elDistFromTop;
                if( winHeight > elHeight )
                    offsetHeight = elBottomDistFromTop - winHeight;
                $.scrollTo( '#w', 800, {offset:offsetHeight} );
            }
            $('#linkSortingPanel').fadeIn();
            $('#hideShowCLWPnl').find('a').html('Cerrar');
            $('#hideShowCLWPnl').removeClass('editCLWBtn');
            $('#hideShowCLWPnl').addClass('closeCLWBtn');
        } else {
            $('#linkSortingPanel').fadeOut();
            $('#hideShowCLWPnl').find('a').html('Editar');
            $('#hideShowCLWPnl').removeClass('closeCLWBtn');
            $('#hideShowCLWPnl').addClass('editCLWBtn');
        }
    },
    
    /**
     * Method: processSaveAction
     * Parameters: none
     */
    processSaveAction: function(){
        this.saveLinksOrder();
        this.drawCarousel(false);
        this.toggleSortingPanel();
    }
};

;(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);
