if(!Array.indexOf){
    Array.prototype.indexOf = function(obj){
        for(var i=0; i<this.length; i++){
            if(this[i]==obj){
                return i;
            }
        }
        return -1;
    }
}


function getFlash(name) {
	return (window[name]) ? window[name] : document[name];
}

function parseAnchors()
{
	var items = document.getElementsByTagName("a");
	var i = items.length;
	var a;
	while(i-- > 0)
	{
		items[i].onmouseover = anchorOver;
		items[i].onmouseout = anchorOut;
	}
}

function anchorOver()
{
	if(getFlash("HarajukuLovers")){
		try{
			getFlash("HarajukuLovers").htmlAnchorOver();
		}catch(e)
		{
			
		}
	}
}
function anchorOut()
{
	if(getFlash("HarajukuLovers")){
		try{
			getFlash("HarajukuLovers").htmlAnchorOut();
		}catch(e)
		{
			
		}
	}
}
parseAnchors();




var buttons = ["logo", "create", "gallery", "twitter", "facebook", "about", "privacyHeader", "termsHeader"];

function showButtons(names, ignore)
{
	changeButtonVisibility(names, ignore, true);
}

function hideButtons(names, ignore)
{
	changeButtonVisibility(names, ignore, false);
}

function changeButtonVisibility(names, ignore, visible)
{
	var i, p;
	if(!names) names = [].concat(buttons);
	names = [].concat(names);
	if(ignore)
	{
		ignore = [].concat(ignore);
		i = ignore.length;
		while(i-- > 0)
		{
			if((p = names.indexOf(ignore[i])) >= 0) names.splice(p, 1);
		}
	}
	i = names.length;
	var e;
	while(i-- > 0)
	{
		e = document.getElementById(names[i]);
		if(!e) continue;
		e.style.display = (visible)?"block":"none";
	}
}

hideButtons();



//------------------------------------------------------------------------------
//	FACEBOOK
//------------------------------------------------------------------------------
//FB.Event.subscribe("auth.statusChange", fbStatusChange);

var fbConnected = false;

function fbLogin() {
	FB.login(function(response) {
		if (response.session) {
			if (response.perms) {
				// user logged in and granted permissions
			} else {
				// logged in, but didn't grant permissions
			}
		} else {
			// user did not log in
		}
	}, {perms: 'publish_stream,offline_access'});
}

function fbStatusChange(response)
{
	switch(response.status)
	{
		case "connected":
			fbConnected = true;
			break;
		case "notConnected":
		case "unknown":
			fbConnected = false;
			break;
	}
}

function fbGetLoginStatus()
{
	FB.getLoginStatus(fbLoginStatus);
}

function fbGetStatus()
{
	FB.getSession();
}

function fbLoginStatus(response)
{
	if (response.session) {
		alert("Connected");
	} else {
		alert("not Connected");
	}
}
