/* Player controls */

function favorites(uri, type, id)
{ 
	if(userid != 0 )
	{
		tb_show('',uri +'/addToFavorites/' + type + '/' + id+ '?TB_iframe=true&width=310&height=150');
	}
	else
	{ 
		var url = uri+'/notLoggedIn';		
		tb_show('',url+'?TB_iframe=true&width=410&height=160'); 
	}	
}

function share(uri, type, id) 
{
	if(userid != 0)
	{		
		var url 	= uri+'/share/'+ type +'/'+ id;
		var mywindow= window.open(url, "my_window", "width=475,height=340")
		mywindow.moveTo(100,200);
	}
	else
	{
		var url = uri+'/notLoggedIn';		
		tb_show('',url+'?TB_iframe=true&width=410&height=160'); 
	}	
}

function postVideo(uri, type, id) 
{
	if(userid != 0)
	{		
		var url = uri+'/postVideo/'+ type +'/'+ id;
		tb_show('',url+'?TB_iframe=true&width=310&height=150');
	}
	else
	{
		var url = uri+'/notLoggedIn';		
		tb_show('',url+'?TB_iframe=true&width=410&height=160'); 
	}	
}

function comments(param) 
{
/*	if(typeof( window[ 'video_id' ] ) != "undefined" )
	{
		var url="http://"+media_uri+'/commentVideo/'+video_id;
		tb_show('',url+'?TB_iframe=true&width=600&height=400');
	}
	else
	{
		var url="http://"+media_uri+'/notLoggedIn';
		tb_show('',url+'?TB_iframe=true&width=300&height=120'); 
	}    */	
	window.location.href = '#bottom';
	$('#body').focus();
}

function flag(uri,video_id) 
{	
	if(userid != 0)
	{
		var url 	= uri+'/report_content/video/'+video_id;
		var mywindow= window.open(url, "my_window", "width=473,height=368")
		mywindow.moveTo(100,200);
	}
	else
	{
		var url = uri+'/notLoggedIn';
		tb_show('',url+'?TB_iframe=true&width=410&height=160'); 
	}
}

function onClickPlay() {
  var temp = document.getElementById('ultimate_street_player');
	temp.play()
}

function onClickPause() {
  var temp = document.getElementById('ultimate_street_player');
	temp.pause()
}

function onClickStop() {
  var temp = document.getElementById('ultimate_street_player');
	temp.stop()
}

function setRating(param) 
{ 
	if( window[ 'user_id' ] != "0" )
	{
		$(document).ready(function() 
				{ 
					$.get( "http://"+ media_uri+"/rateVideo/"+video_id+"/"+param, "", function callback(data) 
					        {		
								tb_show('',"http://"+media_uri+'/showMessage/6/?TB_iframe=true&width=310&height=150');
					        }  
						 );  
			    });
	}
	else
	{
		var url="http://"+media_uri+'/notLoggedIn';
		tb_show('',url+'?TB_iframe=true&width=410&height=160'); 
	}		
}

function thumbClick(param) 
{
	if (param) 
	{  
		imgTitle = top_video[param].mediaTitle;					
		document.location.href = "http://" +  media_uri + "/video/" + param + '/' + imgTitle;
	}
}

function addWikiPhotos(uri, aid)
{ 
	if(userid != 0 )
	{
		var url		 = uri +'/article/addPhoto/' + aid;		
		tb_show('', url+'?TB_iframe=true&width=331&height=250')
	}
	else
	{ 
		var url = uri+'/notLoggedIn';
		tb_show('',url+'?TB_iframe=true&width=410&height=160'); 
	}	
}

