var tempTimeout = 0;
var closeTimeout = null;
function HS_VChatRequest( type, param )
{
   var oXHR = zXmlHttp.createRequest();
   oXHR.open("post", MainURL+"modules/vchat.php", true);
   oXHR.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
   oXHR.onreadystatechange = function() {
       if (oXHR.readyState == 4) {
           HS_ShowVChatWindow( oXHR.responseText );
       }
   }

   var post = null;

   switch(type){
       case 'invite':
           post = "action=invite&per_id="+param;
           break;
       case 'cancel':
           HS_CloseVChatWindow();
           post = "action=cancel&session_id="+param;
           break;
       case 'accept':
           HS_CloseVChatWindow();
           post = "action=accept&session_id="+param;
           break;
       case 'decline':
           HS_CloseVChatWindow();
           post = "action=decline&session_id="+param;
           break;
       case 'ignore':
           HS_CloseVChatWindow();
           post = "action=ignore&session_id="+param;
           break;
       case 'invited':
           post = "action=invited&session_id="+param;
           break;
       case 'unavailable':
           post = "action=unavailable&session_id="+param;
           break;
       case 'open_invited':
           post = "action=open_invited&session_id="+param;
           break;
       case 'open_invitee':
           post = "action=open_invitee&session_id="+param;
           break;
       case 'declined':
           post = "action=declined&session_id="+param;
           break;
       case 'close':
           HS_CloseVChatWindow();
           break;
   }

   oXHR.send( post );
}

function HS_HandleVChatSignal( code )
{
   var details = code.split(".");
   HS_VChatRequest( details[0], details[1] );
}

function HS_AlignVChatWindow()
{
   var ns = (document.layers)?1:0;
   var Position = new Array;
   if(ns){
       Position['Left'] = window.innerWidth + window.pageXOffset - 5;
       Position['Top']  = window.innerHeight + window.pageYOffset - 5;
   }//if
   else{
       Position['Left'] = document.body.clientWidth + document.body.scrollLeft - 5;
       Position['Top']  = document.body.clientHeight + document.body.scrollTop - 5;
   }//else
   var VChatWindow = document.getElementById("vchat_window");
   VChatWindow.style.top = (Position['Top']/2) - (VChatWindow.offsetHeight/2);
   VChatWindow.style.left = (Position['Left']/2) - (VChatWindow.offsetWidth/2);
   if(tempTimeout)
       setTimeout( "HS_AlignVChatWindow()", 500 );
}
function HS_ShowVChatWindow( content )
{
   if(content){
       var element = document.getElementById( "vchat_window" );
       element.innerHTML = content;
       tempTimeout = 1;
       HS_AlignVChatWindow();
       element.style.visibility = "visible";
   }
}

function HS_CloseVChatWindow()
{
   tempTimeout = 0;
   var element = document.getElementById( "vchat_window" );
   element.innerHTML = "";
   element.style.visibility = "hidden";
}

function HS_LaunchVChat( session_id )
{
   HS_CloseVChatWindow();
   url = MainURL+"modules/vchat.php?action=launch&session_id="+session_id;
   var newwin = window.open(url, "vchat", "width=550,height=330,scrollbars=no,menubar=no,resizable=no,location=no");
   newwin.focus();
}

var NotiTimer = new Array;
var BlindIDCount = 0;
function MM_preloadImages() { //v3.0
   var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}//MM_preloadImages
