/*
    Author: Joe Tan
    Email: jtan@silaspartners.com

*/    
var SilasPage = function() {
    function SilasPlugins(e){
    }
    var self = SilasPlugins
    
    function addOnLoad (func) {
        this.plugins[this.plugins.length] = func
    }
    function addOnLoadFinish (func) {
        this.pluginsFinish[this.pluginsFinish.length] = func
    }
    
    function initialize() {
        for (var i=0;i<this.plugins.length;i++) {
            this.plugins[i]()
        }
        for (var i=0;i<this.pluginsFinish.length;i++) {
            this.pluginsFinish[i]()
        }
    }
    self.addOnLoad = addOnLoad
    self.addOnLoadFinish = addOnLoadFinish
    self.initialize = initialize
    self.plugins = Array()
    self.pluginsFinish = Array()
    return self;
}();

function initializeBookmark() {
    var location = window.location + ""
    if (location.indexOf('#') != -1)
        gotoBookmark(location.substring(location.indexOf('#')+1))
}

SilasPage.addOnLoadFinish(initializeBookmark)

/*
Some useful utility DOM functions
*/
function GetElementsWithClassName(elementName,className,obj) {
    var allElements = null
    if (obj) {
        allElements = obj.getElementsByTagName(elementName);
    } else {
    	allElements = document.getElementsByTagName(elementName);
    }
	var elemColl = new Array();
	for (i = 0; i< allElements.length; i++) {
		if (isClass(allElements[i], className)) {
			elemColl[elemColl.length] = allElements[i];
		}
	}
	return elemColl;
}
function DOM_insertAfter(newChild,refChild)
//Post condition: if childNodes[n] is refChild, than childNodes[n+1] is newChild.
{
  var parent=refChild.parentNode;
  if(parent.lastChild==refChild) return parent.appendChild(newChild);
  else return parent.insertBefore(newChild,refChild.nextSibling);
}
function isClass(object, className) {
	return (object.className.search('(^|\\s)' + className + '(\\s|$)') != -1);
}


/* Misc functions */
function clearDefaultValue(obj) {
    if (!obj.defaultValue || obj.defaultValue == '' || (obj.defaultValue == obj.value)) {
        obj.value = ''
        if (obj.className) obj.className += ' focused'
        else obj.className = 'focused'
    }
}
function gotoBookmark (bookmark) {
    return
}
function clearDefault(obj) { return clearDefaultValue(obj); }
function doDropDown(obj) {
    var url = obj.options[obj.selectedIndex].value
    if (url != "null") {
    window.location = url
    }
}
function iniRandomLoad(targetUL) {
	if(document.getElementById && document.getElementsByTagName) {
		if(document.getElementById(targetUL)) {
			var container = document.getElementById(targetUL);
			var ads = container.getElementsByTagName('li'); 		
			var whichAd = Math.floor(Math.random()*(ads.length));
			ads[whichAd].className += ' show';	
		}
	}
}
function showVideoPlayerCode(url, type, width, height) {
    var html = 
            '<OBJECT ID="Player" height="320" width="320" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" type=application/x-oleobject>' +
            '<PARAM NAME="AUTOSTART" VALUE="0">' +
            '<PARAM NAME="ShowDisplay" VALUE="0">' +
            '<PARAM NAME="ShowControls" VALUE="1">' +
            '<PARAM NAME="TransparentAtStart" VALUE="1">' +
            '<PARAM NAME="AnimationAtStart" VALUE="0">' +	
            '<PARAM NAME="AutoSize" VALUE="1">' +
            '<PARAM NAME="ShowStatusBar" VALUE="1">' +
            '<PARAM NAME="FILENAME" VALUE="'+url+'">' +
            '<PARAM NAME="URL" VALUE="'+url+'">' +
            '<EMBED Type="video/x-ms-asf-plugin" src="'+url+'" name="Player" AutoStart="1" ShowControls="1" ShowStatusBar="1"  ShowDisplay="0" width="320" height="320" ></EMBED>' +
            '</OBJECT>';
    html = html + '<textarea readonly class="banner-code">'+html+'</textarea>';
    document.write(html);
}