var n;
var is_scrolling = false;

function URL(text)
{
	return encodeURIComponent(text);
}

function facebookConnectPopUp(app_id, redirect_uri)
{
	final_url = "https://graph.facebook.com/oauth/authorize?client_id=" + URL(app_id)
		+ "\x26redirect_uri=" + URL(redirect_uri) + "\x26type=user_agent\x26display=popup\x26scope=email";

	window.open(final_url, "_new", "width=550,height=350,left=300,top=150");
}

function change_background(site, category,mouse_type)
{
	if ( mouse_type == '1' )
	{
		document.getElementById(category).style.background='#FFFFFF';
	}
	else
	{
		if ( site == '001.0' )
		{
			document.getElementById(category).style.background='url(/area/001.0/images/nav_bg.jpg)';
		}
		else if ( site == '001.1' )
		{
			document.getElementById(category).style.background='url(/area/001.1/images/nav_bg.jpg)';
		}
		else if ( site == '003.0' )
		{
			document.getElementById(category).style.background='url(/area/003.0/images/nav_bg.jpg)';
		}
		else if ( site == '002.0' )
		{
			document.getElementById(category).style.background='url(/area/003.0/images/nav_bg.jpg)';
		}
		else if ( site == '004.0' )
		{
			document.getElementById(category).style.background='url(/area/004.0/images/nav_bg.jpg)';
		}
		else if ( site == '005.0' )
		{
			document.getElementById(category).style.background='url(/area/005.0/images/nav_bg.jpg)';
		}
		else if ( site == '006.0' )
		{
			document.getElementById(category).style.background='url(/area/006.0/images/nav_bg.jpg)';
		}
		else if ( site == '008.0' )
		{
			document.getElementById(category).style.background='url(/area/008.0/images/nav_bg.jpg)';
		}
		else
		{
			document.getElementById(category).style.background='url(/area/000.0/images/nav_bg.jpg)';
		}
	}
}

function slide_banner()
{

	bf = document.getElementById("banner_float");
	bd = document.getElementById("site_body");

	bdebugger = document.getElementById("debugger");

	t_limit = 146;
	b_limit = 112;

	s = bd.scrollTop;
	sh = bd.scrollHeight;
	ch = bd.clientHeight;

	if (s < t_limit)
	{
		n = 0;
	}
	else if (sh - s - ch < b_limit)
	{
		n = s - t_limit + ((sh - s - ch) - b_limit);
	}
	else
	{
		n = s - t_limit;
	}

	if (bdebugger)
	{
		bdebugger.innerText = "" + s + " " + sh + " " + ch + " " + n;
	}

	if (!is_scrolling) { window.setTimeout("update_scroll()", 2); is_scrolling = true; }
}

function update_scroll()
{
	s = parseInt(bf.style.top);

	sn = s + (n > s ? Math.ceil((n - s) / 4) : Math.floor((n - s) / 4));

	bf.style.top = sn + "px";

	is_scrolling = (sn != n);

	if (is_scrolling) window.setTimeout("update_scroll()", 2);

}

