(function(a) {
    a.fn.vTicker = function(b) {
        var c = {
            speed: 700,
            pause: 4000,
            showItems: 3,
            animation: "",
            mousePause: true,
            isPaused: false,
            direction: "up",
            height: 0
        };
        var b = a.extend(c, b);
        moveUp = function(g, d, e) {
            if (e.isPaused) {
                return
            }
            var f = g;
            var h = f.children(".entry:first").clone(true);
            if (e.height > 0) {
                d = f.children(".entry:first").outerHeight()
            }
            f.animate({
                top: "-=" + d + "px"
            },
            e.speed,
            function() {
                a(this).children(".entry:first").remove();
                a(this).css("top", "0px")
            });
            if (e.animation == "fade") {
                f.children(".entry:first").fadeOut(e.speed);
                f.children(".entry:eq(" + e.showItems + ")").hide().fadeIn(e.speed)
                if (e.height == 0) {
                    f.children(".entry:eq(" + e.showItems + ")").hide().fadeIn(e.speed)
                }
            }
            h.appendTo(f)
        };
        moveDown = function(g, d, e) {
            if (e.isPaused) {
                return
            }
            var f = g;
            var h = f.children(".entry:last").clone(true);
            if (e.height > 0) {
                d = f.children(".entry:first").outerHeight()
            }
            f.css("top", "-" + d + "px").prepend(h);
            f.animate({
                top: 0
            },
            e.speed,
            function() {
                a(this).children(".entry:last").remove()
            });
            if (e.animation == "fade") {
                if (e.height == 0) {
                    f.children(".entry:eq(" + e.showItems + ")").fadeOut(e.speed)
                }
                f.children(".entry:first").hide().fadeIn(e.speed)
            }
        };
        return this.each(function() {
            var f = a(this);
            var e = 0;
            f.css({
                overflow: "hidden",
                position: "relative"
            });
            if (b.height == 0) {
                f.children(".entry").each(function() {
                    if (a(this).outerHeight() > e) {
                        e = a(this).outerHeight()
                        ex = a(this).height()
                    }
                });
                f.children(".entry").each(function() {
                    a(this).height(ex)
                });
                f.height(e * b.showItems)
            } else {
                f.height(b.height)
            }
            var d = setInterval(function() {
                if (b.direction == "up") {
                    moveUp(f, e, b)
                } else {
                    moveDown(f, e, b)
                }
            },
            b.pause);
            if (b.mousePause) {
                f.bind("mouseenter",
                function() {
                    b.isPaused = true
                }).bind("mouseleave",
                function() {
                    b.isPaused = false
                })
            }
        })
    }
})(jQuery);
function toggleFlash(state) {
	var objects = this.doc.getElementsByTagName("object");
	for (var i = 0; i < objects.length; i++) {
		objects[i].style.visibility = (state == "hide") ? 'hidden' : 'visible';
	}
	var embeds = this.doc.getElementsByTagName("embed");
	for (var i = 0; i < embeds.length; i++) {
		embeds[i].style.visibility = (state == "hide") ? 'hidden' : 'visible';
	}
}
function querySt(ji) 
{
    hu = window.location.search.substring(1);
    gy = hu.split("&");
    for (i=0;i<gy.length;i++) 
    {
	ft = gy[i].split("=");
	    if (ft[0] == ji) 
	    {
		return ft[1];
	    }
    }
}
function showSearch(str)
{
	$.doTimeout( 'typing', 50, function(){
		if (str.length<=1)
		{ 
			$("#content_box").hide(150);
			return;
		}
		else if (!document.getElementById("results"))
		{
			document.getElementById("content_box").innerHTML = '<div id="results"></div>';
			$("#content_box").show(150);
		}
		else
		{
			$("#content_box").show(150);
		}

		var http = GetXmlHttpObject();
		var url = "ajax.aspx";
		var params = "search="+str+"&rnd="+Math.random();
		http.open("POST", url, true);

		//Send the proper header information along with the request
		http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		http.setRequestHeader("Content-length", params.length);
		http.setRequestHeader("Connection", "close");

		http.onreadystatechange = function() {//Call a function when the state changes.
			if(http.readyState == 4 && http.status == 200) {
				document.getElementById('results').innerHTML = http.responseText
				$("#content_box").animate( { height: $("#results").height() }, 150, "swing" );
			}
		}
		http.send(params);

	});
} 

function getComment(comment_id, page_id)
{
	http = GetXmlHttpObject();
	var url="ajax.aspx?c=" + comment_id + "&p=" + page_id + "&rnd="+Math.random();
	http.onreadystatechange= function() { 
		if (http.readyState==4)
		{
			document.getElementById('comment_'+comment_id).innerHTML = http.responseText;
		}
		
	}
	http.open("GET",url,true);
	http.send(null);
}

