﻿/*
 * Date Format 1.2.2
 * (c) 2007-2008 Steven Levithan <stevenlevithan.com>
 * MIT license
 * Includes enhancements by Scott Trenda <scott.trenda.net> and Kris Kowal <cixar.com/~kris.kowal/>
 *
 * Accepts a date, a mask, or a date and a mask.
 * Returns a formatted version of the given date.
 * The date defaults to the current date/time.
 * The mask defaults to dateFormat.masks.default.
 */
var dateFormat = function () {
	var	token = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|"[^"]*"|'[^']*'/g,
		timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
		timezoneClip = /[^-+\dA-Z]/g,
		pad = function (val, len) {
			val = String(val);
			len = len || 2;
			while (val.length < len) val = "0" + val;
			return val;
		};

	// Regexes and supporting functions are cached through closure
	return function (date, mask, utc) {
		var dF = dateFormat;

		// You can't provide utc if you skip other args (use the "UTC:" mask prefix)
		if (arguments.length == 1 && (typeof date == "string" || date instanceof String) && !/\d/.test(date)) {
			mask = date;
			date = undefined;
		}

		// Passing date through Date applies Date.parse, if necessary
		date = date ? new Date(date) : new Date();
		if (isNaN(date)) throw new SyntaxError("invalid date");

		mask = String(dF.masks[mask] || mask || dF.masks["default"]);

		// Allow setting the utc argument via the mask
		if (mask.slice(0, 4) == "UTC:") {
			mask = mask.slice(4);
			utc = true;
		}

		var	_ = utc ? "getUTC" : "get",
			d = date[_ + "Date"](),
			D = date[_ + "Day"](),
			m = date[_ + "Month"](),
			y = date[_ + "FullYear"](),
			H = date[_ + "Hours"](),
			M = date[_ + "Minutes"](),
			s = date[_ + "Seconds"](),
			L = date[_ + "Milliseconds"](),
			o = utc ? 0 : date.getTimezoneOffset(),
			flags = {
				d:    d,
				dd:   pad(d),
				ddd:  dF.i18n.dayNames[D],
				dddd: dF.i18n.dayNames[D + 7],
				m:    m + 1,
				mm:   pad(m + 1),
				mmm:  dF.i18n.monthNames[m],
				mmmm: dF.i18n.monthNames[m + 12],
				yy:   String(y).slice(2),
				yyyy: y,
				h:    H % 12 || 12,
				hh:   pad(H % 12 || 12),
				H:    H,
				HH:   pad(H),
				M:    M,
				MM:   pad(M),
				s:    s,
				ss:   pad(s),
				l:    pad(L, 3),
				L:    pad(L > 99 ? Math.round(L / 10) : L),
				t:    H < 12 ? "a"  : "p",
				tt:   H < 12 ? "am" : "pm",
				T:    H < 12 ? "A"  : "P",
				TT:   H < 12 ? "AM" : "PM",
				Z:    utc ? "UTC" : (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""),
				o:    (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4),
				S:    ["th", "st", "nd", "rd"][d % 10 > 3 ? 0 : (d % 100 - d % 10 != 10) * d % 10]
			};

		return mask.replace(token, function ($0) {
			return $0 in flags ? flags[$0] : $0.slice(1, $0.length - 1);
		});
	};
}();

// Some common format strings
dateFormat.masks = {
	"default":      "ddd mmm dd yyyy HH:MM:ss",
	shortDate:      "m/d/yy",
	mediumDate:     "mmm d, yyyy",
	longDate:       "mmmm d, yyyy",
	fullDate:       "dddd, mmmm d, yyyy",
	shortTime:      "h:MM TT",
	mediumTime:     "h:MM:ss TT",
	longTime:       "h:MM:ss TT Z",
	isoDate:        "yyyy-mm-dd",
	isoTime:        "HH:MM:ss",
	isoDateTime:    "yyyy-mm-dd'T'HH:MM:ss",
	isoUtcDateTime: "UTC:yyyy-mm-dd'T'HH:MM:ss'Z'"
};

// Internationalization strings
dateFormat.i18n = {
	dayNames: [
		"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
		"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
	],
	monthNames: [
		"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
		"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
	]
};

// For convenience...
Date.prototype.format = function (mask, utc) {
	return dateFormat(this, mask, utc);
};