function createCookie(name,value,days) {
        if (days)
	{
                var date = new Date();
                date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
                var expires = "; expires=" + date.toGMTString();
        }
        else
	{
		var expires = "";
	}
	document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for(var i=0;i < ca.length;i++) {
                var c = ca[i];
                while (c.charAt(0)==' ') c = c.substring(1,c.length);
                if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
        }
        return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

//  Facebook global components (to be deprecated)
var mv_movie;
var mv_rating;

//  Facebook global components (to be deprecated)
function popUpDiv(divName, val1, val2, val3)
{
	var sb = document.getElementById('site_body');
	var bd = document.getElementById('DIV_ALL');
	var pd = document.getElementById(divName);

	var logged_in = document.getElementById('LOGGED_IN').value;

	if (logged_in == 'N')
	{
		if(val3 == "profile_thumbs")
		{
			pd = document.getElementById('DIV_FB_LOGIN');
		}
		else
		{
			pd = document.getElementById('DIV_USER_LOGIN');		
		}
	}

	bd.style.display = 'block';
	//bd.style.top = sb.scrollTop;
	bd.style.width = sb.clientWidth;
	bd.style.height = document.body.scrollHeight;
	
	pd.style.display = 'block';
	pd.style.top = sb.scrollTop + 50;
	pd.style.zIndex = 30;
	
	if (divName == "DIV_MOVIE_RATING")
	{
		//window.alert(document.getElementById('LOGGED_IN').value);
		//window.alert(val1);
		deselectRating();
		mv_movie = val1;
		mv_rating = "";
		document.getElementById("mv_review").value = "";
		document.getElementById("flex_movies_div").style.visibility = 'hidden';
	}
	else if (divName == "DIV_BIZ_REVIEW")
	{
		var formBiz = document.getElementById('form_biz');
		formBiz.value = val1;
		var lsRegExp = /\+/g;
		document.getElementById('biz_review_company_name').innerHTML = unescape(val2).replace(lsRegExp, " ");
		fixedBiz=unescape(val2).replace(lsRegExp, " ");
		
		document.getElementById('biz_review_type').innerHTML = "You Like ";
		document.getElementById('review').value='';
		document.getElementById('review').focus();
	}
	
	try
	{
		document.getElementById('banner_float').style.display='none';
	}
	catch(err)
	{}

}

function closePopUp(divName)
{
	document.getElementById('DIV_ALL').style.display = 'none';
	document.getElementById(divName).style.display = 'none';
	if (divName == "DIV_MOVIE_RATING")
	{
		document.getElementById('flex_movies_div').style.visibility = 'visible';
	}
	else if(divName == "DIV_BIZ_REVIEW")
	{
		document.getElementById('biz_profile_like').style.display = 'block';
	
	}
}

function doRating(rating)
{

        for (star = 0;star <= 8; star = star + 1)
        {
                if (rating >= star)
                {	
			if (star >= rating && star == 0)
			{
                                document.getElementById('DIV_' + star).style.background = "url(/images/star_on_zero.png)";
				mv_rating = rating;
			}
                        else if (star % 2 == 1 && star != 0)
                        {
                                document.getElementById('DIV_' + star).style.background = "url(/images/star_on_left.png)"; 
                        }
                        else if (star != 0)
                        { 
                                document.getElementById('DIV_' + star).style.background = "url(/images/star_on_right.png)";
                        }
                }
                else
                {
			if (star == 0)
			{
                                document.getElementById('DIV_' + star).style.background = "url(/images/star_on_zero.png)"; 
			}
                        else if (star % 2 == 1)
                        {
                                document.getElementById('DIV_' + star).style.background = "url(/images/star_off_left.png)";
                        }
                        else
                        {
                                document.getElementById('DIV_'+ star).style.background = "url(/images/star_off_right.png)";
                        }
                }
        }
	document.getElementById('DIV_SELECTED_rating').innerHTML = rating/2 + ' Stars (click to choose)';

}

function selectRating(rating)
{
	//window.alert(rating/2);
	mv_rating = rating;
	//document.getElementById('rating_container').removeEventListener('mouseout',deselectRating,false);
	document.getElementById('rating_container').onmouseout=function(){};
	document.getElementById('DIV_SELECTED_rating').innerHTML = 'You chose: ' + rating/2 + ' Stars';
        
	for (star = 0;star <= 8; star = star + 1)
	{
		if (rating >= star)
		{
			if (star >= rating && star == 0)
			{
				document.getElementById('DIV_' + star).style.background = "url(/images/star_on_zero.png)";
				document.getElementById('DIV_' + star).onmouseover=function(){};
			}
			else if (star % 2 == 1 && star != 0)
			{
				document.getElementById('DIV_' + star).style.background = "url(/images/star_on_left.png)";
				document.getElementById('DIV_' + star).onmouseover=function(){};
			}
			else if (star != 0)
			{
				document.getElementById('DIV_' + star).style.background = "url(/images/star_on_right.png)";
				document.getElementById('DIV_' + star).onmouseover=function(){};
			}
		}
		else
		{
			if (star == 0)
			{
				document.getElementById('DIV_' + star).style.background = "url(/images/star_on_zero.png)";
				document.getElementById('DIV_' + star).onmouseover=function(){};
			}
			else if (star % 2 == 1)
			{
				document.getElementById('DIV_' + star).style.background = "url(/images/star_off_left.png)";
				document.getElementById('DIV_' + star).onmouseover=function(){};
			}
			else
			{
				document.getElementById('DIV_' + star).style.background = "url(/images/star_off_right.png)";
				document.getElementById('DIV_' + star).onmouseover=function(){};
			}
		}
	}
}

function deselectRating()
{
	for (star = 0; star <= 8; star = star + 1)
	{
		if (star == 0)
		{ 
			document.getElementById('DIV_' + star).style.background = "url(/images/star_off_zero.png)"; 
		}
		else if (star % 2 == 1)
		{
			document.getElementById('DIV_' + star).style.background = "url(/images/star_off_left.png)";
		}
		else
		{
			document.getElementById('DIV_' + star).style.background = "url(/images/star_off_right.png)";
		}
	}
}

