// JavaScript Document



function $(id) 					{ return(document.getElementById(id)); }
function isset(v) 				{ return( (typeof(v)=='undefined' || v.length==0) ? false : true); }
function empty(v)				{ return( (v.length==0) ? false : true); }
function is_obj(v)				{ return( (typeof(v)=='object') ? true : false); }
function in_array(array, value)	{ for(var i in array) if(array[i] == value)	return true; }

//******************** Augment Arguments ***********************//
function augment(oSelf, oOther) {
    if (oSelf == null) {
        oSelf = {};
    }
    for (var i = 1; i < arguments.length; i++) {
        var o = arguments[i];
        if (typeof(o) != 'undefined' && o != null) {
            for (var j in o) {
                oSelf[j] = o[j];
            }
        }
    }
    return oSelf;
}
//fetch inner window size
var innerWin = new Object();
function innerWindowSize()	{
	
	if( typeof( window.innerWidth ) == 'number' ) 
	{
    //Non-IE
   	innerWin.Width = window.innerWidth;
   	innerWin.Height = window.innerHeight;
  	} 
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
	{
    //IE 6+ in 'standards compliant mode'
    innerWin.Width = document.documentElement.clientWidth;
   	innerWin.Height = document.documentElement.clientHeight;
  	} 
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
	{
    //IE 4 compatible
    innerWin.Width = document.body.clientWidth;
    innerWin.Height = document.body.clientHeight;
    }
}

//get the scrolled position
function scrolled()	{
	
	var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body;

	innerWin.scrollX = document.all? iebody.scrollLeft : pageXOffset;
	
	innerWin.scrollY = document.all? iebody.scrollTop : pageYOffset;
		
}

//find the center of the screen relative to the size of the div to be positioned
function divScreenCenter(width, height)	{
	
	//init the inner window size object
	innerWindowSize();		
	scrolled();
		
	//determine the window center		
	var horCent = Math.floor((innerWin.Width/2) - (width/2));
	var verCent = (Math.floor((innerWin.Height/2) - (height/2))) + innerWin.scrollY;
	
	//make sure the pop doesnt fall off the screen
	if(horCent < 0)
	{
		horCent = 0;
	}
	
	//make sure the pop doesnt fall off the screen
	if(verCent < 0)
	{
		verCent = 0;
	}	
	
	return{verCent:verCent, horCent:horCent};	
}
//Get the complete body size
function docSize()
{
  var b=document.body, e=document.documentElement;
  var esw=0, eow=0, bsw=0, bow=0, esh=0, eoh=0, bsh=0, boh=0;
  if (e) {
    esw = e.scrollWidth;
    eow = e.offsetWidth;
    esh = e.scrollHeight;
    eoh = e.offsetHeight;
  }
  if (b) {
    bsw = b.scrollWidth;
    bow = b.offsetWidth;
    bsh = b.scrollHeight;
    boh = b.offsetHeight;
  }
  return{w:Math.max(esw,eow,bsw,bow),h:Math.max(esh,eoh,bsh,boh)};
}
function findPosition(element) {
 
	if(typeof element != "object")
	{
		var element = document.getElementById(element);
	}
	
	//if the element has any parents
	if(element.offsetParent)  
	{
		/*runs through all the parent nodes adding each realtive offset dimensions 
		to get the elements offset from the top parent node*/
		for(var posX = 0, posY = 0; element; element = element.offsetParent) 
		{
			posX += element.offsetLeft;
			posY += element.offsetTop;
			//N.B ie and mozilla have different numbers of parents	 
		}   
	
		return [ posX, posY ];
	} 
	else //element has no parents
	{
		return [ element.x, element.y ];
	}
}
var intervalID;

function scrollMeRight(divId)	{
	
	//var divId = document.getElementById(divId);
		
	var move = function()	{
		var currentPos = divId.scrollLeft;
		divId.scrollLeft = currentPos + 5;
	}
	intervalID = setInterval(move, 20);
}
function scrollMeLeft(divId)	{
	
	//var divId = document.getElementById(divId);
		
	var move = function()	{
		var currentPos = divId.scrollLeft;
		divId.scrollLeft = currentPos - 5;
	}
	intervalID = setInterval(move, 20);
}


function scrollMe(event, divId, direction)	{
	
	//get current mouse position
	if(window.event)
	{
		var mouseX = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
	}
	else
	{
		var mouseX = event.clientX + window.scrollX;
	}
	
	//get the div position
	var divId = document.getElementById(divId);	
	
	
	if(direction == "left")
	{		
		scrollMeLeft(divId);	
	}
	else if(direction == "right") 
	{		
		scrollMeRight(divId);
	}	
}


function loadYouTube(targetId)
{
	
	jax = new ajax();
	
	ajax.prototype.callBack = function(responseText)	{
	
	$(targetId).innerHTML += responseText;
	}
	
	jax.postData("ajax_load_home_scroll.php", "");	
	
	
}

function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;
	document.getElementById(id).style.visibility = 'visible';
	
    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 

function blackOut(id, zindex)	{
	//Create the page Blackout
	var divBlackout = document.createElement("div");
	divBlackout.setAttribute("id" , id);
	document.body.appendChild(divBlackout);
	var divB = document.getElementById(id);
		
	divB.style.cssText = "position: absolute; left: 0px; top: 0px; width:" + docSize().w + "px; height: " + docSize().h + "px;"+
	"z-index:"+ zindex +"; background-color: #000; opacity: .0; filter: alpha(opacity = 0);";
	
	opacity(id, 0, 80, 400);
}

function removeBlackOut(blackoutId)	{
	
	if(typeof(blackoutId) != "object")
	{
		var blackoutObj = document.getElementById(blackoutId);
	}	
	
	document.body.removeChild(blackoutObj);
}

//init the friendCard mouse follow object
var fCard = new Object();
function fetchFriendCardInit(event, hiddenDiv)	{
	
	//assign the friend card div
	var friendCard = document.getElementById(hiddenDiv);
	fCard.div = friendCard;
	
	if(window.event)
	{
		x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
		y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
	}
	else
	{
		x = event.clientX + window.scrollX;
		y = event.clientY + window.scrollY;
	}
		
	//event listeners make the fCard move with the mouse
	if(document.attachEvent)
	{
	document.attachEvent("onmousemove", fetchFriendCardFollow);
	}
	else
	{
	document.addEventListener("mousemove", fetchFriendCardFollow, true);
	}
	
	if(fCard.div.style.display != 'block')
	{
		fCard.div.style.display = 'block';
		fCard.div.style.zIndex = 50;
	}
	
	fCard.div.style.left = (10 + x) + "px";
	fCard.div.style.top = (5 + y) + "px";
	
}
function fetchFriendCardFollow(event)	{
	
	if(window.event) 
	{
    x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
  	}
	else 
	{
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  	}
	
	//move the card
	fCard.div.style.left = (10 + x) + "px";
	fCard.div.style.top =  (5 + y) + "px";	
}
function stopFriendCardFollow(event)	{
	
	
	if(document.detachEvent)
	{
		document.detachEvent("onmousemove", fetchFriendCardFollow);
	}
	else
	{
		document.removeEventListener("mousemove", fetchFriendCardFollow, true);
	}	
	
	fCard.div.style.display = 'none';
	fCard.div.style.zIndex = 0;
}
