/**
* Keeps track of the number of submits performed by forms
* on the page.
*/
var num_submits = 0;

/**
 * Reset the number of submits so the user can re-submit if they
 * go back in their browser history.
 *
 */
window.onbeforeunload = function() {
    num_submits = 0;
};

function hide(link_id, target_id) {
    document.getElementById(link_id).style.backgroundImage ='url(http://resources.ableton.com/common/arrow.png)';
    document.getElementById(target_id).style.display='none';
}

function show(link_id, target_id) {
    document.getElementById(link_id).style.backgroundImage ='url(http://resources.ableton.com/common/arrow_open.png)';
    document.getElementById(target_id).style.display='block';
}

function toggle(element_name) {
    link_id = element_name + '_link';
    target_id = element_name + '_target';
    if(document.getElementById(target_id).style.display == 'block') {
        hide(link_id, target_id);
    }
    else {
        show(link_id, target_id);
    }
}

function process_form_submission(form) {
    return is_first_submit();
}

function submit_address_form() {
    document.getElementById("address_form").submit()
}

/**
 * Increments the number of form submissions then returns
 * true if the last submission was the first, false otherwisse.
 *
 * @return a boolean value
 *
 */
function is_first_submit() {
    num_submits++;
    return num_submits == 1;
}

function connect(link) {
  window.location.href = link
  return true;
}

/**
 * Apply some CSS changes for the case
 * Javascripts is enabled
*/
$(document).ready(function() {
    $('div.toggle_headline').each(function () {$(this).addClass('toggle_headline_js')});
    $('div.toggle_content').each(function () {$(this).addClass('toggle_content_js')});
    $('div.popup a').hover(function() {
        $(this).find('.pop').each(function () {
            $(this).css('display', 'block');
            $(this).css('height', '1px');
            $(this).css('left', '-1px');
            $(this).css('position', 'absolute');
            $(this).css('top', '-1px');
            $(this).css('width', '0px');;
        });
    });
});


 // prevent soundcloud link to go to soundcloud page
 // but start playing
$(document).ready(function() {
    $('.sc-player .sc-info a').live('click', function() {
        $(this).parent().parent().siblings('ol').find('li:first').click();
        return false
    });
});