function SkinClass() 
{
	this.domain = 'http://'+document.domain;
	this.serviceurl = '/Services/Service.ashx';
	this.skinpath = '/Portals/_default/Skins/SmashCapComSkin';
	this.runCalendar = function(targetId,interval)
	{
		//LOOP THROUGH PARAMETERS;
		var now = new Date();
		var src = document.getElementById(targetId);
		if (typeof src != 'undefined' && src!=null)
		{
			try
			{
				var attributes = src.getAttribute('calendar');
				if (attributes!=null && attributes.length>0)
				{
					var parameters = false;
					eval('var parameters = ' + attributes);
					if (parameters && parameters.Targets.length > 0 && parameters.Targets.length == parameters.Formats.length)
					{
						var i = 0;
						for(i=0;i<parameters.Targets.length;i++)
						{
							var target = document.getElementById(parameters.Targets[i]);
							if (typeof target != 'undefined' && target!=null)
							{
								var format = parameters.Formats[i];
								target.innerHTML = now.format(format);
							}
						}
					}
				}
			}
			catch(ex)
			{
			}
		}
		
		window.setTimeout('skin.runCalendar(\'' + targetId + '\','+interval+');',interval)
	}
	this.messages = {"Media":[]};
	this.images = {"Media":[]};
	this.videos = {"Media":[]};
	
	this.messageItems = new Array();
	this.imageLastIndex = -1;
	this.messageLastIndex = -1;
	this.videoLastIndex = 1;

	this.imageIndex = 0;
	this.messageIndex = 0;
	this.videoIndex = 0;

	this.imageWait = false;
	this.messageWait = false;
	this.videoWait = false;
		
	this.messageAlt = true;
	this.messageRegisters = new Array();
	this.messageRegisterKeys = new Array();
	this.registerMessages = function(targetid,maxcount,interval,pid,eid,lid,sid,flt)
	{
    if (this.messageRegisters['msg'+targetid]==null)
    {
      this.messageRegisterKeys.push('msg'+targetid);
      this.messageRegisters["msg"+targetid] = {"targetid":targetid,"maxcount":maxcount,"interval":interval,"pid":pid,"eid":eid,"lid":lid,"sid":sid,"flt":flt};
    }
	}
	this.refreshMessages = function()
	{
    var keyi = 0;
    for (keyi=0;keyi<this.messageRegisterKeys.length;keyi++)
    {
      var r = this.messageRegisters[this.messageRegisterKeys[keyi]];
      this.runMessages(r.targetid,r.maxcount,r.interval,r.pid,r.eid,r.lid,r.sid,r.flt);
    }
	}
	
	this.runMessages = function(targetid,maxcount,interval,pid,eid,lid,sid,flt)
	{
        
		if (typeof(eid)=='undefined'||eid==null)
			eid = -1;
		if (typeof(pid)=='undefined'||pid==null)
			pid = -1;
		if (typeof(lid)=='undefined'||lid==null)
			lid = -1;
		if (typeof(sid)=='undefined'||sid==null)
			sid = -1;
		if (typeof(flt)=='undefined'||flt==null)
			flt = '';
			
		this.registerMessages(targetid,maxcount,interval,pid,eid,lid,sid,flt);
		
		if (this.messageIndex < this.messages.Media.length)
		{
			//SHOW THE MESSAGE
			this.showMessage(targetid,this.messages.Media[this.messageIndex],maxcount-1);
		}
		this.messageIndex=this.messageIndex+1;
		if (this.messageIndex >= this.messages.Media.length && !this.messageWait)
		{
			this.getMessages(pid,eid,lid,sid,flt);
		}
		window.setTimeout('skin.runMessages(\'' + targetid + '\','+maxcount+','+interval+','+pid+','+eid+','+lid+','+sid+',\'' + flt + '\');',interval)
	}
	
	this.runImages = function(pid,eid,lid,sid)
	{
		if (typeof(eid)=='undefined'||eid==null)
			eid = -1;
		if (typeof(pid)=='undefined'||pid==null)
			pid = -1;
		if (typeof(lid)=='undefined'||lid==null)
			lid = -1;
		if (typeof(sid)=='undefined'||sid==null)
			sid = -1;
		
		this.getImages(pid,eid,lid,sid);
	}
	
	this.display_images = new Array();
	this.display_text = new Array();
	this.display_image = new Array();
	this.display_video = new Array();
	
	this.register = function(name,id)
	{
		switch(name)
		{
			case 'image':
				this.display_image.push($jq('#'+id));
				break;
			case 'images':
				this.display_images.push($jq('#'+id));
				break;
			case 'video':
				this.display_video.push($jq('#'+id));
				break;
			case 'text':
				this.display_text.push($jq('#'+id));
				break;
		}
	}
	this.transfer = function(id) {this.transferid=id};
	this.transferid = null;
	this.sliderCycle = 0;
	this.getLastImage = function(selector)
	{
		var obj = $jq(selector);
		var img = obj.children('img');
		if (img!=null&&img.length>0)
			return img.attr('src');
		return null;
	}
	this.showTransfer=true;
	this.showFullImage = function(fullImage,frequency) {
try {
		for(var i=0;i<this.display_image.length;i++)
		{
		
			var slider = $jq('#'+'skinslider'+i);
			if (slider!=null&&slider.length>0&&this.transferid!=null)
			{
				if (this.showTransfer)
				{
					var bgobj = $jq('#stylizer123');
					if (bgobj==null||bgobj.length==0)
					{
						var objdiv = document.createElement('div');
						objdiv.id = 'stylizer123';
						$jq('#Footer').append(objdiv);
						bgobj = $jq('#stylizer123');
					}
					var lastImagesrc = this.getLastImage(slider);
					if (lastImagesrc!=null)
						bgobj.html('<style>.ui-effects-transfer{background: url('+lastImagesrc+');}</style>');
									
						eval('slider.hide(\'transfer\',{to: "#'+this.transferid+'",className: "ui-effects-transfer"},'+(frequency/4)+',function() { skin.slideFullImage(\''+fullImage+'\','+i+','+frequency+') });');
					slider.fadeOut(frequency/6);
				}
				else
				{
					eval('slider.hide(\'clip\',{},'+(frequency/10)+',function() { skin.slideFullImage(\''+fullImage+'\','+i+','+frequency+') });');
				}
			}
			else
			{
				skin.slideFullImage(fullImage,i,frequency);
			}
		}
} catch(ex) { 
debugger;
}
	}
	this.slideFullImage = function(fullImage,index,frequency)
	{
		$jq('#skinslider'+index).remove();
			this.display_image[index].html('<div id="skinslider'+index+'" style="display:none;"><img class="fullImage" src="' + fullImage + '"></div>');
		$jq('#skinslider'+index).show('scale',{percent: 100},(frequency*1)/10);
	}

	this.setStatus = function(src,status)
	{
		switch(src.toLowerCase())
		{
			case 'photo':
			{
				if (status.toLowerCase()=='live')
					this.imageLastIndex = -1;
				else
					this.imageLastIndex = 1;
				this.imageMax = true;
				this.photos = {"Media":[]};
				break;
			}
			case 'text':
			{
				if (status.toLowerCase()=='live')
					this.messageLastIndex = -1;
				else
					this.messageLastIndex = 1;
				this.messageMax = true;					
				this.messages = {"Media":[]};
				break;
			}
			case 'video':
			{
				if (status.toLowerCase()=='live')
					this.videoLastIndex = -1;
				else
					this.videoLastIndex = 1;
				this.videoMax = true;					
				this.videos = {"Media":[]};
				break;
			}
		}
	}
	this.messageCounter = 0;
	this.showMessage = function(targetid,message,max)
	{
		this.messageCounter++;
		if (this.messageCounter>10000)
			this.messageCounter = 0;
		
		var target = document.getElementById(targetid);
		var parentid = $jq('#'+targetid).parent().attr("id");
		
		this.messageAlt = !this.messageAlt;
		this.messageLastIndex=this.messages.Media[this.messageIndex].id;
		while (this.messageItems.length > max*2)
		{
			$jq(this.messageItems[0]).slideUp('slow');
			$jq(this.messageItems[1]).slideUp('slow');
			target.removeChild(this.messageItems[0]);
			target.removeChild(this.messageItems[1]);
			this.messageItems.splice(0,2);
		}
		var newMessage = document.createElement('div');
		var internalContainer = '';
		var newStamp = document.createElement('div');
		var background = '';
		if (!this.messageAlt)
		{
			background='#bbb';
			internalContainer = 'text';
			newMessage.className = 'text_icon_container';
		}
		else
		{
			background='#eee'; //'#dddddd';
			internalContainer = 'text_alter';
			newMessage.className = 'text_icon_container_alter';
		}
		newStamp.className = 'timestamp';
		newMessage.style.display='none';
		newStamp.style.display='none';
		var datevalue = message.date;
		if (typeof datevalue!='undefined' && datevalue!=null)
		{
		try {
			datevalue = (new Date(datevalue)).format('mmmm d yyyy h:MM tt');
		}
		catch (ex)
		{
			datevalue = '';
		}
		}
		var sourcetxt = '';
		if (message.internal=='True')
		{
			sourcetxt = '<img align="right" src="'+this.skinpath+'/_i/servicetype'+message.type+'.gif" />';
		}
		else
		{
			sourcetxt = '<img align="right" src="'+this.skinpath+'/_i/servicetype'+message.type+'.gif" />';
		}
			newMessage.innerHTML = '<div class="'+internalContainer+'" id="'+parentid+'m'+this.messageCounter+'"><div class="frame1"><div class="frame2"><div class="frame3"></div></div></div><p>' + sourcetxt + '<b>'+message.author+'</b> ' + message.src + '</p><div class="frame4"><div class="frame5"><div class="frame6"></div></div></div></div></div>';	
		newStamp.innerHTML = datevalue;
		this.messageItems.push(newMessage);
		this.messageItems.push(newStamp);
		target.appendChild(newMessage);
		target.appendChild(newStamp);
				
		$jq(newMessage).fadeIn('slow');$jq(newStamp).fadeIn('slow');
		if (this.messageScroll==false)
			this.messageScroll = document.getElementById(parentid);
		this.messageScroll.scrollTop = this.messageScroll.scrollHeight;
	}
	this.messageScroll = false;
	this.nextImage = function(pid,eid,lid,sid) {
		var url = '/Portals/'+pid+'/live.jpg';
		if (this.imageIndex < this.images.Media.length)
		{
			//SHOW THE IMAGE
			this.imageLastIndex=this.images.Media[this.imageIndex].id;			
			url = '/assets/'+this.images.Media[this.imageIndex].srv+'/'+this.images.Media[this.imageIndex].src;
		}
		this.imageIndex=this.imageIndex+1;
		if (this.imageIndex >= this.images.Media.length && !this.imageWait)
		{
			this.getImages(pid,eid,lid,sid);
		}	
		url = this.domain+url;
try {
		this.fullImages.push(this.images.Media[this.imageIndex].src);
		var img = new Image();
		img.src = this.images.Media[this.imageIndex].src + '.large.jpg';
} catch(ex) { }
	return url;
	}
	
		this.assetUrl=function(asset){       return '/assets/'+asset.srv+'/'+asset.src; 		}
	this.nextVideo = function() {
		if (this.videoIndex < this.videos.Media.length)
		{
			//SHOW THE IMAGE
			this.videoLastIndex=this.videos.Media[this.videoIndex].id;		
			var urlPath  = '/assets/'+this.videos.Media[this.videoIndex].srv+'/';
			var urlSource = this.videos.Media[this.videoIndex].src;
			if (urlSource.substr(0,5)=='http:')
			{
					urlPath='';
			}
			else
			{
				if (this.videos.Media[this.videoIndex].src.substr(0,1)=='/' || this.videos.Media[this.videoIndex].src.substr(0,1)=='\\')
					urlPath = '';
			}
			url = urlPath+this.videos.Media[this.videoIndex].src;
		}
		this.videoIndex=this.videoIndex+1;
		if (this.videoIndex >= this.videos.Media.length && !this.videoWait)
		{
			this.getVideos();
		}	
		url = url;
		return url;
	}
	this.imageError = false;
	this.messageError = false;
	this.getImages = function(pid,eid,lid,sid) {
		if (this.imageError)
		{
			window.clearTimeout(this.imageError);
			this.imageError =false;
		}
		this.imageWait = true;
		//alert(this.imageLastIndex);
		//REQUEST DATA
		//alert(this.imageLastIndex);

		var extras = '';
		if (pid>-1)
			extras=extras+'&pid='+pid;
		if (eid>-1)
			extras=extras+'&eid='+eid;
		if (lid>-1)
			extras=extras+'&lid='+lid;
		if (sid>-1)
			extras=extras+'&sid='+sid;
		if (!this.imageMax)
		{
			this.ajax('images',this.domain+this.serviceurl+'?stmp='+(new Date()).format('mmddyyyyhhMMss')+'&type=json'+extras+'&src=photo&id='+this.imageLastIndex+'&pre=skin.loadImages(&post=);');
		}
		else
		{
			this.imageMax=false;
			this.ajax('images',this.domain+this.serviceurl+'?stmp='+(new Date()).format('mmddyyyyhhMMss')+'&type=json'+extras+'&src=photo&max=1&pre=skin.loadImages(&post=);');
		}
		this.imageError = window.setTimeout ( "skin.imageWait=false;", 60000 );
		
	}
	this.imageMax = false;
	this.messageMax = true;
	this.getMessages = function(pid,eid,lid,sid,flt)
	{
		if (this.messageError)
		{
			window.clearTimeout(this.messageError);
			this.messageError =false;
		}

		this.messageWait = true;
		//REQUEST DATA
				var extras = '';
		if (pid>-1)
			extras=extras+'&pid='+pid;
		if (eid>-1)
			extras=extras+'&eid='+eid;
		if (lid>-1)
			extras=extras+'&lid='+lid;
		if (sid>-1)
			extras=extras+'&sid='+sid;
		if (flt.length>0)
			extras=extras+'&flt='+flt;
		
		if (!this.messageMax)
		{
			this.ajax('messages',this.domain+this.serviceurl+'?stmp='+(new Date()).format('mmddyyyyhhMMss')+'&type=json'+extras+'&src=note&id='+this.messageLastIndex+'&pre=skin.loadMessages(&post=);');
		}
		else
		{
			this.messageMax=false;
			this.ajax('messages',this.domain+this.serviceurl+'?stmp='+(new Date()).format('mmddyyyyhhMMss')+'&type=json'+extras+'&src=note&max=1&pre=skin.loadMessages(&post=);');
		}
		this.messageError = window.setTimeout ( "skin.messageWait=false;", 60000 );
	}
	this.lastMessage = function()
	{
		//depricated
		//this.messageMax = true;
		//this.imageMax = true;
		//this.videoMax = true;
	}
	
	
	this.loadMessages = function(content)
	{
		if (content.Media.length > 0)
		{
			this.messages = content;
			this.messageIndex = 0;
		}
		this.messageWait = false;
	}
	this.loadImages = function(content)
	{
		if (content.Media.length > 0)
		{
			this.images = content;
			this.imageIndex = 0;
		}
		this.imageWait = false;
	}
	this.videoPlayer = false;
	this.videoMax = false;
	this.videoWait = false;
	this.getVideos = function()
	{
		this.videoWait = true;
		//REQUEST DATA
		if (!this.videoMax)
		{
			if (this.videoLastIndex==0)
				this.videoLastIndex = 1;
	//alert(this.videoLastIndex);
			this.ajax('videos',this.domain+this.serviceurl+'?stmp='+(new Date()).format('mmddyyyyhhMMss')+'&type=json&src=video&id='+this.videoLastIndex+'&'+this.videoParameters+'&pre=skin.loadVideos(&post=);');
		}
		else
		{
			this.videoMax=false;
			this.ajax('videos',this.domain+this.serviceurl+'?stmp='+(new Date()).format('mmddyyyyhhMMss')+'&type=json&src=video&max=1'+'&'+this.videoParameters+'&pre=skin.loadVideos(&post=);');
		}
	}	
	
	this.loadVideos = function(content)
	{
		if (content.Media.length > 0)
		{
			this.videos = content;
			this.videoIndex = 0;
		}
		this.videoWait = false;
	}	
	this.videoParent = false;
	this.videoParentWidth = 0;
	this.videoParentHeight = 0;
	this.videoParameters = '';
	this.runVideos = function(targetid,width,height,url,pid,eid,lid,sid,flt)
	{
        
		if (typeof(eid)=='undefined'||eid==null)
			eid = -1;
		if (typeof(pid)=='undefined'||pid==null)
			pid = -1;
		if (typeof(lid)=='undefined'||lid==null)
			lid = -1;
		if (typeof(sid)=='undefined'||sid==null)
			sid = -1;
		if (typeof(flt)=='undefined'||flt==null)
			flt = '';
		this.videoParameters = 'pid='+pid+'&eid='+eid+'&lid='+lid+'&sid='+sid+'&flt='+flt
		
		this.videoParent = targetid;
		this.videoParentWidth = width;
		this.videoParentHeight = height;
		var dest = document.getElementById(targetid);
		//var str = '<embed id="myplayer" flashvars="controlbar=none&screencolor=ffffff&stretching=fill" name="myplayer" src="/player/player.swf" width="'+width+'" height="'+height+'" />';
		//dest.innerHTML = str;
		
		var so = new SWFObject('/player/player.swf','myplayer',width,height,"9","#ffffff");
		so.addParam('flashvars','controlbar=none&screencolor=ffffff&stretching=fill');
		so.write(targetid);
		
		this.videos = {"Media":[{"id":"-1","author":"","url":"","link":"","title":"","src":"","date":""}]};
		this.videos.Media[0].src = url;
	}
	this.videoFeedSource = 0;
	this.videoFeedWait = false;
	this.videoFeedChange = function()
	{
		var rslt = this.videoFeedSource;
		this.videoFeedWait = false;
		this.videoFeedSource = 0;

		this.videos = {"Media":[{"id":"0","author":"","url":"","link":"","title":"","src":"","date":""}]};

		this.playState = new Function('');
		try {
			this.videoPlayer.sendEvent("STOP");	
		} catch(ex) { }
				
//var str = '<object type="application/x-shockwave-flash" width="'+this.videoParentWidth+'" height="'+this.videoParentHeight+'" data="/Portals/0/webcamxp.swf">';
//str += '<param name="movie" value="webcamxp.swf?webcam=http://127.0.0.1:8080/cam_1.jpg&amp;refresh=50&amp;connect=&amp;offline=&amp;transtype=Fade&amp;bgcolor=#FFFFFF&amp;txtcolor=#808080" />';
//str += '<param name="FlashVars" value="webcam=http://127.0.0.1:8080/cam_1.jpg&amp;refresh=50&amp;connect=&amp;offline=&amp;transtype=Fade&amp;bgcolor=#FFFFFF&amp;txtcolor=#808080" />';
//str += '<param name="loop" value="false" />';
//str += '<param name="menu" value="false" />';
//str += '<param name="quality" value="best" />';
//str += '<param name="scale" value="noscale" />';
//str += '<param name="salign" value="lt" />';
//str += '<param name="wmode" value="opaque" />';
//str += '</object>';
		
		var FFL = (navigator.userAgent.indexOf("Firefox")!=-1)?true:false;
		if (!FFL)
			FFL = (navigator.userAgent.indexOf("Chrome")==-1 && navigator.userAgent.indexOf("Safari")!=-1)?true:false;
			
		if (!FFL)
		{
			var so = new SWFObject('/Portals/0/webcamxp.swf','myplayer',this.videoParentWidth,this.videoParentHeight,"9","#ffffff");
			so.addParam('flashvars','webcam=http://r2imedia.r2integrated.com:8080/cam_' + rslt + '.jpg&amp;refresh=50&amp;connect=&amp;offline=&amp;transtype=Fade&amp;bgcolor=#FFFFFF&amp;txtcolor=#808080');
			so.addParam('movie','webcamxp.swf?webcam=http://r2imedia.r2integrated.com:8080/cam_' + rslt + '.jpg&amp;refresh=50&amp;connect=&amp;offline=&amp;transtype=Fade&amp;bgcolor=#FFFFFF&amp;txtcolor=#808080');
			so.addParam('loop','false');
			so.addParam('menu','false');
			so.addParam('quality','best');
			so.addParam('scale','noscale');
			so.addParam('salign','lt');
			so.addParam('wmode','opaque');
			so.write(this.videoParent);
		}
		else
		{
			document.getElementById(this.videoParent).innerHTML = '<img src="http://r2imedia.r2integrated.com:8080/cam_' + rslt + '.cgi" class="webcam" id="webcam1" width="'+this.videoParentWidth+'" height="'+this.videoParentHeight+'" alt="Live Stream" />';
		}

//		document.getElementById(this.videoParent).innerHTML = str;

	
	
	}
	this.videoFeedTime = function()
	{
		var dateH = (new Date()).format('hh') * 1;
		var dateM = (new Date()).format('MM') * 1;
		if (dateH >= 5 && dateM >= 10)
		{	
			this.videoFeedSource = 0;
			this.videoFeed();
		}	
		else
		{
			window.setTimeout('skin.videoFeedTime();',10000);
		}
	}
	this.videoFeed = function()
	{
		this.videoFeedSource++;
		if (!this.videoFeedWait)
		{
			this.videoFeedWait = true;
			window.setTimeout('skin.videoFeedChange();',2000);
		}		
	}
	
	this.playVideos = function(player)
	{
		this.videoPlayer = player;
		this.videoPlayer.addModelListener('STATE','skin.playState');		
		this.playVideo();
	}
	this.playState = function(obj)
	{
		if (obj.newstate == 'COMPLETED')
		{
			this.playVideo();
		}
	}
	this.skipVideo = function()
	{
		this.playVideo();
	}
	this.playVideo = function()
	{
	  var url=this.nextVideo();
		this.videoPlayer.sendEvent("LOAD",url);
		this.videoPlayer.sendEvent("PLAY");	
	}
	
	this.ajaxItems = new Array();
	this.ajaxCreate = function (name)
	{
		if (typeof this.ajaxItems[name] == 'undefined' || this.ajaxItems[name] == null)
		{
			this.ajaxItems[name] = {"request":false,"response":false};
			eval('this.ajaxItems[name].response = new Function("skin.ajaxResponse(\''+name+'\');");');
			try
			{
				this.ajaxItems[name].request = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch(e)
			{
				try
				{
					this.ajaxItems[name].request = new ActiveXObject("Microsoft.XMLHTTP");
				} 
				catch(oc)
				{
					this.ajaxItems[name].request = null;
				}
			}
			//Mozilla and Safari 
			if((typeof this.ajaxItems[name].request == 'undefined' || this.ajaxItems[name].request == null) && typeof XMLHttpRequest != "undefined") 
			{
				this.ajaxItems[name].request = new XMLHttpRequest();
			}
		}
	}
	this.ajax = function(name,url)
	{
		this.ajaxCreate(name);
		
		// If browser supports XMLHTTPRequest object
		if(this.ajaxItems[name].request!=null && this.ajaxItems[name].request)
		{
			try {
			//Setting the event handler for the response
			this.ajaxItems[name].request.onreadystatechange = this.ajaxItems[name].response;
			
			//Initializes the request object with GET (METHOD of posting), 
			//Request URL and sets the request as asynchronous.
			this.ajaxItems[name].request.open("GET", url,  true);
			
			//Sends the request to server
			this.ajaxItems[name].request.send(null);	

			//return XmlHttp.responseText;		
			}
			catch(ex)
			{
			}
		}
	}
	this.ajaxResponse = function(name)
	{
		 // To make sure receiving response data from server is completed
		 if(this.ajaxItems[name].request.readyState == 4)
		 {
		  // To make sure valid response is received from the server, 200 means response received is OK
		  if(this.ajaxItems[name].request.status == 200)
		  {   
			try
			{
			var JSONResult = eval(this.ajaxItems[name].request.responseText);
			this.ajaxItems[name] = null;
			//loadExecResult(JSONResult);
			} 
			catch(ex)
			{

			}
		  }
		  else
		  {

		  }
		 }
	}
}
var skin = new SkinClass();
//skin.runImages();

function playerReady(obj) {
	var objX = document.getElementById(obj['id']);
	if (typeof obj['id'] == 'undefined')
	{
		objX = document.getElementById('myplayer');
	}
	skin.playVideos(objX);
};

function imageCycle(name,id,cclass,iwidth,iheight,iclass,count,frequency,position,direction,callback,pid,eid,lid,sid) {
		if (typeof(eid)=='undefined'||eid==null)
			this.eid = -1;
		else
			this.eid = eid;
		if (typeof(pid)=='undefined'||pid==null)
			this.pid = -1;
		else
			this.pid = pid;
		if (typeof(lid)=='undefined'||lid==null)
			this.lid = -1;
		else
			this.lid = lid;
		if (typeof(sid)=='undefined'||sid==null)
			this.sid = -1;	
		else
			this.sid = sid;
	this.name = name;
	this.id = id;
	this.target = $jq('#'+id);
	this.cclass=cclass;
	this.iwidth=iwidth;
	this.iheight=iheight;
	this.iclass=iclass;
	this.count=count;
	this.frequency=frequency;
	if(this.frequency <= 0)
		this.frequency=1000;
	this.position=position;
	this.direction=direction;
	this.callback=callback;
	
	this.timer = null;
	this.items = new Array();


	this.cycler = 0;
	this.imagePreloader = new Array();
	this.getLastImage = function(selector)
	{
		var obj = $jq(selector);
		var img = obj.children('img');
		if (img!=null&&img.length>0)
			return img.attr('src');
		return null;
	}
	this.drop = function(selector)
	{
		var obj = $jq(selector);
		obj.remove();
		img =null;
		obj = null;
	}
	this.slide = function(selector)
	{
		$jq(selector).animate({width: this.iwidth},(this.frequency*.25));
	}
	this.cycle = function()
	{
		this.cycler++;
		if (this.cycler>10000) this.cycler=0;
		var nurl = null;
		var url = null;
		try {
			eval('nurl='+this.callback);
		}
		catch(ex)
		{
			nurl = null;
		}
		if (nurl!=null)
		{	
			if (this.imagePreloader.length==4)
			{
				url = this.imagePreloader[0].src;
				this.imagePreloader.splice(0,2);
			}
			var smallImage = new Image();
			var largeImage = new Image();
			
			smallImage.src = nurl;
			this.imagePreloader.push(smallImage);
							
			if (skin.display_image.length>0)
			{
				largeImage.src = nurl+'.large.jpg';
			}
			this.imagePreloader.push(largeImage);

			if (skin.display_image.length>0&&this.imagePreloader.length==4)
			{
				skin.showFullImage(this.imagePreloader[1].src,this.frequency);				
			}
			
		}
		if (url!=null)
		{	
				var remove = null;
				if (this.items.length == this.count)
				{
					remove = '#'+this.items[0];
					this.items.splice(0,1);
				}
				var itemid = this.id+'s'+this.cycler;
				skin.transferid = itemid;
				var item = '<div id="'+itemid+'" style="display:none;width:0;position:relative;float:'+this.direction+'" class="'+this.cclass+'">';
				item = item +'<img style="position:absolute;left:0;top:0;" id="'+itemid+'img" src="'+url+'" width="'+this.iwidth+'" height="'+this.iheight+'" class="'+this.iclass+'"/>';
				item = item +'<img style="position:absolute;left:0;top:0;" src="'+skin.skinpath+'/_i/frame.gif" width="'+this.iwidth+'" height="'+this.iheight+'" class="'+this.iclass+'"/>';
				item = item + '</div>'
				this.items.push(itemid);
				this.target.prepend(item);
				//Rounded('div#'+itemid,"transparent","#bbbbbb");						
				
				var rItem = null;
				if (remove!=null) rItem = $jq(remove);
				
				switch(this.direction)
				{
					case 'left':
						if (remove!=null)
						{
							eval('rItem.hide(\'slide\',{},'+(this.frequency/10)+', function() {'+this.name+'.drop(\''+remove+'\');'+this.name+'.slide(\'#'+itemid+'\');});');	
						}
						else
						{
							this.slide('#'+itemid);
						}
						break;
					case 'right':
						//aItem.animate({width: this.iwidth},750);
						
						if (remove!=null)
						{
							eval('rItem.hide(\'slide\',{},'+(this.frequency/10)+', function() {'+this.name+'.drop(\''+remove+'\');'+this.name+'.slide(\'#'+itemid+'\');});');	
						}
						else
						{
							this.slide('#'+itemid);
						}
						//eval('if (remove!=null) rItem.animate({ width:"0",display:"none" }, { queue:false, duration:500, complete: function() {'+this.name+'.drop(\''+remove+'\');}});');
						//aItem.animate({ width:this.iwidth, display:"block" }, { queue:false, duration:1000},'swing');				
						break;
					case 'top':
						//if (remove!=null) rItem.slideUp('slow');
						//aItem.slideDown('slow');
						break;
					case 'bottom':
						//if (remove!=null) rItem.slideDown('slow');
						//aItem.slideUp('slow');
						break;
				}
				
				rItem = null;
				itemid = null;
				item = null;
				//aItem = null;
		}
		
		window.setTimeout(this.name+'.cycle();',this.frequency);
	}
	this.cycle();
}

