$(function(){
	$("#searchval").focus(function() {
		if($("#searchval").val()==this.title){
		 	$("#searchval").val('');
		 }
	});
	$("#searchval").blur(function() {
		if($("#searchval").val()==''){
		 	$("#searchval").val(this.title);
		 }
	});
	
	$("#username").focus(function() {
		if($("#username").val()==this.title){
		 	$("#username").val('');
		 }
	});
	$("#username").blur(function() {
		if($("#username").val()==''){
		 	$("#username").val(this.title);
		 }
	});
	
	$("#password").focus(function() {
		if($("#password").val()==this.title){
		 	$("#password").val('');
		 }
	});
	$("#password").blur(function() {
		if($("#password").val()==''){
		 	$("#password").val(this.title);
		 }
	});
	
	$("ul.list li").hover(
		function () {
			$(this).addClass("on");
	  	},
		function () {
			$(this).removeClass("on");
		}
	);
	
	$('a[rel~=otherbox]').click(lightbox_show);
	
});

(function( $ ){

$.fn.slideshow = function(options) {
  
	var settings = {
	      'timeOut': 5000
	    };

    return this.each(function() {

		if ( options ) { 
			$.extend( settings, options );
		}
		
		var $slides = $(this).children();
		$slides.hide();
		$($slides.get(0)).show();
		
		setInterval(function(){
			
			var $currentSlide = $($slides).filter(':visible');
			var currentIndex = $($slides).index($currentSlide);
			var nextIndex = currentIndex+1;
			if(nextIndex==$slides.size()){
				nextIndex=0;
			}
			$currentSlide.fadeOut();
			$($slides.get(nextIndex)).fadeIn();
			
		},settings.timeOut);
		
    });

  };
})( jQuery );

function lightbox_show(){
	
	if(document.getElementById('TB_overlay')){
		jQuery('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();
	}

	if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
		//jQuery("body,html").css({height: "100%", width: "100%"});
		//jQuery("html").css("overflow","hidden");
		if (document.getElementById("TB_HideSelect") === null) {//iframe to hide select elements in ie6
			jQuery("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div><div id='TB_window'></div><div id='TB_loader'></div>");
			//jQuery("#TB_overlay").click(lightbox_remove);
		}
	}else{//all others
		if(document.getElementById("TB_overlay") === null){
			jQuery("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div><div id='TB_window'></div><div id='TB_loader'></div>");
			//jQuery("#TB_overlay").click(lightbox_remove);
		}
	}

	if(tb_detectMacXFF()){
		jQuery("#TB_overlay").addClass("TB_overlayMacFFBGHack");//use png overlay so hide flash
	}else{
		jQuery("#TB_overlay").addClass("TB_overlayBG");//use background and opacity
	}

	jQuery('object, embed').hide();
	
	var title = ($(this).attr('title')!='')?$(this).attr('title'):$(this).html();
	
	jQuery("#TB_window").append("<div id='TB_caption'>"+title+"<a id='TB_closeWindow' href=''></a></div><div id='TB_ajaxContent'></div>");
	
	jQuery('#TB_ajaxContent').load(this.href,function(){
		jQuery('#TB_closeWindow').click(lightbox_remove);
		//if (typeof document.body.style.maxHeight !== "undefined") {//if IE 6
		//	jQuery("#TB_window").css({marginTop: '-' + (jQuery("#TB_window").innerHeight()/2) + 'px' });
		//}
		jQuery("#TB_window").fadeIn(function(){
			jQuery("#TB_loader").remove();
			jQuery("#TB_window").css({marginTop: '-' + (jQuery("#TB_window").height()/2) + 'px' });
		});
	});
	return false;
	
}

function imagebox_show(){
	
	if(document.getElementById('TB_overlay')){
		jQuery('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();
	}

	if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
		//jQuery("body,html").css({height: "100%", width: "100%"});
		//jQuery("html").css("overflow","hidden");
		if (document.getElementById("TB_HideSelect") === null) {//iframe to hide select elements in ie6
			jQuery("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div><div id='TB_window'></div><div id='TB_loader'></div>");
			//jQuery("#TB_overlay").click(lightbox_remove);
		}
	}else{//all others
		if(document.getElementById("TB_overlay") === null){
			jQuery("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div><div id='TB_window'></div><div id='TB_loader'></div>");
			//jQuery("#TB_overlay").click(lightbox_remove);
		}
	}

	if(tb_detectMacXFF()){
		jQuery("#TB_overlay").addClass("TB_overlayMacFFBGHack");//use png overlay so hide flash
	}else{
		jQuery("#TB_overlay").addClass("TB_overlayBG");//use background and opacity
	}

	jQuery('object, embed').hide();
	
	var title = ($(this).attr('title')!='')?$(this).attr('title'):$(this).html();
	
	jQuery("#TB_window").append("<div id='TB_caption'><a id='TB_closeWindow' href=''></a></div><div id='TB_ajaxContent'></div>");
	
	jQuery('#TB_ajaxContent').append('<img src="'+this.href+'" alt="" />');
	jQuery('#TB_closeWindow').click(lightbox_remove);
	jQuery("#TB_window").css({width: 'auto'});

	jQuery("#TB_window").fadeIn(function(){
		jQuery("#TB_loader").remove();
		jQuery("#TB_window").css({marginTop: '-' + (jQuery("#TB_window").height()/2) + 'px', marginLeft: '-' + (jQuery("#TB_window").width()/2) + 'px' });
	});

	return false;
	
}

function lightbox_message(message,title){

	if(document.getElementById('TB_overlay')){
		jQuery('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();
	}

	if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
		//jQuery("body","html").css({height: "100%", width: "100%"});
		//jQuery("html").css("overflow","hidden");
		if (document.getElementById("TB_HideSelect") === null) {//iframe to hide select elements in ie6
			jQuery("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div><div id='TB_window'></div>");
			//jQuery("#TB_overlay").click(lightbox_remove);
		}
	}else{//all others
		if(document.getElementById("TB_overlay") === null){
			jQuery("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div><div id='TB_window'></div>");
			//jQuery("#TB_overlay").click(lightbox_remove);
		}
	}
	
	if(tb_detectMacXFF()){
		jQuery("#TB_overlay").addClass("TB_overlayMacFFBGHack");//use png overlay so hide flash
	}else{
		jQuery("#TB_overlay").addClass("TB_overlayBG");//use background and opacity
	}

	jQuery('object, embed').hide();
	
	jQuery("#TB_window").append("<div id='TB_caption'>"+title+"<a id='TB_closeWindow' href=''></a></div><div id='TB_ajaxContent'></div>");
	jQuery('#TB_ajaxContent').html(message);
	jQuery('#TB_closeWindow').click(lightbox_remove);

	if (typeof document.body.style.maxHeight !== "undefined") {//if IE 6
		jQuery("#TB_window").css({marginTop: '-' + (jQuery("#TB_window").innerHeight()/2) + 'px' });
	}

	jQuery("#TB_window").fadeIn();

	return false;
}

function lightbox_remove() {
	jQuery("#TB_window, #TB_overlay").fadeOut("fast",function(){
		jQuery('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();
		jQuery('object, embed').show();
	});
	if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
		//jQuery("body","html").css({height: "auto", width: "auto"});
		//jQuery("html").css("overflow","hidden");
	}
	document.onkeydown = "";
	document.onkeyup = "";
	return false;
}

function tb_detectMacXFF() {
  var userAgent = navigator.userAgent.toLowerCase();
  if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1) {
    return true;
  }
}
