﻿var title = new Array();
	title["public"]='Add file to your public Folder';
	title["unpublic"]='Unshare';
	title["delete0"]='Delete Folder';
	title["delete1"]='Delete File';
	title["rename"]='Rename';
	title["tag"]='Tags';
	title["unzip"]='UnZip';
	
var desc = new Array();
	desc["public"]='Are you shure to shared this file or folder ? Anyone subscribed to this Folder will receive this file or folder in their Updates tab.';
	desc["unpublic"]='People who have access to this file/folder will no longer have access.Are you sure you want to unshare?';
	desc["delete0"]='Delete folder and all subfolders?';
	desc["delete1"]='Are you sure you would like to delete this file?';
	desc["rename"]='Enter a new name here:';
	desc["tag"]='Enter your Tags here: (comma delimited)';
	desc["unzip"]='Are you sure you would like to Unzip this Zip file?';
	
function ActWindow(url, windheight, windwidth, windtop, windleft){
	var windowParam ;
	windowParam = "" ;
	windowParam += "height=" + windheight + "," ;
	windowParam += "width=" + windwidth + "," ;
	windowParam += "statusbar=no,toolbar=no,personalbar=no,menubar=no,titlebar=no,scrollbars=no,locationbar=no,resizable=no," ;
	windowParam += "top=" + windtop + "," ;
	windowParam += "left=" + windleft ;
	strSend = window.open(url,null, windowParam) ;
	if (strSend == "" || strSend == null)
		return false ;    // user canceled
	else
		return true ;
}
		
		
function openWin(htmlFile,htmlWidth,htmlHeight,htmltop,htmlleft)
{
	if(document.all){htmlWidth+=5;htmlHeight+=10;}
	 ActWindow(htmlFile,htmlHeight,htmlWidth,htmltop,htmlleft);
}
	
function show_drag(f){	
	
	var tmp=$('body').width();
	temp=(tmp/2)-240;
	
	/*$('#GB_overlay').show();
	$('#GB_DragDrop').css('left',(tmp/2)-250);
	$('#GB_DragDrop').fadeIn('fast');*/
	
	//openWin('pages/dragdrop_tpl.php?f='+f,550,450,180,temp);
	 openWin('applet_http_core.php?f='+f,550,450,180,temp);
	
}

function sendEmailMsg(id){

	var tmp='#msg_'+id;
	var tmp2='#email_'+id+' form';
	
	$(tmp).html('');

	$.ajax({
			url: "include/process.php",
			type: "POST",
			data: $(tmp2).serialize(),
			async: false,
			success: function(msg){
				/*$('.emailPlaceHolder').fadeOut('slow');
				$('#GB_overlay3').hide();	*/
			$(tmp).html(msg);
			//alert(msg);
			}
		});

}


function setClick3(){	
		
	$('.commDel').unbind('click');
	
	$(".commDel").click( function() {
		var cid=$(this).siblings('input.cid').val();
		var fid=$(this).siblings('input.f-id').val();
		var tmpP=$(this).parent('p');
		$.ajax({
				type: "POST",
				url: "include/process.php",
				data: "cid="+cid+"&task=commentDel",
				success: function(msg){
					tmpP.remove();
				}
			});
	} );

}
	
function setClick2(){
	
	
	$('.docbutton3').unbind('click');
	
	$(".docbutton3").click( function() {
		var objBTN = $(this);
		var txt=$(objBTN).parent('form').children('input.cmttxt').val();
		var cid=$(objBTN).parent('form').children('input.cmtid').val();
		if (txt=='') {alert('please enter your comment'); return false;}
		$.ajax({
				type: "POST",
				url: "include/process.php",
				data: "ftxt="+txt+"&task=comment&fid="+cid,
				success: function(msg){
					var temp='commentHolder'+cid;
					$.ajax({
							url: "ajaxLoad.php?fid="+cid,
							type: "GET",
							data: 'path=pages/files_comment_list.php',
							success: function(msg){
								$('#'+temp).html(msg);
							}
						});
				}
			});
	} );	
	
	


}	

