
//var themePath = 'http://www.playamo.sk/themes/playamonew/images/';

function hideAllDetails()
{
    var t = document.getElementById( "top-stuff-details" );
    if ( !t ) return;
    e = t.getElementsByTagName("p");
    for( i = 0; i < e.length; i++ ) {
        if ( e[i].id.indexOf('more') != -1 ) {
            e[i].style.display = 'none';
        }
    }

    l = t.getElementsByTagName("a");
    for( i = 0; i < l.length; i++ ) {
        if ( l[i].className && l[i].className == 'close' )
            l[i].className = 'open';
    }
}

function showDetails(id, link)
{
    _showDetails(id, link, 'more');
}

function showDetails2(id, link)
{
    _showDetails(id, link, 'nmore');
}

function _showDetails(id, link, name)
{
    idName = name + id;
    info = document.getElementById( idName );
    if ( !info ) return;
    if ( !link.className ) return;
    //if ( !info.style.display ) return;
    if ( info.style.display == 'none' ) {
        info.style.display = 'block';
        link.className = 'close';
    }
    else {
        info.style.display = 'none';
        link.className = 'open';
    }
}

function commentStarHover( stars )
{
    for( i = 1; i <= stars; i++ ) {
        star = document.getElementById( 'star' + i );
        if ( !star ) continue;
        star.src = themePath + 'star_form_hover.gif';
    }
}

function commentStarClick( stars )
{
    for( i = 1; i <= 5; i++ ) {
        star = document.getElementById( 'star' + i );
        if ( !star ) continue;
        if ( i <= stars ) {
            star.src = themePath + 'star_form_hover.gif';
            star.className = 'on';
        }
        else {
            star.src = themePath + 'star_form.gif';
            star.className = 'off';
        }
    }

    form = document.getElementById( 'comment_form' );
    if ( !form ) return;
    form.comment_rating.value = stars;
}

function commentStarOut( stars )
{
    for( i = 1; i <= stars; i++ ) {
        star = document.getElementById( 'star' + i );
        if ( !star ) continue;
        if ( star.className == 'off' )
            star.src = themePath + 'star_form.gif';
    }
}

function switchSupportedPhones()
{
    div = document.getElementById( 'supported-info' );
    if ( !div ) return;
    if ( div.style.display == 'none' )
        div.style.display = 'block';
    else
        div.style.display = 'none';
}

function showPhoneSelect()
{
    d = document.getElementById('phone-switch-div');
    if ( !d ) return;

    if ( d.style.display == 'block' )
        d.style.display = 'none';
    else
        d.style.display = 'block';
}

function pickPhoneSelect(v,sel)
{
    //v = radio.value;
    if ( !v ) return;
    v = parseInt(v);
    f = document.getElementById('phone-switch-form');
    if ( !f ) return;
    s = f.phone_switch_type;
    if ( !s ) return;
    s.options.length = 1;
    s.disabled = false;
    if ( v == 0 ) {
        s.disabled = true;
        return;
    }
    //s.disabled = true;
    var list = devices[v];
    if ( !list ) return;
    selIndex = 0;
    a = 1;



    for( i = 0; i < list.length; i+=2 ) {
        s.options[(i/2)+1] = new Option(list[i+1],list[i]);

        if ( list[i] == sel ) selIndex = a;
        a++;
    }
    s.selectedIndex = selIndex;
    //s.disabled = false;
}

function pickSupportVendor(selectedPhone)
{
    f = document.getElementById( 'help_phones_ajax_form' );
    if ( !f ) return;
    v = f.help_phone_vendor;
    t = f.help_phone_type;
    if ( !t || !v ) return;
    vendorString = v.options[v.selectedIndex].value;

    i = vendorString.indexOf(":");
    vendorId = parseInt(vendorString.substring(0, i));

    t.options.length = 1;
    if ( vendorId == 0 ) {
        t.disabled = true;
        return;
    }

    var list = supportDevices[vendorId];
    if ( !list ) return;

    var cnt = 1;
    sel = 0;
    for(i=0;i<list.length;i+=3) {
        t.options[cnt] = new Option(list[i+1],list[i]+':'+list[i+2]+':'+list[i+1]);
        if ( list[i] == selectedPhone )
            sel = cnt;
        cnt++;
    }
    t.selectedIndex = sel;

    t.disabled = false;
}

