/* Required by JQuery */
$(document).ready(
	function()
	{
	 

		//Stuff that happens on ready
		// Hide all but_maxes by default
		$(".but_max").hide();
		$(".issue_detail").hide();
		$('#customiser').hide();
//		$('#loading').hide();




		// Show portlet button
		$('a.but_max').click(function()
			{
				$(this).parent('div').parent('div').parent('div').next('div').show('medium');
				$(this).hide();
				$(this).prev('a').show();
				return false;
			}
		);

		// Hide portlet button
		$('a.but_min').click(function()
			{
				$(this).parent('div').parent('div').parent('div').next('div').hide('medium');
				$(this).hide();
				$(this).next('a').show();
				return false;
			}
		);

		// Close portlet button
		$('a.but_close').click(function()
			{
				if (confirm('Close this widget?')) {
					$(this).parent('div').parent('div').parent('div').parent('div').hide('medium');
				}
				return false;
			}
		);

		// Show portlet controls on hover
		$('.portlet_header').hover(
			function() {
				$(this).children('div').children('div').show();
			},
			function() {
				$(this).children('div').children('div').hide();
			}
		);

		

	}
);




function submitSearch()
{

var q=document.getElementById('searchfield').value;

//q=q.replace(/?/g, " ");
q=q.replace(/:/g, " ");
//q=q.replace(///g, " ");
q=q.replace(/&/g, "and");
q=q.replace(/'/g, " ");
q=q.replace(/"/g, " ");

q=q.replace(/ /g, "-");
q=q.replace(/--/g, "-");



location.href='http://nowsup.com/'+q;


return false;
}




//controls the saving of portlets //////////////////////////////////
	    $(function()
	    {


 
	        $(".column").bind('sortupdate', function()
	        {
	            var i = 0;
	            $('.column').each(function()
	            {
	                $.cookie("col" + (i++), $(this).sortable('toArray'), { expires: 365 });
	            });
	        });




	        // check for order cookies
	        for (var i = 0; i < 3; i++)
	        {
	            var ckie = $.cookie("col" + i);

	            if (ckie && ckie != '')
	            {
	                var list = ckie.split(',');

	                for (var x = 0; x < list.length; x++)
	                {
	                    $('#'+list[x]).appendTo('#col' + i);
	                }
	            }
	        }

	        $(".column").sortable({
	            connectWith: '.column',
                   opacity: 0.7,
                   helperclass: 'sort_placeholder',

                   tolerance: 'pointer'
	        });

	 
	    });
//////////////////////////////////////////////////////////////////////////
//allows to insert ajax query

var xmlhttp;



function insertQuery(str)
{

xmlhttp=GetXmlHttpObject();

if (xmlhttp==null)
  {


  return;

  }


var url="insertQuery.php";

url=url+"?q="+str;

url=url+"&sid="+Math.random();



xmlhttp.open("GET",url,true);

xmlhttp.send(null);

}





function GetXmlHttpObject()

{

if (window.XMLHttpRequest)

  {

  // code for IE7+, Firefox, Chrome, Opera, Safari

  return new XMLHttpRequest();

  }

if (window.ActiveXObject)

  {

  // code for IE6, IE5

  return new ActiveXObject("Microsoft.XMLHTTP");

  }

return null;

}