function showPic(){
	$('#GB_overlay').show();
	var tmp=$('body').width();
	$('#GB_photobox').css('left',(tmp/2)-250);
	$('#GB_photobox').fadeIn('fast');
}
	
	
function setClick(){

	/*$('#photoTool').unbind('click');
	$('#photoTool').click(function(){
	alert('rt');
		$('#GB_overlay').show();
		var tmp=$('body').width();
		$('#GB_photobox').css('left',(tmp/2)-250);
		$('#GB_photobox').fadeIn('fast');
	});*/

	$('.closePopup').click(function(){
			$('#GB_folder').fadeOut('normal');
			$('#GB_upload').fadeOut('normal');
			$('#GB_popup').fadeOut('normal');
			$('#GB_popupTxt').fadeOut('normal');
			$('#GB_musicbox').fadeOut('normal');
			$('#GB_musicbox').fadeOut('normal');
			$('#GB_zipbox').fadeOut('normal');
			$('#GB_DragDrop').fadeOut('normal');
			$('#GB_photobox').fadeOut('normal');
			$('#GB_movebox').fadeOut('normal');
			$('.sharePlaceHolder').fadeOut('normal');
			$('.emailPlaceHolder').fadeOut('normal');
			$('#GB_overlay').hide();
			$('#GB_overlay2').hide();
			$('#GB_overlay3').hide();
		});

	$('.actionFile').click(function(e){
		var temp = $(this).children('input').val();
		var temp2 = $(this).siblings('input').val();
		$('#actionID').val(temp);
		$('#actionType').val(temp2);
		$('.contextMenu').hide();
		var top=e.pageY; 
		var left=e.pageX-165; 
		$('#myMenu').css('top',top);	
		$('#myMenu').css('left',left);	
		$('#myMenu').addClass("contextMenu");	
		$('#myMenu').slideDown('slow');
	});
	
	$('.actionFile2').click(function(e){
		var temp = $(this).children('input').val();
		var temp2 = $(this).siblings('input').val();
		$('#actionID').val(temp);
		$('#actionType').val(temp2);
		$('.contextMenu').hide();
		var top=e.pageY; 
		var left=e.pageX-165; 
		$('#myMenu2').css('top',top);	
		$('#myMenu2').css('left',left);	
		$('#myMenu2').addClass("contextMenu");	
		$('#myMenu2').slideDown('slow');
	});
	
	$('div.fileStatus').unbind('click');
	$('div.fileStatus').toggle(function(){
		$(this).siblings('div.sharePlaceHolder2').slideDown('slow');
	}, function(){
		$(this).siblings('div.sharePlaceHolder2').slideUp('slow');
	});
	$("div.fileStatus").hover(function(){
		$(this).addClass("hover");
	},function(){
		$(this).removeClass("hover");
	});	
	
	$('div.fileComment').unbind('click');
	$('div.fileComment').toggle(function(){
		$(this).parent('li').children('div.commentPlaceHolder').slideDown('slow');
	}, function(){
		$(this).parent('li').children('div.commentPlaceHolder').slideUp('slow');
	});
	$("div.fileComment").hover(function(){
		$(this).addClass("hover");
	},function(){
		$(this).removeClass("hover");
	});	
	
	
	$('div.fileActions').unbind('click');
	$('div.fileActions').toggle(function(){
		$(this).siblings('div.actionsPlaceHolder').slideDown('slow');
		//$('div.sharePlaceHolder').slideUp('slow');
	}, function(){
		$(this).siblings('div.actionsPlaceHolder').slideUp('slow');
	});
	$("div.fileActions").hover(function(){
		$(this).addClass("hover");
	},function(){
		$(this).removeClass("hover");
	});	
	
	$("div.orangActions").hover(function(){
		$(this).addClass("orangActionsH");
	},function(){
		$(this).removeClass("orangActionsH");
	});	
	
		
	$('#closeMsg').click(function(e){
		$('#msgHolder').hide('fast');
	});
	
	$('.imgOrange').imghover();
	
	$('div#ZipTool').unbind('click');
	$('div#ZipTool').click(function(){
		setCheckAction('checkbox');
	});
	$("div#ZipTool").hover(function(){
			$(this).addClass("ZipToolhover");
		},function(){
			$(this).removeClass("ZipToolhover");
	});	
	
	$('div#delTool').unbind('click');
	$('div#delTool').click(function(){
		setDelAction('checkbox');
	});
	$("div#delTool").hover(function(){
			$(this).addClass("delToolhover");
		},function(){
			$(this).removeClass("delToolhover");
	});	
	
	$('div#dragTool').unbind('click');
	$('div#dragTool').click(function(){
		show_drag();
	});
	$("div#dragTool").hover(function(){
			$(this).addClass("delToolhover");
		},function(){
			$(this).removeClass("delToolhover");
	});	
	
	$('#closeDrag').unbind('click');
	$('#closeDrag').click(function(){
		window.location.reload();
	});
	
	$('div.orangActions').unbind('click');
	
	$('.web').unbind('click');
	
	$("div.orangActions").click(function(){
		$(this).children('div.actionBox').slideDown('slow');
	},function(){
	});
	
	$("div.orangActions").hover(function(){
	},function(){
		$(this).children('div.actionBox').slideUp('fast');
	});
	
	
	$("div.buttonTree").unbind('click');
	$("div.buttonTree").click(function(){
		if($(this).attr('opened') == '0'){
			openPaths();
			$(this).attr('opened', '1');
		}
		else{
			closePaths();
			$(this).attr('opened', '0');
		}
	});
	
		
		
}

