// document onload function to hook up all JQuery event hijackers
$(document).ready(function() {
   if (typeof document.body.style.maxHeight == "undefined") {
     // this is IE 6 or below, we don't have to do anything
   } else {
     // for every other browser, remove the ie6 notice div altogether so it hopefully doesn't get indexed by Google
     $('#ie_notice').remove();
   }
   
   // set up links with the 'remote' class to be submitted via ajax
   $("a.remote").click(function(){
     if(this.rel) {
       // if a rel is specified, the contents of the href are loaded into the div with that id
       $(this.rel).load(this.href);
     } else {
       $.get(this.href, null, null, "script");
     }
     return false;
   })
});

function get_width() {
  if($('#sortable_items')) {
    // get the total width of the containing element
    var total_width = $('#sortable_items').width()

    // subtract width of other elements and allow for padding
    var new_width_single = total_width - 180;
    var new_width_double = total_width - 210;
	var new_width_only = total_width - 200;

    // set the width on the elements
    $('.auto_width').css('width', new_width_single);
    $('.auto_width2').css('width', new_width_double/2);
  	$('.auto_width3').css('width', new_width_only);
}
}




// methods to show/hide "AJAX" form divs. assumes you have _form, _busy, and _link divs
function show_busy_div(name) {
	if($("#" + name + "_form")) { $("#" + name + "_form").hide(); };
	if($("#" + name + "_link")) { $("#" + name + "_link").hide(); };
	if($("#" + name + "_busy")) { $("#" + name + "_busy").show(); };
}
function show_form_div(name) {
	if($("#" + name + "_link")) { $("#" + name + "_link").hide(); };
	if($("#" + name + "_busy")) { $("#" + name + "_busy").hide(); };
	if($("#" + name + "_form")) { $("#" + name + "_form").show(); };
}
function show_link_div(name) {
	if($("#" + name + "_busy")) { $("#" + name + "_busy").hide(); };
	if($("#" + name + "_form")) { $("#" + name + "_form").hide(); };
	if($("#" + name + "_link")) { $("#" + name + "_link").show(); };
}
function clear_form_div(name) {
	if($("#" + name + "_form")) { $("#" + name + "_form").html(""); }
	if($("#" + name + "_form")) { $("#" + name + "_form").hide(); };
	if($("#" + name + "_busy")) { $("#" + name + "_busy").hide(); };
	if($("#" + name + "_link")) { $("#" + name + "_link").show(); };
}
// methods to show/hide "AJAX" form spans in table rows.
function show_busy_row(name,id) {
	if($("#tr_" + name + "_link_"+id)) { $("#tr_" + name + "_link_"+id).hide(); };
	if($("#tr_" + name + "_busy_"+id)) { $("#tr_" + name + "_busy_"+id).show(); };
}
function show_link_row(name,id) {
	if($("#tr_" + name + "_busy_"+id)) { $("#tr_" + name + "_busy_"+id).hide(); };
	if($("#tr_" + name + "_link_"+id)) { $("#tr_" + name + "_link_"+id).show(); };
}
// methods to show/hide busy widgets
function show_busy_widget(name) {
	if($("#" + name)) { $("#" + name).show(); };
} 
function hide_busy_widget(name) {
	if($("#" + name)) { $("#" + name).hide(); };
}


// -------------------------------------------------------
// Methods to batch add tags to multiple upload
// -------------------------------------------------------
function apply_tags(){
	var tags = $("input[name='batch_tags']").attr("value");
	var form_inputs = $(":input");
	
	for(var i=0; i < form_inputs.length; i++){
		if(form_inputs[i].name.match("tags")){
			if( form_inputs[i].value.length > 0 ){ form_inputs[i].value = form_inputs[i].value + ", " + tags; }
			else { form_inputs[i].value = tags; }
		}
	}
	
	// clear out the field
	$("input[name='batch_tags']").attr("value", "");
}