function pageflip(hide,show,id,target) {
	document.getElementById(id+hide).style.display = 'none';
	document.getElementById(id+show).style.display = 'block';
	document.location.href = '#'+target;
}
// Need to support the old highlighting functions until VH1 migrates to new code
function vidlist_high(obj){
	obj.className = 'vidlist_high';
}

function vidlist_dehigh(obj){
	obj.className = 'vidlist_dehigh';
}

function vidclick(url){
	document.location.href = url;

}

// Hey Ojo - had to jack this in for none MTV sites - 
if (typeof(MTV) == 'undefined') MTV = {};

MTV.VidPopup = new function()
{
	this.init = function(ajaxstatus){
		obj = $j('.vidlist_dehigh');
		var i = 1;
		
		obj.each(function(){			
			var posX = 0;
			var posY = 0;
			var stepback = i-1;
			var triggerParentId = 'vidlist_'+i;
            var trigger = $j('#innerVidlist_'+i);
			var triggerParent = $j('#'+triggerParentId);
			var pagination = triggerParent.attr("pagination");
			var timeout = 50;
			
			var id = 'popup_'+i;
            var inb = $j('#'+inb);	
		
			
			triggerParent.css({cursor: 'pointer'});
			
			var getViews = "";
			if(triggerParent.attr("mainviews")!='')
			{
				getViews = "     <span class='views'>"+triggerParent.attr("mainviews")+"</span>";	
			}
			
			var getMainTitle = triggerParent.attr("maintitle");
			var getImg =  document.getElementById('img_'+i).innerHTML;
			var getScript = "&nbsp;<span id='scriptPopupWidget_"+i+"'></span>";
			var getTitle = "<div class='title1'><a href='#'>"+getImg+getMainTitle+"</a></div>";
			var getTContent = "<p class='deck'>"+triggerParent.attr("maincontent")+"</p>";			
			var getPosted = "<span class='posted'>Posted "+triggerParent.attr("mainposted")+"</span>";
			var getLink = "<p class='usage'>"+getPosted+getViews+"</p>";
			
			var construct = "<div class='popup_div_body'><div>"+getTitle+getTContent+getLink+"</div><div class='clr'>"+getScript+"</div></div><div class='popup_div_bottom' id=\"popUpBottom_"+i+"\"> </div>";				
			dynaPopupShow(id,triggerParentId,construct,'popup_div');
			
			var oldWidgetId = 'FW_Usage_'+stepback;
			var widgetId = $j('#scriptPopupWidget_'+i);	
			var scriptId = $j('#script_'+i);	
			var info = $j('#popup_'+i);
			
			widgetId.html(scriptId.html());
			if(ajaxstatus==true)
			{
				if(triggerParent.attr("mainuri")!='')
				{
					scriptId.remove();
					MTVN.Flux.Widgets.loadEach('#ModuleVideoList_'+i);
				}
			}
		
			i += 1;
			trigger.hover(
			  function (e) 
			  {
				triggerParent.addClass('vidlist_high');				
				var inbOffset  = triggerParent.offset();
				var initPosX = inbOffset.left;
				var initPosY = inbOffset.top;
							
				var scriptInfo = scriptId;
				
				if(scriptInfo!=null)
				{
					if(ajaxstatus!=true)
					{
							widgetId.html(scriptId.html());
					}
					posX = parseInt(initPosX) + ((triggerParent.width()-info.width())/2);
					posY = parseInt(initPosY) - info.height();
					
					info.css({
							  left: posX+'px',
							  top: posY+'px',
							  display: 'block'
							 });
				}
			  }, 
			  function (e) {
				triggerParent.removeClass('vidlist_high');
				info.css({
						  display: 'none'
						 });
                return false;
			});
			trigger.click(function () {
					document.location.href = triggerParent.attr("mainurl");
			});
			 
		});		
	}
}

function dynaPopupShow(tip_id, atagId,info,classname)
{
	try{
		var browser = navigator.appName;
		var divNodeW = document.createElement("div");
		divNodeW.setAttribute('id',tip_id);
		
		document.body.appendChild(divNodeW);
		
		$j(divNodeW).addClass(classname);
		
		var tooltipDiv = document.getElementById(tip_id);
		tooltipDiv.innerHTML = info;
	}
	catch(e){}
}



function dynaAjaxCall(module,reciever)
{
	var xmlhttp = "";
	var paintData = $j('#'+reciever);
	var x = document.getElementById(module.id);
	var i = x.selectedIndex;
	var url = x.options[i].value;
	
	$j('#'+reciever+' #Module2_AjaxLoader').css({display:'inline'});
	
	$j.get(url, {}, function(data) {
		$j(".popup_div").remove();
		$j('#'+reciever+' #Module2_AjaxLoader').css({display:'none'});
		paintData.html();
		paintData.replaceWith(data);
		MTV.VidPopup.init(true);
	});
}


function getTwitterFeed(url,reciever,loader)
{
	$j('#'+loader+' #Module2_AjaxLoader').css({display:'inline'});
	$j.get(url.replace(/&amp;/g,'&'), {}, function(data) {
		$j('#'+loader+' #Module2_AjaxLoader').css({display:'none'});
		$j('#'+reciever).html(data);
	});	
}

function getAjaxModule(url,reciever,loader)
{
	$j('#'+loader+' #Module2_AjaxLoader').css({display:'inline'});
	$j.get(url.replace(/&amp;/g,'&'), {}, function(data) {
		$j('#'+loader+' #Module2_AjaxLoader').css({display:'none'});
		$j('#'+reciever).html(data);
	});	
}

function runTwitterFeedUpdate(url,parent,recieverHeader,loader,interval)
{
	setTimeout(function()
	{
		//$j('#'+recieverHeader).css({display:'inline'});
		//$j('#'+recieverHeader+' #ReFresh').css({display:'inline'});
		var searchvalue = $j('#'+parent+' li:nth-child(0) img').attr("posted");
		//var searchvalue = "Mon, 19 Oct 2009 17:19:42";
		$j.get(url.replace(/&amp;/g,'&'), {}, function(data) {
								
			var arrayData = new Array(data);
			for(var i = 0; i<arrayData.length; i++)
			{
				if(arrayData[i].indexOf(searchvalue))
				{
					//alert("true");
					$j('#'+recieverHeader+' #ReFresh').slideDown();
					$j('#'+recieverHeader+' #ReFresh a').html('<b>REFRESH '+i+' NEW POSTS</b>');
				}
				else
				{
					$j('#'+recieverHeader+' #ReFresh').slideUp();
				}
			}
			runTwitterFeedUpdate(url,parent,recieverHeader,loader,interval);
			
		});
	}, interval);
}


function renderFbFanBox(profile_id,stream,connections,width,height)
{
	document.write('<fb:fan profile_id="'+profile_id+'" stream="'+stream+'" connections="'+connections+'" width="'+width+'" height="'+height+'"></fb:fan>');	
}
