var useflash = true;

function createPlayer(theFile,placeholder,anid,wide,high,img) {
		if (useflash == true) {
            if (high > 200) {
				var flashvars = {
                    file:theFile+'.flv', 
                    autostart:"false", 
                    shuffle:"false", 
					repeat:"list",
                    playlistsize:"0",
                    playlist:"none",
					skin:"modieus.swf"};
				 var params = {
                    allowfullscreen:"true", 
                    allowscriptaccess:"always",
					wmode:"opaque"
            }
            }else{
				
				var flashvars = {
                    file:theFile+'.flv', 
                    autostart:"false", 
                    shuffle:"false",
					repeat:"list",
                    playlistsize:"0",
                    playlist:"none",
					skin:"modieus.swf",
					plugins:"spectrumvisualizer-1"}
				 var params = {
                    allowfullscreen:"false", 
                    allowscriptaccess:"always",
					wmode:"opaque"
            }
            };
           
            var attributes = {
                    id:anid,  
                    name:anid
            }
            swfobject.embedSWF("/flash/player.swf", placeholder, wide,high, "9.0.115", false, flashvars, params, attributes);
		}else{
			// inject html5 mobile video player
			html='<a href="'+theFile+'.3gp" target="_blank">Play Video</a>';
			//wide='140px';
			//high='80px';
			//html = '<video id="'+anid+'" width="'+wide+'" height="'+high+'" controls="controls"><source src="'+theFile+'.mp4video.mp4" type="video/mp4" /><source src="'+theFile+'.theora.ogv" type="video/ogg" />Your browser does not support the video tag.</video>';
			$(placeholder).set('html', html);
		}
};

function goparent(alink){
 if (window!=window.top) {
	 self.parent.location=alink;
 }else{
	 window.location=alink;
 };
}

function createAudioPlayer(adiv,afile){
  AudioPlayer.embed(adiv, {soundFile: ""+afile+""}); 
};
	
function DHTMLSound(surl){if((navigator.userAgent.indexOf('iPhone')!=-1)||(navigator.userAgent.indexOf('iPod')!=-1)||(navigator.userAgent.indexOf('Linux')!=-1))
{window.location=surl;}else{document.getElementById("dummyspan").innerHTML="<embed src='"+surl+"' hidden=true autostart=true loop=false type='audio/mpeg'>";}}
					   
function enableTooltips(id) {
    var links, i;
	//show popup tooltips/hints for each of these types of elements' title parameter:
    if (id == null) links = document.getElementsByTagName("a");
    else links = document.getElementById(id).getElementsByTagName("a");
    for (i = 0; i < links.length; i++) {
        Prepare(links[i])
    };
    links = document.getElementsByTagName("img");
    for (i = 0; i < links.length; i++) {
        Prepare(links[i])
    };
    links = document.getElementsByTagName("span");
    for (i = 0; i < links.length; i++) {
        Prepare(links[i])
    };
    links = document.getElementsByTagName("input");
    for (i = 0; i < links.length; i++) {
        Prepare(links[i])
    };
    links = document.getElementsByTagName("div");
    for (i = 0; i < links.length; i++) {
        Prepare(links[i])
    };
	var Tips3 = new Tips($$('.atooltip'), {
	   //class:'tooltip tip shadow',
       fixed: true
    });
	// also ensure lightbox videos etc are shown after ajax load
	if(typeof(Mediabox) != "undefined") {
		//MediaBox.scanPage()
		};
};
function hasClass(ele,cls) {
	return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
};
function addClass(ele,cls) {
	if (!this.hasClass(ele,cls)) ele.className += " "+cls;
};

function Prepare(el) {
   // add class 'tips' to this element if it has a title 
    var tooltip, t, b, s, l, anel;
    t = el.getAttribute("title");
    if (t > '') {
        addClass(el,'atooltip');
    };
};

function parseScript(_source) {
		var source = _source;
		var scripts = new Array();
		
		// Strip out tags
		while(source.indexOf("<script") > -1 || source.indexOf("</script") > -1) {
			var s = source.indexOf("<script");
			var s_e = source.indexOf(">", s);
			var e = source.indexOf("</script", s);
			var e_e = source.indexOf(">", e);
			
			// Add to scripts array
			scripts.push(source.substring(s_e+1, e));
			// Strip from source
			source = source.substring(0, s) + source.substring(e_e+1);
		}
		
		// Loop through every script collected and eval it
		for(var i=0; i<scripts.length; i++) {
			try {
				eval(scripts[i]);
			}
			catch(ex) {
				// do what you want here when a script fails
			}
		}
		
		// Return the cleaned source
		return source;
	};


