var acdc="file=/content/acdc/media/ACDC_RockNRollTrain.flv&controlbar=none";

function toggleDisplay(id) {
    if(document.getElementById(id).style.display == 'none') {
        document.getElementById(id).style.display = '';
    } else {
        document.getElementById(id).style.display = 'none';
    }
}

function initTabs() {
    var elements = $('portletTabs').getElementsBySelector('.yui-content > div');
    var links = $('portletTabs').getElementsBySelector('.yui-nav a').each(function (e) {
        e.onclick = toggleTab;
    });
    
    for(var i = 1; i < elements.length; i++) {
        elements[i].hide();
    }    
}

function toggleTab(event) {
    var tabNum = this.attributes[0].nodeValue.substr(4); 
    var elements = $('portletTabs').getElementsBySelector('.yui-content > div').each(function (e) {
        e.hide();
    });
    
    this.up(2).childElements().each(function (e) {
        e.removeClassName('selected');
    });
    
    
    elements[tabNum-1].show();
    this.up(1).addClassName('selected');
}

window.onload = function(){ 
    if ($('portletTabs') != null) {
        initTabs();
    }
};

function ie_thumb(element, changeBack) {
    if (changeBack) {
        element.className = 'listItemCont1';
        var info = $(element).select('div.listItemCont1_info');
        info[0].style.display = 'none';
        element.style.margin = "0 0 0 0";
    } else {
        element.style.left = "auto";
        if (window.ActiveXObject) {
            element.style.margin = "auto auto auto -67px";
        }
        element.className = 'userhover';
        var info = $(element).select('div.listItemCont1_info');
        info[0].style.display = 'inline';
    }
}

function openPlayer(id) {    
    var newWindow = window.open("http://www.cluster.mubito.customers.artful.net/flash/popUpPlayer.jsp?mediaId="+id,"popUpPlayer", "width=691,height=435,scrollbars=no");
    newWindow.opener = null;        
}

function openCart() {
    $('shoppingCartView').show();
}

function addToCart(id,format, additionalformat) {
    var quantity = 1;
    
    if ($('quantity'+id) != null) {
        quantity = $('quantity'+id).options[$('quantity'+id).selectedIndex].value;
    }
    
    if (format != null && format == 'cat11') {
        format = $('types1').options[$('types1').selectedIndex].text + ' ' + $('types2').options[$('types2').selectedIndex].text;
    } else if (format == 'cat6') {
        format = '';
        var keepRunning = true;
        var i = 1;
        while (keepRunning) {
            if ($('types'+i) == null) {
                keepRunning = false;
            } else {
                format = format + $('types'+i).options[$('types'+i).selectedIndex].value + ' ';
                i++;
            }
        }
    } 
    
    if (format == null) {
        format = 'wma';
    }
    
    if (additionalformat != null) {
        format += ' ' + additionalformat;
    }
    
    new Ajax.Request('/shoppingcart.php', {
        method: 'post',
        postBody: 'shoppingCart=1&_scId='+id+'&_scQ='+quantity+'&_scF='+format,
        onSuccess: function(transport) {
            $('cart').update(transport.responseText);
            $('cart').show();  
        }
    });
}

function getCartContents() {
    new Ajax.Request('/shoppingcart.php', {
        method: 'get',
        onSuccess: function(transport) {
            if (transport.responseText.length > 1) {
                $('cart').update(transport.responseText);
            } else {
                $('cart').hide();
            }
        }
    });
} 

function removeFromCart(id) {
    closeCart();
    new Ajax.Request('/shoppingcart.php', {
        method: 'post',
        postBody: 'shoppingCart=2&_scId='+id,
        onSuccess: function(transport) {
            if (transport.responseText.length <= 1) {
                $('cart').hide();
            }
            
            $('cart').update(transport.responseText);   
        }
    });
}

function closeCart() {
    $('shoppingCartView').hide();
}

function showText(id) {
    $$('.tekst').each(function(el) {
        el.hide();
    });
    
    $('tekst'+id).show();
}

function showSection(id) {
    $$('.section').each(function(el) {
        el.hide();
    });

    $('section'+id).show();
}

function competition() {
    if (document.tavling.cemail != null) {
        new Ajax.Request('/content/acdc/competition.php', {
            method: 'post',
            postBody: $('tavling').serialize(),
            onSuccess: function(transport) {
                $('tavling').update(transport.responseText);   
            }
        });
    } else {
        new Ajax.Request('/content/martin/competition.php', {
            method: 'get',
            onSuccess: function(transport) {
                $('tavling').update(transport.responseText);   
            }
        });
    }
    return false;    
}

function makePagination(id, pages, currentPage, link) {
    var paging = '';
                                                    
    for(var i = 1; i <= pages; i++) {
        if (i == currentPage) {
            paging += '['+i+'] ';
        } else {
            paging += '<a href="'+link+'/'+i+'">'+i+' </a>';
        }
    }
    
    $(id).update(paging);
}