// JavaScript Document



function go(url)
{
	window.location=url;
}


function deleteComment(id)
{
	$.get(root_url+"api/deleteComment.php", { id: id } );
	$('#comment-'+id).slideUp();
	return false;
}


function boxHTML(title, html)
{
	return "<div><div class='block'><ul class='tabs_container'><li class='tabactive'><span>"+title+"</span></li></ul><div class='tabs_box'></div><div class='body' style='padding:20px;'>"+html+"</div></div></div>";
}

function getPageScroll()
{

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}



function getPageSize()
{	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight)
	{	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	}
	else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}



function msg_popup(title, html, width, height, overlayClose)
{
	
	try
	{
		if(overlayClose)
		{
			title += "<img onclick='closePopup();' src='"+root_url+"public/images/close.png' alt='X' style='z-index:3;cursor: pointer;margin-top:-15px;margin-right:-15px;float:right;' />";
		}
	
		
		html = boxHTML(title, html);
	
		jsOverlay(true);
		
		if($('#js_o_popup'))
		{
			var objLightbox = $('#js_o_popup');
		}
		else
		{
			var objLightbox = document.createElement('div');
			objLightbox.id = 'js_o_popup';
			objLightbox.className = 'popup';
			$('#js_html').appendChild(objLightbox);
		}
		
		objLightbox = $(objLightbox);
		objLightbox.html(html);
		
		objLightbox.fadeIn('slow');
		
		objLightbox.css('position', 'fixed');
		objLightbox.css('z-index', '3');
		
		if(width != '')
		{
			objLightbox.width(width);
		}
		if(height != '')
		{
			objLightbox.height(height);
		}

		var arrayPageSize = getPageSize();
		var arrayPageScroll = getPageScroll();
		
		my_height = objLightbox.height();
		my_width = objLightbox.width();
		
		objLightbox.centerOnScreen();
		
	}
	catch(e)
	{
		alert(e);
	}
}

function closePopup()
{
	try
	{
		var objLightbox = $('#js_o_popup');
		objLightbox.fadeOut('slow');
		objLightbox.hide();
		
		jsOverlay(false);
		
		if(typeof this.onPopupClose == 'function')
		{
			this.onPopupClose();
		}
	}
	catch(e)
	{
	}
}

function jsOverlay(d)
{
return;
	if(d)
	{
		$('#js_overlay').show();
		$('#js_overlay').css('opacity', 0);
		$('#js_overlay').fadeTo('slow', .65);
		$('#js_overlay').css('height', '800px');
		$('#js_overlay').css('width', '800px');
		$('#js_overlay').css('position', 'fixed');
		$('#js_overlay').css('top', '0');
		$('#js_overlay').css('left', '0');
	}
	else
	{
		$('#js_overlay').fadeOut('slow');
	}
}

var moreMenuOpen = false;
function moreMenu()
{
	moreMenuOpen = !moreMenuOpen;
	if(moreMenuOpen)
	{
		$("#nav_more,#nav_more_active").attr("id", "nav_more_active");
		$('#moreMenu').show();
		
		var pos = $("#nav_more_active").offset();  
		pos.top = pos.top + 20;
		$('#moreMenu').css("top", pos.top);
		$('#moreMenu').css("left", pos.left);

		
	}
	else
	{
		$("#nav_more,#nav_more_active").attr("id", "nav_more");
		$('#moreMenu').hide();
	}
	
	return false;
}

function signUp()
{
	$.get(root_url+"start.php", { random: "1" },
	  	function(data){
	  		var data = "<div id='startUpPop'>"+data+"</div>";		
			jsOverlay(true);

	    		$("#js_html").html($("#js_html").html()+data);
	    		window.scroll(0,0);
	    		$('#startUpPop').centerOnlyOnScreen();
	    	}
	);
	
	return false;

}

function createRoomHome()
{

	if($('#createInputText').val() == "Choose a name for your chatroom...")
	{
		var room = "";
		var uv = "1234567890abcdefghijklmnopqrstuvwxyz";
		for ( var i = 0; i < 5; i++ ) {
			room += uv.charAt ( Math.floor(Math.random()*33 ) );
		}
		$("#createInputText").val(room);
    	}
    
}


function changeEmbedSize(parameter)
{
	$('#videoBox').css("background", "transparent");
	if(parameter == 0)
	{
		$('#videoBox').css('height', '450px');
	}
	else if(parameter == 1 || parameter == 2)
	{
		$('#videoBox').css('height', '650px');
	}
	else if(parameter == 3)
	{
		$('#videoBox').css('height', '590px');
	}
	else if(parameter == 4)
	{
		$('#videoBox').css('height', '550px');
	}
	else if(parameter >= 5 && parameter <= 8)
	{
		$('#videoBox').css('height', '670px');
	}
	else if(parameter >= 8 && parameter <= 12)
	{
		$('#videoBox').css('height', '800px');
	}
	else if(parameter >= 5)
	{
		var height = 670;
		var divi = ((parameter-5)/4);
		height = height + (120 * (divi));
		$('#videoBox').css('height', height+"px");
	}
}

function popPreview(url)
{
	var preview = window.open(url, url, 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=900,height=700');
	return false;
}


$(document).ready(function()
{
	$('#globalSearchBox').focus(function() { $('#globalSearchBox').css('opacity', 1); });
	$('#globalSearchBox').blur(function() { $('#globalSearchBox').css('opacity', .45); });
	$('#globalSearchBox').css('opacity', .45); 
	
	$('.opacity45').css('opacity', .45);
	$('.footer-repeat img').css("opacity", .75);
	
	$("#nav_more,#nav_more_active").click(moreMenu);
	$('#catChange, #sortChange').change(function() { this.form.submit(); });
});

function tcinit()
{
	$('#menuButton').click(menuClick);
	$('#userDropdown').click(menuClose);
}

var menuShow = false;
function menuClick()
{
	if(!menuShow)
	{
		$('#userDropdown').show();
		$('#menuButton').attr("src", root_url+"public/images/menu_active.png");
		$('#menuButton').css("z-index", "99");
		$('#userDropdown').css("z-index", "98");
		menuShow = true;
	}
	else
	{
		menuClose();
		menuShow = false;
	}
}

function menuClose()
{
	if(menuShow)
	{
		menuShow = false;
		$('#userDropdown').hide();
		$('#menuButton').attr("src", root_url+"public/images/menu.png");
	}
}

$(document).ready(tcinit);