if (Browser.Engine.trident4) {
	alert('You need to upgrade your browser! We recommend the latest version of Firefox, Internet Explorer 9 or Chrome.'); 
};

var apagepopup;

function pagepopup(page,wid,high,atitle) {
	var mytext = "<IFRAME id='pagepop' frameBorder='0' src='default.asp?page_url="+page+"' width=" + (wid-10) + "px height=" + (high-5) + "px style='width:100%;height:" + (high-5) + "px;overflow:scroll;background-color:white;'></IFRAME>";
apagepopup = new LightFace({
   width: wid,
   height: high,
   fadeDelay: 100,
   draggable: true,
   title: atitle,
   content: mytext,
   buttons: [
      { title: 'Close', event: function() { this.close(); }, color: 'blue' }
     ],
   resetOnScroll: true
 }); 
apagepopup.open();
};

function urlpopup(page,wid,high,atitle) {
	var mytext = "<IFRAME id='pagepop' frameBorder='0' src='aj_readpage.asp?page_url=pleasewait' width=" + (wid-10) + "px height=" + (high-5) + "px style='width:100%;height:" + (high-5) + "px;overflow:scroll;background-color:white;'></IFRAME>";
apagepopup = new LightFace({
   width: wid,
   height: high,
   fadeDelay: 100,
   draggable: true,
   title: atitle,
   content: mytext,
   buttons: [
      { title: 'Close', event: function() { this.close(); }, color: 'blue' }
     ],
   resetOnScroll: true
 }); 
apagepopup.open();
setTimeout("$('pagepop').src='"+page+"';",1250);

};

var noticecount=1;
var pid = "pagepop"+noticecount;

function noticepopup(noteid,atitle) {
	var wid = 550;
	var high =330;
	noticecount ++;
	pid = "pagepop"+noticecount;	
	aurl='aj_readpage.asp?page_url=notice&notice_id='+noteid+'&sid='+Math.random();
	var mytext = "<div id='"+pid+"' width=" + (wid-10) + "px height=" + (high-5) + "px style='width:100%;height:" + (high-5) + "px;overflow:auto;background-color:white;'><center><img src='images/ajax-loader.gif'></center></div>";
	new LightFace({
	   width: wid,
	   height: high,
	   fadeDelay: 100,
	   draggable: true,
	   title: atitle,
	   content: mytext,
	   overlayAll:true,
	   buttons: [
		  { title: 'Delete', event: function() { 
		  			aurl='aj_readpage.asp?page_url=delete_notice' + '\&' + 'notice_id='+noteid+'\&' + 'uid='+loggedinuserid;
		  			new Request.HTML({method: 'get',url:aurl, update: $(pid)}).send();
					this.close();
					window.location.reload(true); 
					}, color: 'red' },
		  { title: 'Close', event: function() { this.close(); }, color: 'blue' }
		 ],
	   resetOnScroll: true
		}).open();
	 
	new Request.HTML({
		  method: 'get',
		  url:aurl,
		  update: $(pid)
		}).send();
};

function contentpopup(page,wid,high,atitle) {
	aurl='aj_readpage.asp?page_url='+page+'&sid='+Math.random();
	var mytext = "<div id='popupcontent' width=" + (wid-10) + "px height=" + (high-5) + "px style='width:100%;height:" + (high-5) + "px;overflow:auto;background-color:white;'><center><img src='images/ajax-loader.gif'></center></div>";
	var pop1 = new LightFace({
	   width: wid,
	   height: high,
	   fadeDelay: 100,
	   draggable: true,
	   title: atitle,
	   content: mytext,
	   overlayAll:true,
	   buttons: [
		  { title: 'Close', event: function() { this.close(); }, color: 'blue' }
		 ],
	   resetOnScroll: true
		}).open();
	 
	new Request.HTML({
		  method: 'get',
		  url:aurl,
		  update: $('popupcontent')
		}).send();
	return pop1;
};

function resizeIframe(iframeID) { 
if(self==parent) return false; /* Checks that page is in iframe. */ 
else if(document.getElementById&&document.all) /* Sniffs for IE5+.*/ 

var FramePageHeight = framePage.scrollHeight + 10; /* framePage 
is the ID of the framed page's BODY tag. The added 10 pixels prevent an 
unnecessary scrollbar. */ 

parent.document.getElementById(iframeID).style.height=FramePageHeight; 
/* "iframeID" is the ID of the inline frame in the parent page. */ 
};
