// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
sfHover = function() {
	var sfEls = document.getElementById("blue_nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" iehover";
			//Effect.Appear(this.id+"_children", { duration: 0.5, queue: {position:'end', scope: 'blue_nav', limit:2 }})
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" iehover\\b"), "");
			//Effect.Fade(this.id+"_children", { duration: 0.5, queue: {position:'end', scope: 'blue_nav', limit:2 }})
		}
	}

}

if (window.attachEvent) window.attachEvent("onload", sfHover);


function restartGif(){
	for(var i=0; i<document.images.length; i++){
		var img = document.images[i];
		var imgName = img.src.toUpperCase();
		if (imgName.substring(imgName.length-3, imgName.length) == "GIF"){
			img.src = img.src;
		}
	}
}	
Ajax.Responders.register({
  onCreate: function() {
    restartGif();
  }
});

function update_revisions(name, id)
{
	if ($('revisions_'+name).visible())
	{
		Effect.BlindUp('revisions_'+name, {afterFinish: function (element) { 
			Element.show('spinner_'+name);
			new Ajax.Updater('revisions_'+name, 'admin/verbiage/revisions?name='+name+'&page_id='+id, {asynchronous:true, evalScripts:true, onComplete:function(request){Element.hide('spinner_'+name);Effect.BlindDown('revisions_'+name);select_verbiage_revision(name, "new");Effect.Fade('button_revisions_'+name);}})
			 }});
	}
	else
		$("content_"+name+"_revision").value = "new"
}

function select_verbiage_revision(name, id)
{
	if (id == "")
	{
		id = $("content_"+name+"_revision").value
	}
	
	if (id == "new")
	{
		id = $(name+'_revisions').descendants().first().id.sub(name+'_revision_', '');
		$("content_"+name+"_revision").value = id
	}		
	else
		$("content_"+name+"_revision").value = id
	
	unselect_all_verbiage_revisions(name);
	$(name+'_revision_'+id).className = "selected";
}

function unselect_all_verbiage_revisions(name)
{
	$$('#'+name+'_revisions li').each( function(el) { el.className = ""; });
}

function get_hotkey(e) {
	var key = (typeof e != 'undefined' && typeof e.which != 'undefined') ? e.which :
	(typeof e != 'undefined' && typeof e.keyCode != 'undefined') ? e.keyCode :
	(typeof window.event != 'undefined' && typeof event.keyCode != 'undefined') ? event.keyCode :
	null;
	if (!key) return true;
	key = String.fromCharCode(key);

	if ((typeof hotkey[key] != 'undefined' && (e.ctrlKey && e.altKey) || (window.event && window.event.altKey))) return hotkey[key]();
}

window.onkeypress = get_hotkey;
var hotkey = new Object();
hotkey['l'] = function() { 
    document.location = "/admin/login";
}


var Reflector = {
  reflect: function(element) {
    element = $(element);
    options = $H({
      amount: 1/3,
      opacity: 1/3
    }).merge(arguments[1] || {});
    
    var p = element.parentNode, n = element.nextSibling;
    var d = 1.0/(element.height*options.amount);
      
    (element.height*options.amount).times( function(line) {
      var h = Builder.node('div',{style:'height:1px;overflow:hidden'},
        [Builder.node('img',{src:element.src, 
          style:'margin-top:-'+(element.height-line-1)+'px'
        })]);
      p.insertBefore(h,n);
      $(h).setOpacity((1-d*line)*options.opacity);
    });
  }
}