function pickSupportPhone()
{
    f = document.getElementById( 'help_phones_ajax_form' );
    if ( !f ) return;
    v = f.help_phone_vendor;
    t = f.help_phone_type;
    if ( !t || !v ) return;
    typeId = t.options[t.selectedIndex].value;
    vendorString = v.options[v.selectedIndex].value;

    i = typeId.indexOf(":");
    support = -1;
    vendor = '';
    typ = '';
    if ( i != -1 ) {
        part = typeId.substring(i+1);
        ii = part.indexOf(":");
        support = parseInt(part.substring(0,ii));
        typ = part.substring(ii+1);

        x = vendorString.indexOf(":");
        vendor = vendorString.substring(x+1);
    }

    $('#span-yourphone').empty();
    $('#span-yourphone').append(vendor + " " + typ);

    i1 = document.getElementById( 'mono-img' );
    i2 = document.getElementById( 'poly-img' );
    i3 = document.getElementById( 'mp3-img' );
    p = document.getElementById( 'yourphone' );

    if ( !i1 || !i2 || !i3 || !p ) return;

    if ( support == -1 ) {
        p.style.display = 'none';
        return;
    }

    p.style.display = 'block';

    i2.src = themePath + ( support == 0 ? 'no.jpg' : 'yes.jpg' );
    i2.width = ( support == 0 ? 21 : 28 );
    i2.height = ( support == 0 ? 19 : 21 );

    i3.src = themePath + ( support == 2 ? 'yes.jpg' : 'no.jpg' );
    i3.width = ( support == 2 ? 28 : 21 );
    i3.height = ( support == 2 ? 21 : 19 );
}

function checkPhoneSwitchType()
{
    f = document.getElementById('phone-switch-form');
    if ( !f ) return false;
    s = f.phone_switch_type;
    t = f.phone_switch_vendor;
    if ( !s || !t ) return false;

    v = parseInt(s.options[s.selectedIndex].value);
    if ( !t[0].checked && !v ) return false;
    if ( !t[0].checked && v == 0 ) return false;
    return true;
}

function switchTopTab( num )
{
    tones = document.getElementById('top_stuff_tones');
    pics = document.getElementById('top_stuff_images');
    games = document.getElementById('top_stuff_games');

    tonesbut = document.getElementById('top_stuff_tones_button');
    picsbut = document.getElementById('top_stuff_images_button');
    gamesbut = document.getElementById('top_stuff_games_button');

    tonesall = document.getElementById('top_stuff_tones_all');
    picsall = document.getElementById('top_stuff_images_all');
    gamesall = document.getElementById('top_stuff_games_all');

    if ( !tones || !pics || !games ) return;
    if ( !tonesbut || !picsbut || !gamesbut ) return;
    if ( !tonesall || !picsall || !gamesall ) return;

    if ( num != 1 ) {
        tones.style.display = 'none';
        tonesbut.className = 'top-link top-zvonenia';
        tonesall.style.display = 'none';
    }
    else {
        tones.style.display = 'block';
        tonesbut.className = 'top-link top-zvonenia selected';
        tonesall.style.display = 'block';
    }

    if ( num != 2 ) {
        pics.style.display = 'none';
        picsbut.className = 'top-link top-obrazky';
        picsall.style.display = 'none';
    }
    else {
        pics.style.display = 'block';
        picsbut.className = 'top-link top-obrazky selected';
        picsall.style.display = 'block';
    }

    if ( num != 3 ) {
        games.style.display = 'none';
        gamesbut.className = 'top-link top-hry';
        gamesall.style.display = 'none';
    }
    else {
        games.style.display = 'block';
        gamesbut.className = 'top-link top-hry selected';
        gamesall.style.display = 'block';
    }
}

function switchNewestTab( num )
{
    tones = document.getElementById('newest_stuff_tones');
    pics = document.getElementById('newest_stuff_images');
    games = document.getElementById('newest_stuff_games');

    tonesbut = document.getElementById('newest_stuff_tones_button');
    picsbut = document.getElementById('newest_stuff_images_button');
    gamesbut = document.getElementById('newest_stuff_games_button');

    tonesall = document.getElementById('newest_stuff_tones_all');
    picsall = document.getElementById('newest_stuff_images_all');
    gamesall = document.getElementById('newest_stuff_games_all');

    if ( !tones || !pics || !games ) return;
    if ( !tonesbut || !picsbut || !gamesbut ) return;
    if ( !tonesall || !picsall || !gamesall ) return;

    if ( num != 1 ) {
        tones.style.display = 'none';
        tonesbut.className = 'newest-link newest-zvonenia';
        tonesall.style.display = 'none';
    }
    else {
        tones.style.display = 'block';
        tonesbut.className = 'newest-link newest-zvonenia selected';
        tonesall.style.display = 'block';
    }

    if ( num != 2 ) {
        pics.style.display = 'none';
        picsbut.className = 'newest-link newest-obrazky';
        picsall.style.display = 'none';
    }
    else {
        pics.style.display = 'block';
        picsbut.className = 'newest-link newest-obrazky selected';
        picsall.style.display = 'block';
    }

    if ( num != 3 ) {
        games.style.display = 'none';
        gamesbut.className = 'newest-link newest-hry';
        gamesall.style.display = 'none';
    }
    else {
        games.style.display = 'block';
        gamesbut.className = 'newest-link newest-hry selected';
        gamesall.style.display = 'block';
    }
}