function HS_LaunchIM(){
   url = MainURL+"modules/instant_messenger.php?action=launch";
   imwin = window.open(url, "HSIM_CONSOLE", "width=250,height=350,scrollbars=no,menubar=no,resizable=no,location=no");
   imwin.focus();
}//HS_LaunchIM
function HS_LaunchChat(per_id){
   url = MainURL+"modules/instant_messenger.php?action=chat&per_id="+per_id;
   var newwin = window.open(url, per_id, "width=500,height=350,scrollbars=no,menubar=no,resizable=no,location=no");
   newwin.focus();
}//HS_LaunchChat
function HS_BuildBlind(){
   BlindIDCount++;
   var BlindID = "BLIND_"+BlindIDCount;
   var BlindTemplate = document.getElementById("BLIND").innerHTML;
   var Temp = new Array;
   Temp = BlindTemplate.split("BLIND");
   BlindTemplate = Temp.join(BlindID);
   var BlindContent = "<div class='blind' id='"+BlindID+"'>"+BlindTemplate+"</div>";
   var BlindsHandler = document.getElementById("blinds_panel");
   if(BlindsHandler.offsetHeight >= 117){
       BlindsHandler.style.top = parseInt(BlindsHandler.style.top) - 117;
   }//if
   else{
       BlindsHandler.style.top = parseInt(BlindsHandler.style.top) - 117 + BlindsHandler.offsetHeight;
   }//else
   BlindsHandler.innerHTML+= BlindContent;
   return BlindID;
}//HS_BuildBlind

function HS_FadeBlind(BlindID,Direction){
   var Timer = 0;
   var Speed = 50;
   if(Direction == "in"){
       HS_ChangeAlign('blinds_panel',3);
       for(var i=10;i<=100;i=i+10){
           setTimeout("HS_ChangeOpacity(" + i + ",'" + BlindID + "')",(Timer * Speed));
           Timer++;
       }//for
   }//if
   else if(Direction == "out"){
       for(var i=90;i>=0;i=i-10){
           setTimeout("HS_ChangeOpacity(" + i + ",'" + BlindID + "')",(Timer * Speed));
           Timer++;
       }//for
       setTimeout("HS_ChangeAlign('blinds_panel',1)",Timer * Speed);
       setTimeout("HS_RemoveBlind('"+BlindID+"')",Timer * Speed);
   }//else if
}//HS_FadeBlind
function HS_ChangeOpacity(OpacityValue,BlindID){
   var BlindObjStyle = document.getElementById(BlindID).style;
   BlindObjStyle.opacity = (OpacityValue / 100);
   BlindObjStyle.MozOpacity = (OpacityValue / 100);
   BlindObjStyle.KhtmlOpacity = (OpacityValue / 100);
   BlindObjStyle.filter = "alpha(opacity=" + OpacityValue + ")";
}//HS_ChangeOpacity
function HS_PosBlinds(){
   var ns = (document.layers)?1:0;
   var Position = new Array;
   if(ns){
       Position['Left'] = window.innerWidth + window.pageXOffset - 5;
       Position['Top']  = window.innerHeight + window.pageYOffset - 5;
   }//if
   else{
       Position['Left'] = document.body.clientWidth + document.body.scrollLeft - 5;
       Position['Top']  = document.body.clientHeight + document.body.scrollTop - 5;
   }//else
   var BlindsPanel = document.getElementById("blinds_panel");
   if(BlindsPanel) {
   	BlindsPanel.style.top = Position['Top'] - BlindsPanel.offsetHeight;
   	BlindsPanel.style.left = Position['Left'] - 180;
   	setTimeout("HS_PosBlinds()",500);
   }
}//HS_PosBlinds
function HS_ChangeAlign(BlindID,Pos){
   var BlindObjStyle = document.getElementById(BlindID).style;
   BlindObjStyle.zIndex = Pos;
}//HS_ChangeAlign
function HS_RemoveBlind(BlindID){
   var BlindObj = document.getElementById(BlindID);
   BlindObj.innerHTML = "";
}//HS_RemoveBlind
function HS_CloseNotification(BlindID){
   clearTimeout(NotiTimer[BlindID]);
   HS_FadeBlind(BlindID,'out');
}//HS_CloseNotification

function HS_SwapClass( target, cName )
{
	target.className = cName;
}

function HS_viewPhoto( mem_id, pho_id )
{
	if( $("#photoContainer").length > 0 ) {
		$.ajax({
			type: "POST",
			url: "ajax.php",
			data: "module=photos&act=view&pho_id=" + pho_id,
			success: function(html){
				$("#photoContainer").html('');
				$("#photoContainer").append(html);
			}
		});

	} else {
		window.location = MainURL + "index.php?page=photos&section=browse&per_id=" + mem_id + "&pho_id=" + pho_id;
	}
}
