// JavaScript Document
var CurrentID = "";
var ShowBrowseTableInterval = 420;
var MouseOverBrsB = 0;
var MouseOverBrsT = 0;
var MouseOverBrsTimer = 0;

	function loadnewentry(id)
	{
		$.ajax({
				  type: "GET",
				  url: "Ajax/MainContentEntry.php?ID="+id,
				  error: function(xmlobj, error, exception){
					alert("Error: Obj: " + xmlobj.responseText + " error: " + error + " exception: " + exception);
					},
				  success: function(mysuperhtmlvariable){
					//alert(CurrentID);
					$("#"+CurrentID).empty(); //Clear previous content.
					//alert(mysuperhtmlvariable);
					$("#"+CurrentID)[0].innerHTML = mysuperhtmlvariable; // Don't use .Append() for more than 1 line !!! [on IE].
					// Apply the new style to the Entry HTML.
				  	$('#TrailerDiv a, #ActionsDiv a, #DLEADButton').hover(
						function() { $(this).addClass('ui-state-hover'); },
						function() { $(this).removeClass('ui-state-hover'); }
					);
				  	$("#TrailerID").prettyPhoto();
				  }
				});
	}
	function loadwebentry(id,type){
		$.ajax({
				type: "GET",
				url: "Ajax/GetWebEntry.php?ID="+id+'&Type='+type,
				error: function(xmlobj, error, exception){
					alert("Error: Obj: " + xmlobj.responseText + " error: " + error + " exception: " + exception);
				},
				success: function(mysuperhtmlvariable){
				//alert(CurrentID);
				$("#WebContent").empty(); //Clear previous content.
				//alert(mysuperhtmlvariable);
				$("#WebContent")[0].innerHTML = mysuperhtmlvariable; // Don't use .Append() for more than 1 line !!! [on IE].
				}
			});

			//run the effect
			$("#WebContent").effect("slide", {}, 1000, callback);
			//callback function to bring a hidden box back
			function callback(){
				setTimeout(function(){
					$("#WebContent:hidden").removeAttr('style').hide().fadeIn();
				}, 1000);
			};
	}

    function GetRecDesc(id){
	       loadnewentry(id);
    }

	function SetUCPPopUp(pic, text){
		content = '';
		content += '<table class="UCP-PopUp" border="0">';
		content += '  <tr>';
		content += '   <td width="25"><span class="InlineIcon ui-state-default ui-corner-all ui-icon ' + pic + '"></span></td>';
		content += '    <td> ' + text + '</td>';
		content += '  </tr>';
		content += '</table>';
		Obj = document.getElementById('UCP-PopUp');
		Obj.innerHTML = content;
		Obj.style.display = "block";
	}

	function ImgError(source, type){
		source.src = "Pics/NA-"+String(type)+".png";
		source.onerror = "";
		return true;
	}

	function ShowBrowseTable(textid){
		/// Check if the mouse is still on the button, since that when it leaves it sets to - 0;
		if (MouseOverBrsB == 1){$("#BrsT" + textid).show("blind");}
	}
	function HideBrowseTable(){
		/// Check if the mouse is still on the button, since that when it leaves it sets to - 0;
		if (MouseOverBrsT == 0){$(".BrsTable").hide();}
	}

	$(document).ready(function(){
				// FundsMeter
				$("#FundsMeter").progressbar({value: donationnum});
				// Stats 
				$("#accordion").accordion({ header: "h3", active: 0 });

				//newsticker
				$(".newsticker-jcarousellite").jCarouselLite({
					vertical: true,
					visible: 5,
					auto:2500,
					speed:2000
				});

				//hover states on the static widgets
				$('#registerB, #DLButton').hover(
					function() { $(this).addClass('ui-state-error'); },
					function() { $(this).removeClass('ui-state-error');}
				);
				
				//// BROWSE DB.
				$(".BrsButton").hover(
					function(){
						$(this).removeClass("ui-state-active");
						$(this).addClass("ui-state-hover");
						$(".BrsTable").hide();
						MouseOverBrsB = 1;
						textid = $(this).text();
						clearTimeout(MouseOverBrsTimer);
						MouseOverBrsTimer = setTimeout("ShowBrowseTable('" + textid + "')",ShowBrowseTableInterval);
					},
					function(){
						$(this).removeClass("ui-state-hover");
						$(this).addClass("ui-state-active");
						MouseOverBrsB = 0;
						clearTimeout(MouseOverBrsTimer);
						MouseOverBrsTimer = setTimeout("HideBrowseTable()",ShowBrowseTableInterval);
					});

				$(".BrsTable").mouseenter(
					function(){
						MouseOverBrsT = 1;
					})
				$(".BrsTable").mouseleave(
					function(){
						$(this).hide("blind");
						MouseOverBrsT = 0;
					})
				$(".BrsLink").hover(function(){
					$(this).addClass("ui-widget-content");
					MouseOverBrsT = 1;
				});
				
				// Load the collections by ajax. + Set all ClickAble styles. [SetAllClickAble - Called once at end of loading!]
				loadbyajax("GenerateBrowseCollect.php", "BrsTCollections", null, "SetAllClickAble");
				
		   });
	
	function loadbyajax(page, container, vars, func){
		var Jtype = "GET";
		if (vars != null){
			Jtype = "POST";
		}
		$.ajax({
				type: Jtype,
				url: "Ajax/"+page,
				data: vars,
				error: function(xmlobj, error, exception){
					alert("Error: Obj: " + xmlobj.responseText + " error: " + error + " exception: " + exception);
					if (func != null){eval(func+"();");}
				},
				success: function(htmlret){
					$("#"+container).html(htmlret); // Don't use .Append() for more than 1 line !!! [on IE].
					if (func != null){eval(func+"();");}
				}
			});
	}
	
	function SetAllClickAble(){
		$('.ClickAble').hover(
			function(){
				$(this).addClass("ui-state-hover");
			},
			function(){
				$(this).removeClass("ui-state-hover");
			}
		).mousedown(function(){
			$(this).addClass("ui-state-active");
		})
		.mouseup(function(){
				$(this).removeClass("ui-state-active");
		});
	}