// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

function mark_for_destroy(element){
    $(element).next('.should_destroy').value = 1;
    $(element).up('.photo').hide();
}

function destroy_photo(element){
    $(element).up('.photo').remove();
}

function showArrow(arrow){
    $(arrow).style.visibility = "visible";
}

function hideArrow(arrow){
    $(arrow).style.visibility = "hidden";
}

function changeImg(image, isource){
    
    $(image).getElementsByTagName("img").src =isource;
}

function showNextPhoto(){
    active_ajax_loading();
    var seq = eval(getSeqNoFromDiv());    
    new Ajax.Request('/offers/show_next/' + seq,
    {
        asynchronous:true, evalScripts:true     
    }
  ); 
}

function showPreviousPhoto(){
    active_ajax_loading();
    var seq = eval(getSeqNoFromDiv());
    new Ajax.Request('/offers/show_previous/' + seq,
    {
        asynchronous:true, evalScripts:true      
    }
  ); 
}

function getSeqNoFromDiv(){
    if( $("seq_no").innerHTML == ""){
        return null;
    }
    return $("seq_no").innerHTML;
} 
    
function active_ajax_loading(){
    $("offer_main").style.opacity = 0.2;  
    $("ajax_loading").show();
    
}

function deactive_ajax_loading(){
    $("ajax_loading").hide();
    $("offer_main").style.opacity = 1;
}

function choose_picture(obj){
    
    var f = document.forms[0];             
    
    var checkBoxes = f.getInputs('checkbox');
    
    //checkBoxes.each(Element.hide);
    
    if (obj.checked == 1){
        hide_unselected_checkboxes(checkBoxes,obj);
    
    }else{
       show_all_checkboxes(checkBoxes);
    }  
      
}

function hide_unselected_checkboxes(checkBoxes,chck){

     var i;
     
     for(i = 0; i < checkBoxes.length; i++){
        
        if ((checkBoxes[i] != chck) && (checkBoxes[i].id != "offer_special")){
            checkBoxes[i].hide();
        }    
        
    }   

}

function show_all_checkboxes(checkBoxes){
    
    var i;
    
     for(i = 0; i < checkBoxes.length; i++){
        
        checkBoxes[i].show();       
        
     }   
}