function showPopupMove( id, type){
	$('#GB_overlay2').show();
	var tmp=$('body').width();
	$('#GB_movebox').css('left',(tmp/2)-250);
	$('#GB_movebox').fadeIn('normal');
	if (type==0) $('#CopyBtn').css('display', 'none');
	else $('#CopyBtn').css('display', 'block');
	$('#sorceID').val(id);
	$('#targetID').val(0);
	$('#actionType2').val(type);
	$('#rootName').html('My Files');
}

function showPopupAction(action, id, type){
	$('#GB_overlay2').show();
	var tmp=$('body').width();
	$('#GB_popup').css('left',(tmp/2)-250);
	$('#GB_popup').fadeIn('normal');
	var tmp2=id;
	var tmp3=type;
	$('#fType').val(tmp3);
	$('#task').val(action);
	if (action=='delete'){
		$('.text').html(title[action+tmp3]);
		$('.logintext').html(desc[action+tmp3]);
	}else{
		$('.text').html(title[action]);
		$('.logintext').html(desc[action]);
	}
	$('#fID').val(tmp2);
}

function showWebLink(id){
	$('#GB_overlay3').show();
	$('.actionBox').hide();
	var tmp=$('body').width();
	var divtemp='#share_'+id;
	$(divtemp).css('left',(tmp/2)-250);
	$(divtemp).fadeIn('normal');
	$('.actionBox').hide();
}

function showEmail(id){
	$('#GB_overlay3').fadeIn('normal');
	$('.actionBox').hide();
	$('.sharePlaceHolder').fadeOut('normal');
	var tmp=$('body').width();
	var divtemp='#email_'+id;
	var divmsg='#msg_'+id;
	$(divmsg).html('');
	$(divtemp).css('left',(tmp/2)-250);
	$(divtemp).fadeIn('normal');
	$('.actionBox').hide();
}

function showPopupAction2(action, id, type, old){
	$('#GB_overlay2').show();
	var tmp=$('body').width();
	$('#GB_popupTxt').css('left',(tmp/2)-250);
	$('#GB_popupTxt').fadeIn('slow');
	$('.logintext2').removeClass('logintexterror');
	
	var tmp2=id;
	var tmp3=type;
	$('#fType2').val(tmp3);
	$('#task2').val(action);

	$('#newname').val(old);
	$('.text2').html(title[action]);
	$('.logintext2').html(desc[action]);

	$('#fID2').val(tmp2);
}