function switchNewest2Tab( num )
{
    tones = document.getElementById('newest_stuff_animation');
    pics = document.getElementById('newest_stuff_video');

    tonesbut = document.getElementById('newest_stuff_animation_button');
    picsbut = document.getElementById('newest_stuff_video_button');

    tonesall = document.getElementById('newest_stuff_animation_all');
    picsall = document.getElementById('newest_stuff_video_all');

    if ( !tones || !pics ) return;
    if ( !tonesbut || !picsbut ) return;
    if ( !tonesall || !picsall ) return;

    if ( num != 1 ) {
        tones.style.display = 'none';
        tonesbut.className = 'top2-link top2-animacie';
        tonesall.style.display = 'none';
    }
    else {
        tones.style.display = 'block';
        tonesbut.className = 'top2-link top2-animacie selected';
        tonesall.style.display = 'block';
    }

    if ( num != 2 ) {
        pics.style.display = 'none';
        picsbut.className = 'top2-link top2-videa';
        picsall.style.display = 'none';
    }
    else {
        pics.style.display = 'block';
        picsbut.className = 'top2-link top2-videa selected';
        picsall.style.display = 'block';
    }
}

function pickBanner(num, order, id, url, cat)
{
    banner = document.getElementById('bannerimg');
    if ( !banner ) return;

    blink = document.getElementById('bannerlink');
    if ( !blink ) return;

    bzlava = document.getElementById('bannerzlava');

    img1 = document.getElementById('banner1');
    img2 = document.getElementById('banner2');
    img3 = document.getElementById('banner3');
    img4 = document.getElementById('banner4');
    img5 = document.getElementById('banner5');
    img6 = document.getElementById('banner6');

    if ( img1 && num == 1 && img1.className == 'selected1' )
        return;

    if ( img2 && num == 2 && img2.className == 'selected2' )
        return;

    if ( img3 && num == 3 && img3.className == 'selected3' )
        return;

    if ( img4 && num == 4 && img4.className == 'selected4' )
        return;

    if ( img5 && num == 5 && img5.className == 'selected5' )
        return;

    if ( img6 && num == 6 && img6.className == 'selected6' )
        return;

    if ( bzlava ) bannerzlava.style.display = 'none';

    imgsrc = bannersPath + 'games/' + globalLang + '/' + order + '_' + id + ( cat == '' ? '' : '_' + cat ) + '.jpg';
    imgurl = basePath + url + 'banner/' + id + '/' + ( cat == '' ? 'detail' : 'index' ) + '.html';
    if ( img1 ) img1.className = '';
    if ( img2 ) img2.className = '';
    if ( img3 ) img3.className = '';
    if ( img4 ) img4.className = '';
    if ( img5 ) img5.className = '';
    if ( img6 ) img6.className = '';

    banner.src = imgsrc;
    blink.href = imgurl;

    if ( img1 && num == 1 ) img1.className = 'selected1';
    if ( img2 && num == 2 ) img2.className = 'selected2';
    if ( img3 && num == 3 ) img3.className = 'selected3';
    if ( img4 && num == 4 ) img4.className = 'selected4';
    if ( img5 && num == 5 ) img5.className = 'selected5';
    if ( img6 && num == 6 ) img6.className = 'selected6';

    if ( bzlava ) bannerzlava.style.display = 'block';
}

/*function external() {
 if (document.getElementsByTagName) {
  var i, a;
  a = document.getElementsByTagName('a');
  for (i in a) {
   if (a[i].href &&
       a[i].rel && a[i].rel == 'external') a[i].target = '_blank';
  }
 }
}*/
//window.onload = hideAllDetails()
