
//var map = null;
//var mgr = null;
//var mkr = null;
//var bounds = null;
var sliders = false;

$('#catResults').css('display','none');
$('#searchResults > p').eq(0).css('display','none');


/* Set up document on load */
$(document).ready(function(){

 

  setupsliders();

/*
  if ( gup('showcats') == 'false' ){
    hidecats();
  }
  else if ( gup('showcats') == 'true' ){
    showcats();
  }
  else {
    if ( readCookie('showcats') == '1' )
      showcats();
    else if ( readCookie('showcats') == '0' )
      hidecats();
    else
      hidecats();
  }
*/
/*  if ( gup('showmap') == 'false' ){
    hidemap();
  }
  else if ( gup('showmap') == 'true' ){
    showmap();
  }
  else {
    if ( readCookie('showmap') == '1' )
      showmap();
    else if ( readCookie('showmap') == '0' )
      hidemap();
    else
      hidemap();
  }
*/
  if ( gup('showres') == 'false' ){
    hideres();
  }
  else if ( gup('showres') == 'true' ){
    showres();
  }
  else {
    if ( readCookie('showres') == '1' )
      showres();
    else if ( readCookie('showres') == '0' )
      hideres();
    else
      showres();
  }

  $('#catStrip > div.grayButtons').click( togglecats );
 // $('#mapStrip > div.grayButtons').click( togglemap );
  $('#resStrip > div.grayButtons').click( toggleres );

});


function togglemap(){
  if ( $('#mapResults').height() > 0 )
    hidemap();
  else
    showmap();
}

function togglecats(){
  if ( $('#catResults').css('display') != 'none' )
    hidecats();
  else
    showcats();
}

function toggleres(){
  if ( $('#searchResults > p').css('display') != 'none' )
    hideres();
  else
    showres();
}

function showmap(){

  $('#mapStrip > div.grayButtons > a').html('Hide Map');
  $('#catStrip > div.grayButtons > div.openclose').html('-');


  if (GBrowserIsCompatible()) {

    $('#mapResults').width(780);
    $('#mapResults').height(300);

    map = new GMap2(document.getElementById('mapResults'));
    map.addControl(new GSmallMapControl());
    map.addControl(new GMapTypeControl());
    map.setCenter(new GLatLng(41.574361,-101.645508),4);

    window.setTimeout(drawmkrs, 0);

  }

  function drawmkrs(){
    mgr = new GMarkerManager(map);
    if ( !mkr )
      mkr = getMarkers();
    if ( !bounds ){
      bounds = new GLatLngBounds();
      for ( var i=0; i<mkr.length; i++ ) {
        if ( mkr[i].getPoint ){
          bounds.extend(mkr[i].getPoint());
        }
      }
    }
    mgr.addMarkers(mkr, 2);
    map.setZoom(map.getBoundsZoomLevel(bounds));
    map.setCenter(bounds.getCenter());
    mgr.refresh();
  }

  createCookie('showmap', 1, 14);

}

function hidemap(){

  $('#mapStrip > div.grayButtons > a').html('Show Map');
  $('#mapStrip > div.grayButtons > div.openclose').html('+');

  $('#mapResults').height(0);
      GUnload();
      mgr = null;
      map = null;
      $('#mapResults').html('');
      $('#mapResults').attr('style','');

  createCookie('showmap', 0, 14);

}

function showcats(){


  if ( $('#catResults').css('display') != 'none' )
    return;
  $('#catStrip > div.grayButtons > a').html('Hide Categories');
  $('#catStrip > div.grayButtons > div.openclose').html('-');
  $('#catResults').css('display', 'block');
  createCookie('showcats', 1, 14);
}

function hidecats(){
  if ( $('#catResults').css('display') == 'none' )
    return;
  $('#catStrip > div.grayButtons > a').html('Show Categories');
  $('#catStrip > div.grayButtons > div.openclose').html('+');
  $('#catResults').css('display', 'none');
  createCookie('showcats', 0, 14);
}

function showres(){
  if ( $('#searchResults > p').eq(0).css('display') != 'none' )
    return;

  $('#resStrip > div.grayButtons > a').html('Hide Details');
  $('#resStrip > div.grayButtons > div.openclose').html('-');
  $('#searchResults > p').eq(0).css('display', 'block');
  createCookie('showres', 1, 14);
}
function hideres(){

  if ( $('#searchResults > p').eq(0).css('display') == 'none' )
    return;

  $('#resStrip > div.grayButtons > a').html('Show Details');
  $('#resStrip > div.grayButtons > div.openclose').html('+');
  $('#searchResults > p').eq(0).css('display', 'none');
  createCookie('showres', 0, 14);
}





function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


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