function doLogin(){
$("#loadingH").ajaxStart(function(){
			$('#resultHolder').html('');
			$(this).show();
		});
			
		$("#loadingH").ajaxStop(function(){
			$(this).fadeOut('fast');
		});

		var t1 = $('#user_email').val();
		var t2 = $('#user_pass').val();
		var t3 = $("#loginFrom :checkbox").val();
		var action = $('#taskH').val();
		
		var data = $("#loginFrom").serialize();

		 $('#resultHolderH').hide();
		 var response = $.ajax({
				url: "include/process.php",
				type: "POST",
				data: "user_email="+t1 +"& user_pass="+t2+"&task=login&remember="+t3 ,
				async: false
		}).responseText;
		 if (response=='yes') {
			window.location="?page=files";
		}else{
			$('#resultHolderH').html(response);
			$('#resultHolderH').fadeIn('slow');
		}	
}

function appendPaths(p){
	var response = $.ajax({
		url: "include/process.php",
		type: "POST",
		data: "task=showTree&parrent="+p,
		async: false,
		success: function(msg){
			var temp='#Li_'+p;
			$(temp).children('ul').remove();
			$(temp).append(msg);
		}
	});
}

function setPaths(name, id){
	$('#rootName').html(name);
	$('#targetID').val(id);
	$('#treeList').slideUp('normal');
}

function openPaths(){
	var response = $.ajax({
		url: "include/process.php",
		type: "POST",
		data: "task=showTree&parrent=0",
		async: false,
		success: function(msg){
			$('#treeList').html(msg);
			$('#treeList').slideDown('normal');
		}
	});
}

function closePaths(){
	$('#treeList').slideUp('normal');
}


