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

document.observe('dom:loaded', function() {
  setTimeout(hideFlashes, 25000);

	$$("#ms-f-right-2 .ms-tb3 .expanded").each(function(item){item.remove()});
	$$(".ms-navi-main-fly-v1-1 .ms-navi-main-fly-v1-1-right .ms-navi li .ms-navi-main-fly-v1-2").each(function(item){ item.innerHTML = "<iframe></iframe>" })
	
	$$('#equipment_table tbody > tr:nth-child(odd)').each(function(evenRow){
		evenRow.addClassName("odd")
	});
	$$('#equipment_table tbody > tr:first-child').each(function(topRow){
		topRow.addClassName("heading")
	});

	$$('#equipment_table tbody > tr > td:last-child').each(function(lastColumn){
		lastColumn.addClassName("last")
	});

	$$('#equipment_table tbody > tr > th:last-child').each(function(lastColumn){
		lastColumn.addClassName("last")
	});
	
});
  
var hideFlashes = function() {
  $$('.notice', '.warning', '.error').each(function(e) {
    if (e) Effect.Fade(e, { duration: 1.5 });
  })
}

function ismobilesafari(){
	  if(navigator.userAgent.indexOf('iPod') != -1){return true;}
	  if(navigator.userAgent.indexOf('iPad') != -1){return true;}
    if(navigator.userAgent.indexOf('iPhone') != -1){return true;}
    else{return false;}
}

var include = (function(){
    var scripts = [];
    var curr = 0;
    var currScriptElem = null;
    var loadTimeout = null;
    var busy = false;
    var inited = false;
    var head = null;
 
		if (window.addEventListener){
	    window.addEventListener('load', init, false);
		} else if (window.attachEvent) {
			window.attachEvent("onload", init)
		}
 
    function init(){
        head = document.getElementsByTagName('head')[0];
        inited = true;
        next();
    };
 
    function next(e){
        busy = true;
        if(e){
            window.clearTimeout(loadTimeout);
            e.target.removeEventListener('load',next);
            var callbacks = scripts[curr-1].callbacks;
            scripts[curr-1].loaded = true;
 
            if(callbacks.length > 0){
                var i = callbacks.length;
                while(i--){
                    callbacks[i]();
                }
            }
        }
 
        if(scripts.length > curr){
            var currentScript = scripts[curr].path;
            curr++;
 
            var script = document.createElement('script');
            var suffix = currentScript.substring(currentScript.lastIndexOf('.')+1);
            var type;
            switch(suffix){
                case 'js': type ='text/javascript';break;
                case 'rb': type ='text/ruby';break;
                case 'py': type ='text/python';break;
                case 'php': type ='text/php';break;
                default: type = 'text/javascript';
            }
 
             script.setAttribute('type', type);
             script.setAttribute('src', currentScript);
            script.addEventListener('load',next,false);
 
            currScriptElem = script;
            loadTimeout = window.setTimeout(skip,10000);
            head.appendChild(script);
 
        } else {
            busy = false;
        }
    };
 
    function skip(){
        currScriptElem.removeEventListener('load',next);
        head.removeChild(currScriptElem);
        next();
    };
 
    function include(scriptPath,optCallback){
        var dup = false;
        var i = scripts.length;
        while (i--) {
            if(scripts[i].path == scriptPath){
                dup = true;
                if (optCallback) {
                    if(scripts[i].loaded){
                        optCallback();
                    } else {
                        scripts[i].callbacks.unshift(optCallback);
                    }
                }
                break;
            }
        }
 
        if(!dup){
            var cbs = [];
            if(optCallback) cbs.unshift(optCallback);
            scripts.push({path:scriptPath,callbacks:cbs,loaded:false});
        }
 
        if(!busy && inited) next();
    };
    return include
})();

Event.observe(window, 'load', function(){
	if (ismobilesafari()){
		include("/ios.js");
	}
});