// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

function sort_by_price() {
    return sort_by('highest', 'lowest');
}

function sort_by_posted() {
    return sort_by('newest', 'oldest');
}

function sort_by_video() {
    return sort_by('with_video', 'without_video');
}

function sort_by_image() {
    return sort_by('with_image', 'without_image');
}

function sort_by(first, second) {
    var sorted_by = $("search_sort_by");
    if(sorted_by.value == first){
        sorted_by.value = second;
    }
    else{
        sorted_by.value = first;
    }
    var form = $("search_form");
    form.submit();
    return false;
}

function toggleUploadVideoInputs(checkbox){
    if(checkbox.checked){
        $('uploadVideoContainerInt').hide();
        $('youtubeCodeContainer').appear();
    } else {
        $('youtubeCodeContainer').hide();
        $('uploadVideoContainerInt').appear();
    }
}

//Tab Reachoo
function waiting_load_changing_tab(){
    var waitingHTMLContent = '<div id="videos_row screen_0" style="float: left;" class="videos_row screen loaded">';
    waitingHTMLContent +='<img alt="spinner" src="/images/spinner.gif" align="center"/>'
    waitingHTMLContent +='</div>'
    $('paginator_scroll').innerHTML =waitingHTMLContent;
    if ($('featured_reachoo_tab_id').hasClassName("feature_active")){
        $('featured_reachoo_tab_id').removeClassName("feature_active");
        $('latest_reachoo_tab_id').addClassName("latest_active");
    }else if ($('latest_reachoo_tab_id').hasClassName("latest_active")){
        $('latest_reachoo_tab_id').removeClassName("latest_active");
        $('featured_reachoo_tab_id').addClassName("feature_active");
    }
}
function deleted_spinner(){
    $('videos_row screen_0').remove();
}

//carousel ( app/view/ads/_user_posted_ads)
function addPage(page){
    var element = $('videos_row screen_'+page);
    if ((page <= total_page) && !(element.hasClassName('loaded'))){
        new Ajax.Request(tabLink,{
            method: 'GET',
            onSuccess: function(){
                element.addClassName('loaded')
            },
            parameters:{
                page: page
            }
        });
    };
}
function view_ad_window(ad_id,hc) {
    if (hc == undefined){
        hc = false;
    }
    myLightWindow = new lightwindow();
    myLightWindow.activateWindow({
        href: "/ads/"+ad_id+"/description?hc="+hc,
        title: "",
        height: 500,
        width: 500
    });
};

  /*function insertSpinner(){
    var nextPageId = 'videos_row screen_'+next_page;
    var spinnerHTML = '<div id="'+nextPageId+'" class="videos_row screen" style="float: left;">';
    spinnerHTML += '<div style="width:930px;" align="center;">';
    spinnerHTML += '<img src="/images/spinner.gif" align="center">';
    spinnerHTML += '</div></div>';
    if ($(nextPageId) == undefined){
      new Insertion.Bottom('paginator_scroll',spinnerHTML);
    }
    generate_carousel_button();
  }*/


// function show_ads() {
//   height = 40;
//   max_height = $('border_top_big').getHeight();
//   $('side_content').childElements().each(function(el) {
//     if(height < max_height) {
//       el.show();
//       height += el.getHeight() + 20;
//     }
//   });
// }
