var last_appeared = "";
function fileOver(id)
{
	//icon_id = "icon_" + id;
	//expCollap_id = "expCollap_" + id;
	//close_id = "close_" + id;
	next_id = "next_" + id;
	prev_id = "prev_" + id;

	//$(icon_id).hide();
	//$(expCollap_id).show();
	//$(close_id).show();
	$(next_id).show();
	$(prev_id).show();
}

function fileOut(id)
{
	/*icon_id = "icon_" + id;
	expCollap_id = "expCollap_" + id;
	close_id = "close_" + id;
*/
	next_id = "next_" + id;
	prev_id = "prev_" + id;

	//$(icon_id).show();
	//$(expCollap_id).hide();
	//$(close_id).hide();
	$(next_id).hide();
	$(prev_id).hide();
}

function moveup(id, step)
{
	max_height = parseInt($(id).offsetHeight);
	current_top = parseInt( $(id).style.top ) * (-1);
	id_number = id.substr(9);
	end_id = "end_"+id;
	end_div = $(end_id);
	inner_div = $(id);
	titles_id = "titles_" + id_number;
	titles_div = $(titles_id);
	end_top = findPos(end_div)[1];
	titles_top = findPos(titles_div)[1];
	if ((end_top-titles_top-step) > step)
		inner_div.style.top = -1*current_top - step + "px";
		
}

function movedown(id, step)
{
	max_height = parseInt($(id).offsetHeight);
	current_top = parseInt( $(id).style.top );

	if (current_top < 0)
		$(id).style.top = parseInt( $(id).style.top ) + step + "px";
}

function blindedUp(id)
{
	collapse_id = "collap_" + id;
	expand_id = "expand_" + id;
	$(collapse_id).hide();
	$(expand_id).show();
}

function blindUp(id)
{
	titles_id = "titles_" + id;
	nextprv_id = "nextprev_" + id;
	nextprv_row_id = "nextprev_row_" + id;
	element = $(titles_id);

	collapse_id = "collap_" + id;
	expand_id = "expand_" + id;
	$(collapse_id).hide();
	$(expand_id).hide();

	//new Effect.BlindUp(element);
	Effect.toggle(element, 'blind', {duration: 1});
	//$(nextprv_row_id).hide();
	$(nextprv_row_id).hide();	
	/*element = $(nextprv_id);
	new Effect.BlindUp(element);
*/
	
	last_appeared="";
	
	setTimeout("blindedUp('"+id+"')",1000);
}

function appeared(id)
{
	collapse_id = "collap_" + id;
	expand_id = "expand_" + id;
	$(collapse_id).show();
	$(expand_id).hide();
}

function appear(id)
{
	nextprv_id = "nextprev_" + id;
	titles_id = "titles_" + id;
	nextprv_row_id = "nextprev_row_" + id;
	
	collapse_id = "collap_" + id;
	expand_id = "expand_" + id;
	$(collapse_id).hide();
	$(expand_id).hide();
	//Effect.BlindDown(nextprv_id, {duration: 0.3});
	
	//Effect.BlindDown(titles_id, {duration: 0.3});
	Effect.toggle($(titles_id),'blind', {duration: 1});
	$(nextprv_row_id).show();

	last_appeared = id;
	setTimeout("appeared('"+id+"')",1000);

}

function trigger(id, ajaxEffect)
{
	titles_id = "titles_" + id;
	element = $(titles_id);
	if(element.style.display == "none")
	{
		if(ajaxEffect=="1")
			blindLast();
		appear(id);
	}
	else
		blindUp(id);
}

function blindLast()
{
	if(last_appeared != "")
	{
		blindUp(last_appeared);
	}
}


function close_file(id)
{
	var close = confirm("هل بالفعل تريد غلق هذا الباب ؟");
	if(close == true)
	{
		file_id = "file_" + id;
		new Effect.SwitchOff($(file_id));
	}
}

function hout(dir, id)
{
	if(dir=="up")
	{
		image_id = "scroll_up_icon_" + id;
		image = $(image_id);
		src = new String(image.src);
		src = src.replace("scrolluphover", "scrollup");
	}
	else
	{
		image_id = "scroll_down_icon_" + id;
		image = $(image_id);
		src = new String(image.src);
		src = src.replace("scrolldownhover", "scrolldown");
	}
	$(image_id).src = src;

}

function hover(dir, id)
{
	if(dir=="up")
	{
		image_id = "scroll_up_icon_" + id;
		image = $(image_id);
		src = new String(image.src);
		src = src.replace("scrollup", "scrolluphover");
	}
	else
	{
		image_id = "scroll_down_icon_" + id;
		image = $(image_id);
		src = new String(image.src);
		src = src.replace("scrolldown", "scrolldownhover");
	}
	$(image_id).src = src;

}

