
// K Functions 01/01/10

$(document).ready(function(){

// Description: provides different panel of content
	$('#toggle-search').show();
	$('#toggle-search-2').hide();

	$('#search-button').click(function () {
    	$('#toggle-search').slideDown("medium");
	  	$('#toggle-search-2').slideUp("medium");
    });

	$('#search-button-2').click(function () {
      	$('#toggle-search-2').slideDown("medium");
	  	$('#toggle-search').slideUp("medium");
    });	
	
// Description: provides more / less information
	$('#long-content').hide();
	$('a.more').click(function() {
		$('#long-content').slideDown("medium");
		$(this).hide();
		$('a.close').show();
		return false;
	});
	
	$('a.close').click(function() {
		$('#long-content').slideUp("medium");
		$(this).hide();
		$('a.more').show();
		return false;
	});
});

//dimScreen()
//by Brandon Goldman
jQuery.extend({
    //dims the screen
    dimScreen: function(speed, opacity, callback) {
        if(jQuery('#__dimScreen').size() > 0) return;
        
        if(typeof speed == 'function') {
            callback = speed;
            speed = null;
        }

        if(typeof opacity == 'function') {
            callback = opacity;
            opacity = null;
        }

        if(speed < 1) {
            var placeholder = opacity;
            opacity = speed;
            speed = placeholder;
        }
        
        if(opacity >= 1) {
            var placeholder = speed;
            speed = opacity;
            opacity = placeholder;
        }

        speed = (speed > 0) ? speed : 500;
        opacity = (opacity > 0) ? opacity : 0.5;
        return jQuery('<div></div>').attr({
                id: '__dimScreen'
                ,fade_opacity: opacity
                ,speed: speed
            }).css({
            background: '#000'
            ,height: '100%'
            ,left: '0px'
            ,opacity: 0
            ,position: 'absolute'
            ,top: '0px'
            ,width: '100%'
            ,zIndex: 999
        }).appendTo(document.body).fadeTo(speed, opacity, callback);
    },
    
    //stops current dimming of the screen
    dimScreenStop: function(callback) {
        var x = jQuery('#__dimScreen');
        var opacity = x.attr('fade_opacity');
        var speed = x.attr('speed');
        x.fadeOut(speed, function() {
            x.remove();
            if(typeof callback == 'function') callback();
        });
    }
});

// Set arrange viewing cookie
function WA_decodeCookieSelectVal(theVal)     {
  theVal = theVal.replace(/\|WACS\|/g, ", ");
  return theVal;
}

function WA_checkCookieSelectOption(theList, theOption, theVal)     {
  var testVal = "";
  if (theList.options[theOption].value)     {
    testVal = theList.options[theOption].value;
  }
  else      {
    testVal = theList.options[theOption].text;
  }
  if (testVal == WA_decodeCookieSelectVal(theVal))     {
    theList.options[theOption].selected = true;
    return true;
  }
  return false;
}

function WA_getCookie(cookieobj, cookiename, cookieset, settype)     {
  var theValue = cookieobj.getValue(cookiename);

  if (settype == 1)     {
    cookieset.value = theValue;
  }
  else if (settype == 2)     {
    cookieset.checked = (String(theValue)!="" && String(theValue).toUpperCase() !="FALSE");
  }
  else if (settype == 3)     {
    for (var n=0; n< cookieset.length; n++)     {
      if (cookieset[n].value == theValue)     {
        cookieset[n].checked = true;
        break;
      }
    }
  }
  else if (settype == 4)     {
    var setArr = theValue.split(", ");
    for (var m=0; m<setArr.length; m++)     {
      for (var n=0; n<cookieset.options.length; n++)     {
        if (n+m < cookieset.options.length && cookieset.options[n+m])     {
          if (WA_checkCookieSelectOption(cookieset, n+m, setArr[m]))     {
            break;
          }
        }
        if (n!=0 && n-m >= 0 && cookieset.options[n-m])     {
          if (WA_checkCookieSelectOption(cookieset, n-m, setArr[m]))     {
            break;
          }
        }
        if (n-m < 0 && n+m >= cookieset.options.length)     {
          break;
        }
      }
    }
  }
}
function WA_setCookie(cookieobj, cookiename, cookievalue, cookiecheck, settype, expdays)     {
  var theValue = "";
  if (settype == 1)     {
    for (var n=0; n<cookievalue.length; n++)    {
      if (cookievalue[n].checked)     {
        theValue = cookievalue[n].value;
      }
    }
  }
  else if (settype == 2)     {
    for (var n=0; n<cookievalue.options.length; n++)    {
      if (cookievalue.options[n].selected)     {
        if (theValue != "")
          theValue += ", ";
        theValue += cookievalue.options[n].value;
      }
    }
  }
  else      {
    theValue = cookievalue
  }

  if (cookiecheck)     {
	if (expdays)  {
	  cookieobj.expires = daysToExpire(expdays);
	}
	else  {
	  cookieobj.expires = "";
	}
    cookieobj.setValue(cookiename, theValue, expdays);
  }
}
// Finish arrange viewing cookie