$(document).ready(function() {



	jQuery.preloadImages = function(){
	  for(var i = 0; i<arguments.length; i++)
	  {
	    jQuery("<img>").attr("src", arguments[i]);
	  }
	}
	
	$.preloadImages("images/login_submit_h.gif", "images/sign_btn_h.gif",  "images/loading.gif",  "images/context_orange_o.gif");

	$('A[rel="external"]').click( function() {
        window.open( $(this).attr('href') );
        return false;
    });
	
	$('div#msgHolder').gradient({ topcolor: '#ff5500', bottomcolor: '#ffffff', horizontal: false, opacity: 80});
	
	/* actions for top  menu*/
///////////////////////////////////////////////////////////////////////////////////////	
	$('ul.links li').ahover();

	
	
			/* actions for file context meny*/
///////////////////////////////////////////////////////////////////////////////////////
	$('body').click(function(){
		$('.contextMenu').hide();
	});
	
	
	
	function showPopup(action){
		$('#GB_overlay2').show();
		var tmp=$('body').width();
		$('#GB_popup').css('left',(tmp/2)-250);
		$('#GB_popup').fadeIn('slow');
		var tmp2=$('#actionID').val();
		var tmp3=$('#actionType').val();
		$('#fType').val(tmp3);
		$('#task').val(action);
		if (action=='delete'){
			$('.text').html(title[action+tmp3]);
			$('.logintext').html(desc[action+tmp3]);
		}else{
			$('.text').html(title[action]);
			$('.logintext').html(desc[action]);
		}
		$('#fID').val(tmp2);
	}
	
	
	$(".contextMenu").hover(function(){
	},function(){
		// $(".contextMenu").fadeOut('fast');
	});
	
	$('.quit').click(function(){
		$(".contextMenu").fadeOut('fast');
	});
	
	$('.public').click(function(){
		showPopup('public');
	});
	
	$('.unpublic').click(function(){
		showPopup('unpublic');
	});
	
	$('.delete').click(function(){
		showPopup('delete');
	});
	
	
	$("#myMenu LI").hover(function(){
		$(this).addClass("hover");
	},function(){
		$(this).removeClass("hover");
	});	
	
	$("#myMenu2 LI").hover(function(){
		$(this).addClass("hover");
	},function(){
		$(this).removeClass("hover");
	});	
	
	setClick();
	
	
	
///////////////////////////////////////////////////////////////////////////////////////	
			/* actions for UPLOAD, NEW Folder POPUP*/
///////////////////////////////////////////////////////////////////////////////////////
	
	$('.folderTool').click(function(){
		$('#GB_overlay2').fadeIn('normal');
		var tmp=$('body').width();
		$('#GB_folder').css('left',(tmp/2)-250);
		$('#GB_folder').fadeIn('slow');
		$('#folderTxt').removeClass('logintexterror');
		$('#loginerror').hide();
		$('#folder_name').val('');
		
	});
	
	$('.uploadTool').click(function(){
		$('#GB_overlay2').fadeIn('normal');
		var tmp=$('body').width();
		$('#GB_upload').css('left',(tmp/2)-250);
		$('#GB_upload').fadeIn('fast');
	});
	
	
	$('.musicTool').click(function(){
		$('#GB_overlay').fadeIn('normal');
		var tmp=$('body').width();
		$('#GB_musicbox').css('left',(tmp/2)-250);
		$('#GB_musicbox').fadeIn('fast');
	});

	
	
	$('.zipTool').click(function(){
		$('#GB_overlay').fadeIn('normal');
		var tmp=$('body').width();
		$('#GB_zipbox').css('left',(tmp/2)-250);
		$('#GB_zipbox').fadeIn('fast');
	});
	
	
	$('.webUnsharebtn').click(function(){
		$('.sharePlaceHolder').fadeOut('fast');
	});
		
	
///////////////////////////////////////////////////////////////////////////////////////

	/*$('.cornered').corner();*/
	
	$("#loading").ajaxStart(function(){
		$('#resultHolder').html('');
		$(this).show();
	});		
		
	$("#loading").ajaxStop(function(){
		$(this).fadeOut('fast');
	});

		
	$('#signBtn').click(function(){	

		 $('#resultHolder').hide();
		 var response = $.ajax({
				url: "include/process.php",
				type: "POST",
				data: $(".leftHalf input").serialize(),
				async: false
		}).responseText;
		
		if (response=='ok'){
		
			var t1 = $('#email').val();
			var t2 = $('#pass1').val();
			
			var response = $.ajax({
				url: "include/process.php",
				type: "POST",
				data: "user_email="+t1 +"& user_pass="+t2+"&task=login" ,
				async: false
			}).responseText;
			 if (response=='yes') {
				window.location="?page=files";
			}else{
				$('#resultHolderH').html(response);
				$('#resultHolderH').fadeIn('slow');
			}	
			
		}else{

			document.getElementById('capImg').src = 'include/securimage_show.php?sid=' + Math.random();
			document.getElementById('capthca').value='';
			$('#resultHolder').html(response);
			$('#resultHolder').fadeIn('slow');
		 
		 }
				
	});
	
	
	$("#user_pass").keypress(function (e) {
      if (e.which == 13) {
        doLogin();
    }
	});
	
	$("#user_email").keypress(function (e) {
      if (e.which == 13) {
        doLogin();
    }
	});

	
	
	$('#loginBtn').click(function(){

		doLogin();
			
	});
	
	
	$("div.settingLink").hover(function(){
			$(this).addClass("settingLinkHover");
		},function(){
			$(this).removeClass("settingLinkHover");
	});	
	
	/*$('.settingLink').click(function(){
		var tmp=$(this).children('input').val();
		$.ajax({
			url: "ajaxLoad.php",
			type: "GET",
			data: 'path=pages/'+tmp+'.php',
			success: function(msg){
				$('#settingPlaceHolder').html(msg);
			}
		});
	});*/
	
	$('#setNewPass').click(function(){	

		 $('#resultHolder').hide();
		 var response = $.ajax({
				url: "include/process.php",
				type: "POST",
				data: $("#settingPlaceHolder input").serialize(),
				async: false
		}).responseText;
		 $('#resultHolder').html(response);
		 $('#resultHolder').fadeIn('slow');
				
	});
	
	
	
	$('#setNewEmail').click(function(){	

		 $('#resultHolder').hide();
		 var response = $.ajax({
				url: "include/process.php",
				type: "POST",
				data: $("#settingPlaceHolder input").serialize(),
				async: false
		}).responseText;
		 $('#resultHolder').html(response);
		 $('#resultHolder').fadeIn('slow');
				
	});
	
	
	
	
	  
 });
 

 