function editWikiPhotos(uri, aid)
{ 
	if(userid != 0 )
	{		
	/*	photopos = slideshow.getPictureIndex();
		photoid  = mediaArray[photopos];		*/
		var url  =  uri +'/article/editPhoto/' + aid + '/' +current_pict_id;
		//var mywindow = window.open(url, "my_window", "width=640,height=600");
		tb_show('', url+'?TB_iframe=true&width=613&height=586')
	}
	else
	{ 
		var url = uri+'/notLoggedIn';
		tb_show('',url+'?TB_iframe=true&width=410&height=160'); 
	}	
}
function shareWikiPhotos(uri,aid)
{ 		
		if(userid != 0)
		{		
			var url = uri+'/share/image_wiki/'+current_pict_id+'/'+aid;
			var mywindow=window.open(url, "my_window", "width=475,height=340");			
			mywindow.moveTo(100,200);
		}
		else
		{
			var url = uri+'/notLoggedIn';		
			tb_show('',url+'?TB_iframe=true&width=410&height=160'); 
		}	
}
function shareSpotlightedPhotos(uri,media_id,userid)
{ 		
		if(userid != 0)
		{		
			var url = uri+'/share/image_spotlighted/'+media_id+'/'+userid;
			var mywindow=window.open(url, "my_window", "width=475,height=340");			
			mywindow.moveTo(100,200);
		}
		else
		{
			var url = uri+'/notLoggedIn';		
			tb_show('',url+'?TB_iframe=true&width=410&height=160'); 
		}	
}
function shareNewsPhotos(uri,iid)
{ 
		if(userid != 0)
		{		
			var url = uri+'/share/image_news/'+current_pict_id+'/'+iid;
			var mywindow=window.open(url, "my_window", "width=475,height=340");
			mywindow.moveTo(100,200);
		}
		else
		{
			var url = uri+'/notLoggedIn';		
			tb_show('',url+'?TB_iframe=true&width=410&height=160'); 
		}	
}
function favoriteWikiPhotos(uri)
{ 		
		favorites(uri, 'image', current_pict_id);
}
function favoriteNewsPhotos(uri)
{ 		
		favorites(uri, 'image', current_pict_id);
}
function showRentDialog()
{
	tb_remove();
	//setTimeout(,1000)
	//alert('http://'+media_uri+'/rentdialog/'+video_id+'?TB_iframe=true&width=472&height=318');
	setTimeout("tb_show('Rent a moovie', 'http://'+media_uri+'/rentdialog/'+video_id+'?TB_iframe=true&width=472&height=318')",1000);
}
function showBuyPopup()
{
	if ( typeof( window[ 'is_free' ] ) != "undefined" ) 
	{
		if(is_free != '1')
		{
			tb_show('Buy Moovie', 'http://'+media_uri+'/buyPopup?TB_iframe=true&width=375&height=116');
		}
	}
}
/** 
 * The Javascript code for social bookmarks.
 */
