(function($) {

$.fn.mgPlayer = function(url,settings) {
	settings = $.extend({
		playerType: 'reg',
		playerWidth: 591,
		playlistOnLoad: true,
		playlistOnStop: true,
		previewImg: '',
		thumbImg: '',
		desc: '',
		initialVol: 80,
		siteCode: ''
	},settings);
	var mgObject = this;
	mgObject.playDiv = $(this);
	mgObject.videoRef = null;
	mgObject.settings = settings;
	mgObject.width=(settings.playerType=='rail')?310:settings.playerWidth;
	mgObject.url = url;
	mgObject.embedCode = '&lt;object width="429" height="295"&gt;&lt;param name="movie" value="http://vp.mgnetwork.net/viewer.swf?u=' + mgObject.url.substring(mgObject.url.lastIndexOf('/')+1,mgObject.url.lastIndexOf('.')) + '&amp;z=' + mgObject.settings.siteCode + '"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;embed src="http://vp.mgnetwork.net/viewer.swf?u=' + mgObject.url.substring(mgObject.url.lastIndexOf('/')+1,mgObject.url.lastIndexOf('.')) + '&amp;z=' + mgObject.settings.siteCode + '" type="application/x-shockwave-flash" allowfullscreen="true" width="429" height="295"&gt;&lt;/embed&gt;&lt;/object&gt;';
	mgObject.height = (settings.playerType=='stnd')?(Math.round((3/4)*mgObject.width)):(Math.round((9/16)*mgObject.width));
	mgObject.cpHeight = (settings.playerType=='rail')?32:39;
	mgObject.sliderWidth = (settings.playerType=='rail')?(mgObject.width-115):(mgObject.width-205);
	mgObject.playlistItems = 0;
	mgObject.playlistCurrent = 0;
	mgObject.playlistPosition = 0;
	mgObject.playlistItemWidth = 0;
	mgObject.currentTime = 0;
	mgObject.totalDuration = 0;
	mgObject.defaultThumb = 'http://vamsimages.mgnetwork.com/no_image.jpg';
	mgObject.paused = false;
	mgObject.adLoaded = false;
	mgObject.videoLoaded = false;
	mgObject.vol = settings.initialVol;
	mgObject.mgPlayerBuild();
	
	mgObject.videoRef.bind('load',function(event,data){
		mgObject.mgPlayerInitLoad();												   
		mgObject.playDiv.find('.controlPanel .playButton, .videoLayer .playOverlay').click(function(){
			mgObject.mgPlayerPlay();
		});
		mgObject.playDiv.find('.controlPanel .pauseButton').click(function(){
			mgObject.mgPlayerPause();
		});
		mgObject.playDiv.find('.controlPanel .backButton').click(function(){
			if (mgObject.videoLoaded&&!mgObject.adLoaded) mgObject.mgPlayerBack();
		});
		mgObject.playDiv.find('.controlPanel .volArea .volIcon').click(function(){
			mgObject.mgPlayerVolIcon();
		});
		mgObject.playDiv.find('.controlPanel .volArea .volBar, .controlPanel .volArea .volBarOn').click(function(){
			mgObject.mgPlayerVolBar(this);
		});
		mgObject.playDiv.find('.controlPanel .slider').mousedown(function(){
			if (mgObject.videoLoaded&&!mgObject.adLoaded) mgObject.mgPlayerSliderMove();
		});
	});
	mgObject.videoRef.bind('play', function (event, data){
		if (typeof sendFlashPageView != 'undefined') sendFlashPageView(curObj.settings.desc, curObj.url);
	});
	mgObject.videoRef.bind('advance',function(event,data){
		mgObject.totalDuration = data.duration;
		mgObject.currentTime = data.time;
		mgObject.playDiv.find('.statSlide').mgPlayerSetSlide(Math.round((data.time/data.duration)*mgObject.sliderWidth),mgObject.sliderWidth);
		mgObject.playDiv.find('.controlPanel .curTime').mgPlayerMakeTime(data.time);
		if (mgObject.settings.playerType!='rail') mgObject.playDiv.find('.controlPanel .totTime').mgPlayerMakeTime(data.duration);
	});
	mgObject.videoRef.bind('complete',function(event,data){
		mgObject.mgPlayerUnload();
	});
	mgObject.videoRef.bind('preroll',function(event,data){
		mgObject.adLoaded = true;
		mgObject.mgPlayerControlsOff(true);
		mgObject.videoRef.one('prerollcomplete',function(event,data){
			mgObject.adLoaded = false;
			mgObject.mgPlayerControlsOn(true);
		});
	});
	return mgObject;
};

$.fn.extend({
	mgPlayerBuild: function(){
		curObj = this;
		curObj.playDiv.append('<div class="controlPanel' + ((curObj.settings.playerType!='rail')?'':' cpSmall') + '"><div class="topRow"><div class="backButton" title="Back"></div><div class="pauseButton" title="Pause"></div><div class="playButton" title="Play"></div><div class="sliderArea"><div class="endL"></div><div class="statSlide"></div><div class="endR"></div></div><div class="timeArea"><span class="curTime">00:00</span>' + ((curObj.settings.playerType!='rail')?' / <span class="totTime">00:00</span>':'') + '</div><div class="volArea"><div class="volIcon" title="Mute"></div>' + ((curObj.settings.playerType!='rail')?'<div class="volBar" level="20"></div><div class="volBar" level="40"></div><div class="volBar" level="60"></div><div class="volBar" level="80"></div><div class="volBar" level="100"></div>':'') + '</div>' + /*((curObj.settings.playerType!='rail')?'<div class="fullButton" title="Full Screen"></div>':'') +*/ '</div><div class="bottomOptions"><div class="shareButton" title="SHARE THIS">+ SHARE THIS</div></div><span class="statusMsg"></span></div>');
		
		curObj.videoRef = $('<div class="videoLayer" id="' + curObj.playDiv.attr('id') + '-videoLayer"></div>').prependTo(curObj.playDiv).videoplayer();
		if (curObj.settings.previewImg!='') curObj.playDiv.find('.videoHtmlLayer').append('<img src="' + curObj.settings.previewImg + '" class="startImage" />');
		curObj.playDiv.height(curObj.height+curObj.cpHeight).width(curObj.width);
		if (curObj.playDiv.find('.videoLayer .videoBackdrop').css('background-image')!='none') curObj.playDiv.find('.videoLayer .videoBackdrop').append('<img src="' + curObj.playDiv.find('.videoLayer .videoBackdrop').css('background-image').substring(curObj.playDiv.find('.videoLayer .videoBackdrop').css('background-image').indexOf('(')+1,curObj.playDiv.find('.videoLayer .videoBackdrop').css('background-image').lastIndexOf(')')).replace(/"/g,'') + '" />').css('background-image','none');
		curObj.playDiv.find('.videoLayer,.videoLayer .videoBackdrop,.videoLayer .videoBackdrop img,.videoLayer .videoPlayer,.videoLayer .videoHtmlLayer').height(curObj.height).width(curObj.width);
		curObj.playDiv.find('.controlPanel .sliderArea').css('width',curObj.sliderWidth+10).find('.statSlide').css('margin-right',curObj.sliderWidth);
		if (curObj.playDiv.find('.videoLayer .startImage').width()/curObj.playDiv.find('.videoLayer .startImage').height()>16/9) curObj.playDiv.find('.videoLayer .startImage').width(curObj.width);
		else curObj.playDiv.find('.videoLayer .startImage').height(curObj.height);
		for(i=2; i<=10; i+=2) curObj.playDiv.find('.controlPanel .volBar[level='+(i*10)+']').css({height:(i+3),'margin-top':(10-i),'background-position':'0 '+(-29+i)+'px'});
		curObj.playDiv.mgPlayerSetVol(curObj.vol);
		curObj.playDiv.find('.statusMsg').text('LOADING');

		curObj.playDiv.append('<div class="shareBg' + ((curObj.settings.playerType!='rail')?'':' shareSmall') + '"></div><div class="sharePanel' + ((curObj.settings.playerType!='rail')?'':' shareSmall') + '"><div class="closeShare" title="Close"></div><div class="shareTitle">GET THIS VIDEO:</div><div class="shareBar"><div class="shareBarScroller"><div class="shareBarCode">' + curObj.embedCode + '</div></div></div><div class="copyButton"></div></div>');
		curObj.playDiv.find('.controlPanel .shareButton').css('cursor','pointer').bind('mouseover',function(){$(this).css('color','#3f8fc5');}).bind('mouseout',function(){$(this).css('color','#656461');}).click(function(){$(this).parents('.nebula_player').find('.shareBg, .sharePanel'+(($(this).parents('.nebula_player').find('.playlistPanel').css('display')=='block')?', .playlistBg, .playlistPanel':'')).slideToggle(200);});
		curObj.playDiv.find('.shareBg, .sharePanel').css({'width':curObj.width,'bottom':curObj.cpHeight})
		curObj.playDiv.find('.shareBg').css('opacity',0.8);
		curObj.playDiv.find('.sharePanel .shareBar').css('width',curObj.width-((curObj.settings.playerType!='rail')?101:86));
		curObj.playDiv.find('.sharePanel .shareBar .shareBarScroller').css('width',curObj.width-56);
		curObj.playDiv.find('.sharePanel .closeShare').css('opacity',0.75).hover(function(){$(this).fadeTo(100,1);},function(){$(this).fadeTo(100,0.75);}).click(function(){$(this).parents('.nebula_player').find('.shareBg, .sharePanel').slideUp(200);});
		curObj.playDiv.find('.sharePanel .copyButton').mouseover(function(){$(this).addClass('copyButtonHover');}).mouseout(function(){$(this).removeClass('copyButtonHover');}).click(function(){
		  embedHtml = curObj.playDiv.find('.sharePanel .shareBar .shareBarCode').text();
		  if (window.clipboardData) {
			window.clipboardData.setData("Text",embedHtml);
		  }else if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) {
			netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
			var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);  
			if (!str) return false;  
			str.data = embedHtml;  
			var trans = Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable);  
			if (!trans) return false;  
			trans.addDataFlavor("text/unicode");  
			trans.setTransferData("text/unicode", str, embedHtml.length * 2);  
			var clipid = Components.interfaces.nsIClipboard;  
			var clip = Components.classes["@mozilla.org/widget/clipboard;1"].getService(clipid);  
			if (!clip) return false;  
			clip.setData(trans, null, clipid.kGlobalClipboard);  
		  }
		});

	},
	mgPlayerInitLoad: function(){
		curObj = this;
		curObj.playDiv.find('.videoHtmlLayer').append('<div class="playOverlay' + ((curObj.settings.playerType!='rail')?'':' smallPlay') + '"><div class="bigButton"></div></div>');
		curObj.playDiv.find('.controlPanel .statSlide').append('<div class="slider"></div>');
		curObj.playDiv.find('.videoLayer .playOverlay').css({'margin-top':Math.round((curObj.height-curObj.playDiv.find('.videoLayer .playOverlay').height())/2)+'px','margin-left':Math.round((curObj.width-curObj.playDiv.find('.videoLayer .playOverlay').width())/2)+'px'});
		curObj.playDiv.find('.videoLayer .playOverlay').hover(function(){$(this).addClass('playOverlayHover').find('.bigButton').addClass('bigButtonHover');},function(){$(this).removeClass('playOverlayHover').find('.bigButton').removeClass('bigButtonHover');});
		curObj.mgPlayerReady();
		curObj.playDiv.find('div.videoLayer div,div.controlPanel div').bind('mousedown',function(){return false;}).bind('selectstart',function(){return false;});
		curObj.playDiv.find('.statusMsg').text('READY');
		if (curObj.settings.playerType=='rail') curObj.playDiv.find('.statusMsg').stop().fadeTo(2000,1,function(){$(this).fadeOut(500);});
	},
	mgPlayerReady: function(){
		curObj = this;
		curObj.playDiv.find('.controlPanel .pauseButton, .controlPanel .volArea .volIcon, .controlPanel .volArea .volBar, .controlPanel .volArea .volBarOn').css('cursor','pointer');
		curObj.playDiv.find('.controlPanel .pauseButton').hover(function(){$(this).addClass('pauseButtonHover');},function(){$(this).removeClass('pauseButtonHover');});
		curObj.playDiv.find('.controlPanel .playButton').hover(function(){$(this).addClass('playButtonHover');},function(){$(this).removeClass('playButtonHover');});
		curObj.playDiv.find('.controlPanel .volArea .volBar, .controlPanel .volArea .volBarOn').hover(function(){$(this).parent('.volArea').mgPlayerSetVol($(this).attr('level'));},function(){$(this).parent('.volArea').mgPlayerSetVol(curObj.vol);});
		if (curObj.playlistItems > 1) {
			curObj.playDiv.find('.controlPanel .plistButton').css('cursor','pointer').bind('mouseover',function(){$(this).css('color','#3f8fc5');}).bind('mouseout',function(){$(this).css('color','#656461');}).click(function(){$(this).parents('.nebula_player').find('.playlistBg, .playlistPanel'+(($(this).parents('.nebula_player').find('.sharePanel').css('display')=='block')?', .shareBg, .sharePanel':'')).slideToggle(200);});
			if (curObj.settings.playlistOnLoad) curObj.playDiv.find('.playlistBg, .playlistPanel').slideDown(200);
		}
	},
	mgPlayerBack: function(){
		curObj = this;
		curObj.playDiv.find('.statSlide').mgPlayerSetSlide(0,curObj.sliderWidth);
		curObj.videoRef.videoplayer('seek',0);
	},
	mgPlayerPlay: function(){
		curObj = this;
		curObj.playDiv.find('.controlPanel .playButton').hide().siblings('.pauseButton').show();
		if (!curObj.videoLoaded) {
			curObj.playDiv.find('.statSlide').mgPlayerSetSlide(0,curObj.sliderWidth);
			curObj.playDiv.find('.videoPlayer').show();
			curObj.videoRef.videoplayer('play',curObj.url);
			curObj.paused = false;
			curObj.videoRef.videoplayer('setVolume',curObj.vol);
			curObj.mgPlayerControlsOn(false);
			curObj.videoRef.one('success',function(event,data){
				curObj.videoLoaded = true;
				if (curObj.playDiv.find('.playlistPanel').css('display')!='none') curObj.find('.playlistBg, .playlistPanel').slideUp(200);
				if (curObj.playDiv.find('.videoHtmlLayer').css('display')!='none') curObj.playDiv.find('.videoHtmlLayer').fadeOut(500);	
			});
		} else {
			if (curObj.paused) curObj.videoRef.videoplayer('pause');
		}
		curObj.paused = false;
		curObj.playDiv.find('.statusMsg').text('PLAYING').show();
		if (curObj.settings.playerType=='rail') curObj.playDiv.find('.statusMsg').stop().fadeTo(2000,1,function(){$(this).fadeOut(500);});
	},
	mgPlayerPause: function() {
		curObj = this;
		curObj.playDiv.find('.controlPanel .pauseButton').hide().siblings('.playButton').show();
		if (!curObj.paused) curObj.videoRef.videoplayer('pause');
		curObj.paused = true;
		curObj.playDiv.find('.statusMsg').text('PAUSED').show().stop();	
	},
	mgPlayerUnload: function() {
		curObj = this;
		curObj.videoLoaded = false;
		curObj.playDiv.find('.controlPanel .pauseButton').hide().siblings('.playButton').show();
		curObj.mgPlayerControlsOff(false);
		curObj.playDiv.find('.videoHtmlLayer').fadeIn(500).find('.playOverlay').hide();
		curObj.playDiv.find('.statusMsg').text('STOPPED').show().stop();
		if (curObj.settings.playlistOnStop && curObj.playlistItems > 0 && curObj.playDiv.find('.playlistBg, .playlistPanel').css('display')!='block') curObj.playDiv.find('.playlistBg, .playlistPanel'+((curObj.playDiv.find('.sharePanel').css('display')=='block')?',.sharePanel,.shareBg':'')).slideToggle(200);
	},
	mgPlayerVolIcon: function(){
		curObj = this;
		curObj.vol=(curObj.vol!=0)?0:curObj.settings.initialVol;
		curObj.playDiv.find('.controlPanel .volArea').mgPlayerSetVol(curObj.vol);
		if (curObj.vol==0) curObj.playDiv.find('.controlPanel .volArea .volIcon').addClass('volIconHover');
		else curObj.playDiv.find('.controlPanel .volArea .volIcon').removeClass('volIconHover');
		curObj.videoRef.videoplayer('setVolume',curObj.vol);
	},
	mgPlayerVolBar: function(volBar){
		curObj = this;
		curObj.vol=$(volBar).attr('level');
		$(volBar).parent('.volArea').mgPlayerSetVol(curObj.vol);
		$(volBar).siblings('.volIcon').removeClass('volIconHover');
		curObj.videoRef.videoplayer('setVolume',curObj.vol);		
	},
	mgPlayerSliderMove: function(){
		curObj = this;
		sliderOff = curObj.playDiv.find('.controlPanel .statSlide').offset().left;
		if (!curObj.paused) curObj.videoRef.videoplayer('pause');
		curObj.playDiv.focus().bind('mousemove',{testObj:curObj},function(e){
			posx=(e.pageX)?e.pageX:((e.clientX)?e.clientX+document.body.scrollLeft+document.documentElement.scrollLeft:0);
			curSlider=(posx-sliderOff<0)?0:((posx-sliderOff>=e.data.testObj.sliderWidth)?e.data.testObj.sliderWidth:(posx-sliderOff));
			sliderTime=Math.round((curSlider/e.data.testObj.sliderWidth)*e.data.testObj.totalDuration);
			e.data.testObj.playDiv.find('.controlPanel .curTime').mgPlayerMakeTime(sliderTime);
			e.data.testObj.playDiv.find('.statSlide').mgPlayerSetSlide(curSlider,e.data.testObj.sliderWidth);
			e.data.testObj.videoRef.videoplayer('seek',sliderTime);
		}).one('mouseup',{testObj:curObj},function(e){
			$(this).unbind('mousemove').blur();
			if (!e.data.testObj.paused) e.data.testObj.videoRef.videoplayer('pause');
		});
	},
	mgPlayerSetVol: function(volLev) {
		for(i=2; i<=10; i+=2) $(this).find('.volBar[level='+(i*10)+'], .volBarOn[level='+(i*10)+']').attr('class',(volLev>=(i*10))?'volBarOn':'volBar');
	},
	mgPlayerSetSlide: function(curWidth,totWidth) {
		if (curWidth+2>totWidth) curWidth=totWidth-2;
		$(this).css({width:curWidth,'margin-right':(totWidth-curWidth)});
		$(this).find('.slider').css('left',curWidth);
	},
	mgPlayerMakeTime: function(seconds) {
		newMin = Math.floor(seconds/60);
		newSec = Math.floor(seconds-(newMin*60));
		if (newSec==60) {newSec=0;newMin=newMin+1;}
		$(this).text(((newMin<10)?'0':'')+newMin+':'+((newSec<10)?'0':'')+newSec);
	},
	mgPlayerControlsOff: function(playlist) {
		curObj = this;
		curObj.playDiv.find('.controlPanel .backButton').css('cursor','default').unbind('mouseover').unbind('mouseout');
		curObj.playDiv.find('.controlPanel .slider').css('cursor','default').unbind('mouseover').unbind('mouseout');
		if (playlist) curObj.playDiv.find('.controlPanel .plistButton').css('cursor','default').unbind('mouseover').unbind('mouseout').unbind('click');
	},
	mgPlayerControlsOn: function(playlist) {
		curObj = this;
		curObj.playDiv.find('.controlPanel .backButton').css('cursor','pointer').mouseover(function(){$(this).addClass('backButtonHover');}).mouseout(function(){$(this).removeClass('backButtonHover');});
		curObj.playDiv.find('.controlPanel .slider').css('cursor','pointer').mouseover(function(){$(this).addClass('sliderHover');}).mouseout(function(){$(this).removeClass('sliderHover');});
		if (playlist) curObj.playDiv.find('.controlPanel .plistButton').css('cursor','pointer').mouseover(function(){$(this).css('color','#3f8fc5');}).mouseout(function(){$(this).css('color','#656461');}).click(function(){$(this).parents('.nebula_player').find('.playlistBg, .playlistPanel'+(($(this).parents('.nebula_player').find('.sharePanel').css('display')=='block')?', .shareBg, .sharePanel':'')).slideToggle(200);});
	},
	addPlaylistItem: function(url,settings) {
		settings = $.extend({
			previewImg: '',
			thumbImg: '',
			desc: ''
		},settings);
		curObj = this;
		if (curObj.playlistItems == 0) {
			curObj.mgPlayerBuildPlaylist();
			curObj.mgPlayerAddItem(curObj.url,curObj.settings);
		}
		curObj.mgPlayerAddItem(url,settings);
	},
	mgPlayerBuildPlaylist: function(){
		curObj = this;
		curObj.playDiv.append('<div class="playlistBg'+((curObj.settings.playerType=='rail')?' playlistSmall':'')+'"></div><div class="playlistPanel'+((curObj.settings.playerType=='rail')?' playlistSmall':'')+'"><div class="closePlaylist" title="Close Playlist"></div><div class="playlistTitle">PLAYLIST (1-1 of ' + curObj.playlistItems + ')</div><div class="playlistStripe"><div class="playlistPrev"></div><div class="playlistVideoArea"></div><div class="playlistNext"></div></div></div>');
		if (curObj.settings.playerType!='rail') {
			curObj.playDiv.find('.controlPanel .bottomOptions').prepend('<div class="plistButton" title="Playlist">PLAYLIST (' + curObj.playlistCurrent + '/' + curObj.playlistItems + ')</div>');	
			curObj.playDiv.find('.controlPanel .shareButton').addClass('shareButtonSep');
		}
		else {
			curObj.sliderWidth = curObj.sliderWidth-34;
			curObj.playDiv.find('.controlPanel .sliderArea').css('width',curObj.sliderWidth+10).find('.statSlide').css('margin-right',curObj.sliderWidth);
			curObj.playDiv.find('.controlPanel .topRow').append('<div class="plistButton" title="Playlist">(' + curObj.playlistCurrent + '/' + curObj.playlistItems + ')</div>');
		}
		curObj.playDiv.find('.playlistBg, .playlistPanel').css({'width':curObj.width,'bottom':curObj.cpHeight})
		curObj.playDiv.find('.playlistBg').css('opacity',0.8);
		curObj.playDiv.find('.playlistPanel .playlistNext, .playlistPanel .playlistPrev').css('opacity',0.5);
		curObj.playDiv.find('.playlistPanel .playlistVideoArea').width(curObj.width-((curObj.settings.playerType!='rail')?78:50));
		curObj.playDiv.find('.playlistPanel .closePlaylist').css('opacity',0.75).hover(function(){$(this).fadeTo(100,1);},function(){$(this).fadeTo(100,0.75);}).click(function(){$(this).parents('.nebula_player').find('.playlistBg, .playlistPanel').slideUp(200);});
		curObj.playlistItemWidth = Math.floor((curObj.width-((curObj.settings.playerType!='rail')?102:62))/2);
	},
	mgPlayerAddItem: function(url,settings){
		settings = $.extend({
			previewImg: '',
			thumbImg: '',
			desc: ''
		},settings);
		curObj = this;
		$('<div class="playlistVideo' + ((curObj.playlistItems==0)?' selected':'') + '" num="' + (curObj.playlistItems+1) + '"><img height="'+((curObj.settings.playerType!='rail')?'58':'36')+'" src="' + ((settings.thumbImg&&settings.thumbImg.indexOf('{')==-1)?settings.thumbImg:curObj.defaultThumb) + '" />' + settings.desc + '</div>').appendTo(curObj.playDiv.find('.playlistVideoArea')).css({'width':curObj.playlistItemWidth,'left':((curObj.playlistItemWidth+((curObj.playerType!='rail')?12:6))*curObj.playlistItems)}).hover(function(){$(this).addClass('playlistVideoHover');},function(){$(this).removeClass('playlistVideoHover');}).bind('click',{testObj:curObj},function(e){e.data.testObj.mgPlayerPlayItem(url,settings,$(this).attr('num'));});
		curObj.playlistItems++;
		curObj.playlistCurrent=1;
		curObj.playlistPosition=1;
		curObj.playDiv.find('.playlistPanel .playlistTitle').text('PLAYLIST (1-'+((curObj.playlistItems>1)?'2':curObj.playlistItems)+' of '+curObj.playlistItems+')');
		curObj.playDiv.find('.controlPanel .plistButton').text(((curObj.settings.playerType!='rail')?'PLAYLIST ':'')+'('+curObj.playlistCurrent+'/'+curObj.playlistItems+')');
		curObj.mgPlayerCheckPlaylist();		
	},
	mgPlayerCheckPlaylist: function(){
		curObj = this;
		if (curObj.playlistItems > 2) {
			curObj.playDiv.find('.playlistPanel .playlistPrev').removeClass('playlistPrevHover').empty().css({'opacity':0.5,'cursor':'default'}).unbind('mouseover').unbind('mouseout').unbind('click');
			curObj.playDiv.find('.playlistPanel .playlistNext').removeClass('playlistNextHover').empty().css({'opacity':0.5,'cursor':'default'}).unbind('mouseover').unbind('mouseout').unbind('click');
			if (curObj.playlistPosition > 2) {
				curObj.playDiv.find('.playlistPanel .playlistPrev').append('<div class="prevButton"></div>').css({'opacity':1,'cursor':'pointer'}).bind('mouseover',function(){$(this).addClass('playlistPrevHover');}).bind('mouseout',function(){$(this).removeClass('playlistPrevHover');}).bind('click',{testObj:curObj,offset:(curObj.playlistItemWidth+((curObj.playerType!='rail')?12:6))},function(e){
					$(this).siblings('.playlistVideoArea').find('.playlistVideo').animate({'left':'+='+(e.data.offset*2)+'px'},200);
					e.data.testObj.playlistPosition = e.data.testObj.playlistPosition-2;
					e.data.testObj.playDiv.find('.playlistPanel .playlistTitle').text('PLAYLIST ('+e.data.testObj.playlistPosition+'-'+((e.data.testObj.playlistItems>e.data.testObj.playlistPosition)?e.data.testObj.playlistPosition+1:e.data.testObj.playlistPosition)+' of '+e.data.testObj.playlistItems+')');
					e.data.testObj.mgPlayerCheckPlaylist();
				});				
			}
			if (curObj.playlistItems-curObj.playlistPosition > 1) {
				curObj.playDiv.find('.playlistPanel .playlistNext').append('<div class="nextButton"></div>').css({'opacity':1,'cursor':'pointer'}).bind('mouseover',function(){$(this).addClass('playlistNextHover');}).bind('mouseout',function(){$(this).removeClass('playlistNextHover');}).bind('click',{testObj:curObj,offset:(curObj.playlistItemWidth+((curObj.playerType!='rail')?12:6))},function(e){
					$(this).siblings('.playlistVideoArea').find('.playlistVideo').animate({'left':'-='+(e.data.offset*2)+'px'},200);
					e.data.testObj.playlistPosition = e.data.testObj.playlistPosition+2;
					e.data.testObj.playDiv.find('.playlistPanel .playlistTitle').text('PLAYLIST ('+e.data.testObj.playlistPosition+'-'+((e.data.testObj.playlistItems>e.data.testObj.playlistPosition)?e.data.testObj.playlistPosition+1:e.data.testObj.playlistPosition)+' of '+e.data.testObj.playlistItems+')');
					e.data.testObj.mgPlayerCheckPlaylist();
				});
			}
		}
	},
	mgPlayerPlayItem: function(url,settings,cur){
		settings = $.extend({
			previewImg: '',
			thumbImg: '',
			desc: ''
		},settings);
		curObj = this;	
		if (curObj.videoLoaded) {
			curObj.mgPlayerUnload();
			if (curObj.paused) curObj.videoRef.videoplayer('pause');
			curObj.videoRef.videoplayer('stop');
		}
		curObj.url = url;
		curObj.playlistCurrent=cur;
		curObj.embedCode = '&lt;object width="429" height="295"&gt;&lt;param name="movie" value="http://vp.mgnetwork.net/viewer.swf?u=' + curObj.url.substring(curObj.url.lastIndexOf('/')+1,curObj.url.lastIndexOf('.')) + '&amp;z=' + curObj.settings.siteCode + '"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;embed src="http://vp.mgnetwork.net/viewer.swf?u=' + curObj.url.substring(curObj.url.lastIndexOf('/')+1,curObj.url.lastIndexOf('.')) + '&amp;z=' + curObj.settings.siteCode + '" type="application/x-shockwave-flash" allowfullscreen="true" width="429" height="295"&gt;&lt;/embed&gt;&lt;/object&gt;';
		curObj.playDiv.find('.playlistBg, .playlistPanel').hide();
		curObj.playDiv.find('.playlistPanel .playlistVideo').removeClass('selected').filter('[num='+cur+']').addClass('selected');
		curObj.playDiv.find('.controlPanel .plistButton').text(((curObj.settings.playerType!='rail')?'PLAYLIST ':'')+'('+curObj.playlistCurrent+'/'+curObj.playlistItems+')');
		curObj.playDiv.find('.videoHtmlLayer img.startImage').attr('src',settings.previewImg);
		curObj.playDiv.find('.sharePanel .shareBarCode').html(curObj.embedCode);
		curObj.mgPlayerPlay();
	}
});

})(jQuery);