function getAComment(comment_id, r, page_id)
{
	http = GetXmlHttpObject();
	var url="ajax.aspx?c=" + comment_id + "&rmv="+r+"&p=" + page_id + "&rnd="+Math.random();
	http.onreadystatechange= function() { 
		if (http.readyState==4)
		{
			document.getElementById('comment_'+comment_id).innerHTML = http.responseText;
		}
		
	}
	http.open("GET",url,true);
	http.send(null);
}


function postComment(comment_id, page_id)
{
	http = GetXmlHttpObject();
	var url = "ajax.aspx";
	var params = "post_comment=" + comment_id + "&page_id=" + page_id;
	if(document.getElementById('author_'+comment_id))
		params += "&author=" + encodeURIComponent(document.getElementById('author_'+comment_id).value);
	if(document.getElementById('subject_'+comment_id))
		params += "&subject=" + encodeURIComponent(document.getElementById('subject_'+comment_id).value);
	if(document.getElementById('http_'+comment_id))
		params += "&http=" + encodeURIComponent(document.getElementById('http_'+comment_id).value);
	if(document.getElementById('email_'+comment_id))
		params += "&email=" + encodeURIComponent(document.getElementById('email_'+comment_id).value);
	if(document.getElementById('message_'+comment_id))
		params += "&message=" + encodeURIComponent(document.getElementById('message_'+comment_id).value);
		
	params += "&rnd="+Math.random();
	http.open("POST", url, true);

	//Send the proper header information along with the request
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");

	http.onreadystatechange = function() {//Call a function when the state changes.
		if(http.readyState == 4 && http.status == 200) {
			document.getElementById('comment_'+comment_id).innerHTML = http.responseText
		}
	}
	http.send(params);
}


$(document).ready(function(){
	/*
	pollHash();
	setInterval('pollHash()', 100);
	$('#mainmenu .ajax').click(function(){
			loadContent("/" + $(this).attr('href'), true);
		return false;
	});
	*/
	$('#media_import').vTicker({animation: 'fade'});
});

function loadContent(href, clicked)
{
	if(clicked)
	{
		recentHash = "#" + href;
		window.location.hash = href;
	}

	if(href.indexOf('page/') != -1)
	{
		var _Href = "/" + href.substr(href.indexOf('page/'));

		var page_id = _Href.substring(_Href.indexOf('page/') + 5, _Href.indexOf('/', _Href.indexOf('page/') + 5));

		var extraparams = "";
		if(_Href.indexOf('.aspx') > -1)
			extraparams = _Href.substring(_Href.indexOf('.aspx')+5).replace('?','&');
		var params = "content=" + page_id + "&r=" + Math.random();

		//$('#outer_content').css( { height: $('#content').height() } );
		$.ajax({
			type: 'GET',
			url: "ajax.aspx",
			data: params + extraparams,
			dataType: 'html',
			timeout: 5000,
			success: function(d,s){
						$('.activeitem').removeClass('activeitem');
						$('.active').removeClass('active');
						$('#li_' + page_id).addClass('activeitem active');
						$('#a_' + page_id).addClass('activeitem active');
						$('li.activeitem').parents('li').addClass('active');
						$('li.activeitem').parents('li').children('a:first-child').addClass('active');
						
						//d = d.replace(new RegExp('ajax.aspx\\?'+params,'g'), "#");
						//d = d.replace(new RegExp('ajax.aspx\\?'+params + extraparams,'g'), "#"+_Href);
						//d = d.replace(new RegExp('"page/','g'), '"#/page/');
						$('#content').html(d);

						//$('#outer_content').animate( { height: $('#content').height() }, 150, 'swing' );
					},
			error: function(o,s,e){
						window.location = _Href.substr(1);
					}
		});
	}
	
}

var recentHash = "";
function pollHash() {

	current_url = window.location.href;
	if(current_url.indexOf("#") > -1)
		current_hash = current_url.substr(current_url.indexOf("#"));
	else
		current_hash = "";
	if(recentHash != current_hash)
	{
		recentHash = current_hash;
		window.location.hash = current_hash;

		loadContent(current_hash, false);
		
	}

}




    function getAjax(parameters, destination)
    {
	    http = GetXmlHttpObject();
	    var url="ajax.aspx?" + parameters + "&rnd="+Math.random();
 
	    http.onreadystatechange= function() { 
		    if (http.readyState==4)
		    {
			    if(destination != "")
				    document.getElementById(destination).innerHTML = http.responseText;
		    }
	    }
	    http.open("GET",url,true);
	    http.send(null);
    }
 
    function postAjax(parameters, destination)
    {
    	http = GetXmlHttpObject();
	    var url = "ajax.aspx";
   		
	    parameters += "&rnd="+Math.random();
	    http.open("POST", url, true);
 
	    http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	    http.setRequestHeader("Content-length", parameters.length);
	    http.setRequestHeader("Connection", "close");
 
	    http.onreadystatechange = function() {
		    if(http.readyState == 4 && http.status == 200) {
		    	if(destination != "")
			    document.getElementById(destination).innerHTML = http.responseText
		    }
	    }
	    http.send(parameters);
    }

 
function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}