var sorcialBookmarks = {};
if(Drupal.jsEnabled) {
  /**
   * Function to share on Facebook
   */
	sorcialBookmarks.shareOnFacebook = function() {
		u=location.href;
		t=document.title;
		window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');   
	} 
	sorcialBookmarks.shareOnMyspace = function() {
			u=location.href;
			t=document.title;
			var targetUrl = 'http://www.myspace.com/index.cfm?fuseaction=postto&' + 't=' + encodeURIComponent(t)
			+ '&u=' + encodeURIComponent(u) ;
			window.open(targetUrl,'sharer','toolbar=0,status=0,width=626,height=436');			
	} 
	sorcialBookmarks.addToFurl = function() {
			u=location.href;
			t=document.title;
			var targetUrl = 'http://www.diigo.com/post?title=' + encodeURIComponent(t)
			+ '&url=' + encodeURIComponent(u) ;
			window.open(targetUrl,'AddToFurl','toolbar=0,status=0,width=626,height=436');
	} 
	sorcialBookmarks.addToSpurl = function() {
			u=location.href;
			t=document.title;
			var targetUrl = 'http://www.spurl.net/spurl.php?title=' + encodeURIComponent(t)
			+ '&url=' + encodeURIComponent(u) ;
			window.open(targetUrl,'AddToSpurl','width=770px,height=500px,status=0,location=0,left=0,top=80,resizable=1,scrollbars=1');
	} 
	sorcialBookmarks.addToDigg = function() {
			u=location.href;
			t=document.title;
			var targetUrl = 'http://digg.com/submit?topic=autos&title=' + encodeURIComponent(t)
			//var targetUrl = 'http://digg.com/submit?phase=2'
			//+ '&url=http://www.topstreetracing.com/home' ;
			+ '&url=' +encodeURIComponent(u) ;
			window.open(targetUrl,'AddToDigg','width=770px,height=500px,status=0,location=0,left=0,top=80,resizable=1,scrollbars=1');
	} 
	sorcialBookmarks.addToDelIcio = function() {
			u=location.href;
			t=document.title;
			var targetUrl = 'http://del.icio.us/post?title=' + encodeURIComponent(t)
			+ '&url=' + encodeURIComponent(u) ;
			window.open(targetUrl,'AddToDelIcio','width=770px,height=500px,status=0,location=0,left=0,top=80,resizable=1,scrollbars=1');
	} 

	sorcialBookmarks.addToBlinkList = function() {
			u=location.href;
			t=document.title;
			var targetUrl = 'http://www.blinklist.com/index.php?Action=Blink/addblink.php&title=' + encodeURIComponent(t)
			+ '&url=' + encodeURIComponent(u) ;
			window.open(targetUrl,'AddToBlinkList','width=770px,height=500px,status=0,location=0,left=0,top=80,resizable=1,scrollbars=1');
	} 
	sorcialBookmarks.addToSimpy = function() {
			u=location.href;
			t=document.title;
			var targetUrl = 'http://simpy.com/simpy/LinkAdd.do?title=' + encodeURIComponent(t)
			+ '&href=' + encodeURIComponent(u) ;
			window.open(targetUrl,'AddToSimpy','width=770px,height=500px,status=0,location=0,left=0,top=80,resizable=1,scrollbars=1');
	} 
	sorcialBookmarks.addToYMYWeb = function() {
			u=location.href;
			t=document.title;
			//var targetUrl = 'http://myweb2.search.yahoo.com/myresults/bookmarklet?t=' + encodeURIComponent(t)
			var targetUrl = 'http://bookmarks.yahoo.com/toolbar/savebm?opener=tb&t=' + encodeURIComponent(t)
			+ '&u=' + encodeURIComponent(u) ;
			//+ '&u=' + 'http://www.qloud.com/artist/Katy-Perry--a_1155736.php' ;
			window.open(targetUrl,'AddToYMYWeb','width=770px,height=500px,status=0,location=0,left=0,top=80,resizable=1,scrollbars=1');
	} 
	sorcialBookmarks.addToGoogle = function() {
			u=location.href;
			t=document.title;
			var targetUrl = 'http://fusion.google.com/add?title=' + encodeURIComponent(t)
			+ '&feedurl=' + encodeURIComponent(u) ;
			window.open(targetUrl,'AddToGoogle','width=770px,height=500px,status=0,location=0,left=0,top=80,resizable=1,scrollbars=1');
	} 
	sorcialBookmarks.addToStumbleupon = function() {
			u=location.href;
			t=document.title;
			var targetUrl = 'http://www.stumbleupon.com/submit?url=' + encodeURIComponent(u)+'&title='+encodeURIComponent(t) ;
			window.open(targetUrl,'addToStumbleUpon','width=770px,height=500px,status=0,location=0,left=0,top=80,resizable=1,scrollbars=1');
	} 
}

var time=null;

