﻿function openPopup(mylink, windowname)
{
    window.open(mylink, windowname.toString().replace(' ', ''), 'width=400,height=350,scrollbars=no');
   /* if (! window.focus)return true;
    var href;
    if (typeof(mylink) == 'string')
       href=mylink;
    else
       href=mylink.href;
    window.open(href, windowname, 'width=400,height=300,scrollbars=no',null);
    window.open('http://www.google.com/', 'TEST', 'width=400,height=300,scrollbars=no');
    return false;*/
};


$(function () {
    $('#signInTwitter').mousedown(function () { $(this).toggleClass('signinbuttonclick') });
    $('#signInTwitter').mouseup(function () { $(this).toggleClass('signinbuttonclick') });
    $('#signInTwitter').hover(function () { $(this).toggleClass('signinbuttonhover') }, function () { $(this).toggleClass('signinbuttonhover') });

    $('#signInFacebook').mousedown(function () { $(this).toggleClass('signinbuttonclick') });
    $('#signInFacebook').mouseup(function () { $(this).toggleClass('signinbuttonclick') });
    $('#signInFacebook').hover(function () { $(this).toggleClass('signinbuttonhover') }, function () { $(this).toggleClass('signinbuttonhover') });
    $('#signInFacebook').mousedown(function () { $(this).toggleClass('signinbuttonclick') });
    $('#signInFacebook').mouseup(function () { $(this).toggleClass('signinbuttonclick') });
    $('#signInFacebook').hover(function () { $(this).toggleClass('signinbuttonhover') }, function () { $(this).toggleClass('signinbuttonhover') });

    if (window.location.hash != null && window.location.hash != "" && window.location.hash != "#") {
        var loc = window.location + "";
        var url = loc.split('#')[0];
        var token = loc.split('#')[1].split('&')[0].split('=')[1];
        window.location = url + "?access_token=" + token;
    }

    if (window.location.hash != null && window.location.hash != "" && window.location.hash != "#") {
        var loc = window.location + "";
        var url = loc.split('#')[0];
        var token = loc.split('#')[1].split('&')[0].split('=')[1];
        window.location = url + "?access_token=" + token;
    }
    playFirstTrack();
    playFirstBand();
    playNewBand();
    playPrehome();


});

function LoadWall(url) {
 $.getJSON(url,function(json) {
    var html = "<ul>";
        
    //loop through and within data array's retrieve the message variable.
    $.each(json.data,function(i,fb)
    {
        if (fb.message == undefined)
        {
            if (fb.picture != undefined)
            {
                html += "<li><span class=\"fromName\">" + fb.from.name + "</span><br />" + fb.name + "<br /><a href=\"" + fb.link + "\"><img src=\"" +  fb.picture + "\" /></a></li>";
            }
        }
        else
        {
            if (fb.picture != undefined)
            {
                html += "<li><span class=\"fromName\">" + fb.from.name + "</span><br />" + fb.name + "<br /><a href=\"" + fb.link + "\"><img src=\"" +  fb.picture + "\" /></a></li>";
            }
            
            html += "<li><span class='fromName'>" + fb.from.name + "</span>&nbsp;" +  fb.message + "</li>";
        }
     });
        html += "</ul>";
        $('.facebookfeed').html(html);
    });
};

function Count(clientId)
{ 
    var txtInput = $('#' + clientId); 
    var labelCount = $('.lbCount'); 
    labelCount.html(140 - txtInput.text().length); 
} 

function playFirstTrack()
{
    if($('div.datoPrimerTema').length > 1)
    {
        var url1 = $('div.datoPrimerTema').html();  
        var url2 = $('div.datoPrimerTema:nth-child(2)').html();

        playDestacados(url1, url2, 'mediaspace', '718', '403', 0, true, '#wrapTemasPlaylist div',true, false);
    }
 }
 
 
 function playFirstBand()
{
    if($('div.datoPrimerBanda').length > 1)
    {
        var url1 = $('div.datoPrimerBanda').html();  
        var url2 = $('div.datoPrimerBanda:nth-child(2)').html();
        var index = $('div.datoPrimerBanda:nth-child(3)').html();

        playDestacados(url1, url2, 'mediaspace', '251', '23', index, true, '#wrapTemasPlaylist div', false, false);
    }
 }
 
  function playNewBand()
{
    if($('div.datoNuevaBanda').length > 1)
    {
        var url1 = $('div.datoNuevaBanda').html();  
        var url2 = $('div.datoNuevaBanda:nth-child(2)').html();
		
        play(url1, url2, 'video', '430', '287');
    }
}

function playPrehome() {
    if ($('div.datoPrehome').length > 0) {
        var url1 = $('div.datoPrehome').html();

        play(url1, '', 'mediaspace', '462', '386');
    }
}

function playFirstDescarga() {
    if ($('div.datoPrimerDescarga').length > 1) {
        var es = $('div.datoPrimerDescarga').html();
        if (es == '1')
        {
            var url1 = $('div.datoPrimerDescarga:nth-child(2)').html();
            var url2 = $('div.datoPrimerDescarga:nth-child(3)').html();
            var index = $('div.datoPrimerDescarga:nth-child(4)').html();

            playDestacados(url1, url2, 'mediaspace', '251', '23', index, true, '#wrapTemasPlaylist div', false, false);
        }
    }
}
 
 