function reload(id, type, category_id, typeinURL, file_id)
{
	if(type != "sendcard")
		$('material').innerHTML="<br/><br/><br/><br/><br/><br/><br/><br/><center><img src=\"img/loading.gif\"/></center><br/><br/><br/><br/><br/><br/><br/><br/>";
	if(type=="article")
	{
		new Ajax.Updater('material', "innerArticleView.php?id=" + id + "&category_id=" + category_id + "&file_id=" + file_id,
		  {
			method: 'get',
		  	evalScripts: true,
		    onFailure: function(){ alert('Something went wrong...') }
		  });
	}

	else if(type=="snd")
	{
		new Ajax.Updater('material', "innerSndView.php?id=" + id + "&category_id=" + category_id + "&typeURL=" + typeinURL + "&file_id=" + file_id,
		  {
			method: 'get',
		  	evalScripts: true,
		    onFailure: function(){ alert('Something went wrong...') }
		  });
	}

	else if(type=="vid")
	{
		new Ajax.Updater('material', "innerVidView.php?id=" + id + "&category_id=" + category_id + "&typeURL=" + typeinURL + "&file_id=" + file_id,
		  {
			method: 'get',
		  	evalScripts: true,
		    onFailure: function(){ alert('Something went wrong...') }
		  });
	}
	
	else if(type=="photo")
	{
		new Ajax.Updater('material', "innerPhotoView.php?id=" + id + "&category_id=" + category_id + "&file_id=" + file_id,
		  {
			method: 'get',
		  	evalScripts: true,
		    onFailure: function(){ alert('Something went wrong...') }
		  });
	}

	else if(type=="sendcard")
	{
		document.getElementById('submit_btn').disabled = "disabled";
		$('loadingsubmit_result').hide();
		$('loadingsubmit_img').show();
		
		frm_parameters = "addCard.php?title=" + $("title").value + "&file_id=" + file_id + "&pic_id=" + id + "&message=" + $("message").value + "&emda=" + $("emda").value + "&sender_name=" + $("sender_name").value + "&sender_mail=" + $("sender_mail").value + "&receiver_name=" + $("receiver_name").value + "&receiver_mail=" + $("receiver_mail").value + "&confirmation=" + $("confirmation").checked;

		new Ajax.Updater('loadingsubmit_result', frm_parameters,
		  {
			method: 'get',
		  	evalScripts: true,
		    onSuccess: function(){ $('loadingsubmit_img').hide(); $('loadingsubmit_result').show(); document.getElementById('submit_btn').removeAttribute('disabled') },
		    onFailure: function(){ alert('Something went wrong...'); document.getElementById('submit_btn').removeAttribute('disabled') }
		  });
	}
}

function CreateBookmarkLink(title,url) {

	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); }
	else if(window.opera && window.print) { // Opera Hotlist
		return true; }
 }

function copyToClipBoard()
{
   // the IE-way
   window.clipboardData.setData("Text", $('urlText').value);
   
}

function initialize_left_bar(category_id)
{
	var themes = new Array("white", "blue", "gray", "yellow");
	for(j=0; j < themes.length; j++)
	{
		class_name = "file_" + themes[j];
		files = document.getElementsByClassName(class_name);
		for(i=0; i < files.length; i++)
		{
			/* delete margin */
			files[i].style.margin = "0px";
			
			/*collapse all */	
			id = new String(files[i].id);
			id = id.replace("file_", "");
			if(category_id != id)
				blindUp(id);
			
			file_id = "file_" + id;
			$(file_id).style.margin="0px";
		}
	}
	last_appeared = category_id;
}

function select_input(input)
{
	input.focus();
	input.select();
}

function preloader() 
{
     // counter
     var i = 0;

     // create object
     imageObj = new Image();

     // set image list
     images = new Array();
     images[0]="http://salafvoice.com/files/img/bl-white.png"
     images[1]="http://salafvoice.com/files/img/br-white.png"
     images[2]="http://salafvoice.com/files/img/tl-white.png"
     images[3]="http://salafvoice.com/files/img/tr-white.png"
     images[4]="http://salafvoice.com/files/img/collapse.jpeg"
     images[5]="http://salafvoice.com/files/img/expand.jpeg"
     images[6]="http://salafvoice.com/files/img/next.gif"
     images[7]="http://salafvoice.com/files/img/previous.gif"

     // start preloading
     for(i=0; i<=3; i++) 
     {
          imageObj.src=images[i];
     }

} 

function findPos(obj) {
	var curleft = 0;
	var curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function validEmail(email)
{
	var re = new RegExp();
	re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+(,\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+)*$/;
	if (!re.test(email)) {
	        return false;
	}else{
	        return true;
	}
}
	