function showBubble(bubble, objRef, dX, dY)
{	
	if(bubble!=null)
	{
		bubble.style.display="block";
	}
	try
	{  // alert(getLeft(objRef)); alert(dX);
		bubble.style.left = parseInt(getLeft(objRef) + dX ) + "px";
	}
	catch(e){};
	try
	{   //alert(getTop(objRef)); alert(dY);
		if((getTop(objRef) + dY < document.body.scrollTop) && !$.browser.safari)
		{ 
			bubble.style.top = document.body.scrollTop + "px";
		}
		else
		{  
			bubble.style.top = parseInt(getTop(objRef) + dY) + "px";
		}
	}
	catch(e){};
	if(time){
		clearTimeout(time); 	
	}
}

function onMouseOverBubble(){
	if(time){
		clearTimeout(time); 	
	}
}


function hideBubble(bubble)
{
	time=setTimeout('closeBubble()',100);
}
function closeBubble(){
	var bubble=document.getElementById('thebubble');
	if(bubble!=null)
	{
		bubble.style.display="none";
	}
	bubble=document.getElementById('thebubble2');
	if(bubble!=null)
	{
		bubble.style.display="none";
	}	
}

function getTop(elem)
{
	if (elem.offsetParent)
		{
			return elem.offsetTop + getTop(elem.offsetParent);
		}
	else
		{
			return elem.offsetTop;
		}
}

function getLeft(elem)
{
	if (elem.offsetParent)
	{
		return elem.offsetLeft + getLeft(elem.offsetParent);
	}
	else
	{
		return elem.offsetLeft;
	}
}

function colorMe(nr, className)
{
	for(var i=1; i<=nr; i++)
		$('#star'+i).attr('class', className+'Full');
	
	for(var i=nr+1; i<=5; i++)
		$('#star'+i).attr('class', className+'Empty');
}
function colorMeNot(nr, className)
{
	for(var i=1; i<=nr; i++)
		$('#star'+i).attr('class', className+'Empty');
}
function showToolTip(bubble, objRef, dY)
{	
	if(bubble!=null)
	{
		bubble.style.display="block";
	}
	try
	{
		bubble.style.left = parseInt(getLeft(objRef) + objRef.offsetWidth/2 - bubble.offsetWidth/2 ) + "px";
		bubble.style.top = parseInt(getTop(objRef)+dY) + "px";
	}
	catch(e){};
}

//car vs car search
function removeValue(nr)
{
	if ($('#edit-car'+nr).val() == 'type any car')
	{
		$('#edit-car'+nr).val('');
		$('#edit-car'+nr).addClass('txtonfocus');
	}
}

function addValue(nr)
{
	if ($('#edit-car'+nr).val() == '')
	{
		$('#edit-car'+nr).val('type any car');
		$('#edit-car'+nr).removeClass('txtonfocus');
	}
}
function removeCarValue(nr)
{ 
	if ($('#edit-car'+nr).val() == 'type any car')
	{
		$('#edit-car'+nr).val('');
		$('#edit-car'+nr).addClass('txtonfocus');
	}
}

function addCarValue(nr)
{
	if ($('#edit-car'+nr).val() == '')
	{
		$('#edit-car'+nr).val('type any car');
		$('#edit-car'+nr).removeClass('txtonfocus');
	}
}
function run_search()
{
	var car1 = $('#edit-car1').val();
	if (car1 != 'type any car' && car1 != '')
		$("#racecar").submit();
	else
	{		
		$('#edit-car1').focus();
	}
}
$(document).ready(function() {
	var opt={}
	
	opt.resultsClass='ac_results_car2';
	/*jQuery(function() {
		 jQuery("#edit-car1").suggest(url+"/carvscar/search/1", '',false);	  
	});
	jQuery(function() { 
		jQuery("#edit-car2").suggest(url+"/carvscar/search/2",opt,false); 
	});*/
	if ($.browser.mozilla) {
		$('#edit-car2').keypress(process_Key);	// onkeypress repeats arrow keys in Mozilla/Opera
	} else
		$('#edit-car2').keydown(process_Key);	
	
});

function process_Key(e) 
{  
	if(e.keyCode == 13 )
	{  
		run_search();
		return false;
	}	
}
