// JavaScript Document

jQuery.noConflict();

jQuery.fn.hint = function() {
	return this.each(function(){
		var t = jQuery(this); // get jQuery version of 'this'
		var title = t.attr('title'); // get it once since it won't change

		if (title) { // only apply logic if the element has the attribute

			// on focus, set value to blank if current value matches title attr
			t.focus(function(){
				if (t.val() == title) {
				  t.val('');
				  t.removeClass('blur');
				}
			})

			// on blur, set value to title attr if text is blank
			t.blur(function(){
				if (t.val() == '') {
				  t.val(title);
				  t.addClass('blur');
				}
			})

			// clear the pre-defined text when form is submitted
			t.parents('form:first()').submit(function(){
				if (t.val() == title) {
					t.val('');
					t.removeClass('blur');
				}
			});

			// now change all inputs to title
			t.blur();
		}
	})
}

jQuery(function(){
	jQuery('input:text, input:password').hint();
})


jQuery.fn.resizehandle = function() {
  return this.each(function() {
    var me = jQuery(this);
    me.after(
      jQuery('<div class="resizehandle"></div>')
      .bind('mousedown', function(e) {
        var h = me.height();
        var y = e.clientY;
        var moveHandler = function(e) {
          me
          .height(Math.max(20, e.clientY + h - y));
        };
        var upHandler = function(e) {
          jQuery('html')
          .unbind('mousemove',moveHandler)
          .unbind('mouseup',upHandler);
        };
        jQuery('html')
        .bind('mousemove', moveHandler)
        .bind('mouseup', upHandler);
      })
    );
  });
}


jQuery(document).ready(function() {
   jQuery("#show-fog-pass").click(function(){
		jQuery("#box-login, #box-password").toggle();
		return false;
   });

   jQuery("#show-login").click(function(){
		jQuery("#box-login, #box-password").toggle();
		return false;
   });

	jQuery('#top-form-login, #show-fog-pass-id').hide();


	jQuery('#show-login-first').click(function(){
		jQuery('#top-form-login, #show-fog-pass-id').fadeIn();
	});



	jQuery("#show-login-first, #show-fog-pass").attr("href", "#");



});

// add the class "ie6menu" to li tags to make ie6 mirror :hover

ie6submenu = function() {
	if (document.getElementById("submenu")) {
		var sfEls = document.getElementById("submenu").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" ie6menu";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" ie6menu\\b"), "");
			}
		}
	}
}

var is_submenu_display = false;


jQuery(function() {
	jQuery("#menu li:has(ul)").mouseover(function() {
		jQuery(this).find("ul").css({ display: "block"});
		jQuery("#content form select.ie6").css({ visibility: "hidden" });
		is_submenu_display = true;
	}).mouseout(function() {
		is_submenu_display = false;
		setTimeout(function() {
			do_hide_ie6();
		},100);
	});
});

function do_hide_ie6()
{
	if (is_submenu_display==false) {
		jQuery("#content form select.ie6").css({ visibility: "visible" });
		jQuery("#menu li ul").css({ display: "none" });
	}
}

function applyPopups()
{
  a = document.getElementsByTagName("a");

  for(i=0; i<a.length; i++)
  {
    if(a[i].getAttribute("target") && a[i].getAttribute("target") == "_blank")
    {
      a[i].onclick = function()
      {
        url = this.getAttribute("href");
        window.open(url,'popup','width=1000,height=600,scrollbars=1,resizable=1');
        return false;
      }
    }
  }
}


this.blankwin = function(){
	var hostname = window.location.hostname;
	hostname = hostname.replace("www.","").toLowerCase();
	var a = document.getElementsByTagName("a");
	this.check = function(obj){
		var href = obj.href.toLowerCase();
		return (href.indexOf("http://")!=-1 && href.indexOf(hostname)==-1) ? true : false;
	};
	this.set = function(obj){
		obj.target = "_blank";
		obj.className = "external";
	};
	for (var i=0;i<a.length;i++){
		if(check(a[i])) set(a[i]);
	};
};

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

addLoadEvent(applyPopups);
addLoadEvent(ie6submenu);
addLoadEvent(blankwin);
