/*---
 initialize goto
---*/
function initGoto(pDivSlider, pGoto) {
  if(pGoto.length != 0){
		var oAnchor = $("[name=\"" + pGoto + "\"]");
		var oTitle = oAnchor.next();
		var oBody = oTitle.next();
		if (oTitle.length > 0) {
			while (oBody.get(0).id != pDivSlider) {
				oTitle.addClass("active");
				oSpan = oTitle.children().children("span");
				tSpan = oSpan.html();
				oSpan.html(tSpan.substring(0, tSpan.length - 1) + "-");
				oBody.show();
				oBody = oBody.parent();
				oTitle = oBody.prev();
			}
		}
		scrollTo(0, oAnchor.offset().top);
	}
}
/*---
 initialize slider
 ---*/
function initSlider(pDivSlider){
	$("."+pDivSlider+"_parent").mouseover(function(){
		$(this).addClass("hover");
	})
	$("."+pDivSlider+"_parent").mouseout(function(){
		$(this).removeClass("hover");
	})	
	$("."+pDivSlider+"_parent").click(function(){
		$.o_siblings = $(this).siblings("."+pDivSlider+"_parent");
		if ($.o_siblings.length > 0) {
		$(this).siblings("."+pDivSlider+"_parent").next().hide();
		  $(this).siblings("."+pDivSlider+"_parent").removeClass("active");
			oSpan=$(this).siblings("."+pDivSlider+"_parent").children().children("span");
			tSpan=oSpan.html();
			oSpan.html(tSpan.substring(0,tSpan.length-1)+"+");
		}
		oSpan=$(this).children().children("span");
		tSpan=oSpan.html();
		tSpan=tSpan.substring(0,tSpan.length-1);	
		if($(this).next().get(0).style.display=='block'){
		  $(this).removeClass("active");
			$(this).next().hide();
			tSpan+="+";
		}else{
		  $(this).addClass("active");
			$(this).next().show();
			tSpan+="-";
		}
		oSpan.html(tSpan);
		scrollTo(0,$(this).offset().top);
 })
}
/*---
 generate emails by javascript due to security issue
---*/
function generate_email(username, domain){
 var atsign = "&#64;";
 var addr = username + atsign + domain;
 document.write("<" + "a" + " " + "href=" + "mail" + "to:" + addr + ">" + addr + "<\/a>");
}

/*---
 menu script
 Droppy 0.1.2
 (c) 2008 Jason Frame (jason@onehackoranother.com)
*/
$.fn.droppy = function(options) {
  options = $.extend({
		showTime: 250,
		fadeOutTime: 250,
		hideAfterTime: 1000
		}
		, options);

  this.each(function() {
    var root = this;
		var timerHiding;

		// get submenu
    function getSubmenu(oParentA) {
      var submenu = $(oParentA).next();
      return submenu.length ? submenu : null;
    }
		// hide trigger
    function hide() {
    }
		// show trigger
    function show() {
			// highlight
			$(this).addClass('hover');
			$(this).parents("ul", root).prev("a").addClass('hover'); 
			// hide all siblings submenus
			$(this).parent("li").siblings("li").find("ul").stop(true, true).hide();
			$(this).parent("li").siblings("li").find("a").removeClass('hover'); 
			// stop hiding after hover-out from menu
			clearTimeout(timerHiding);
			if($.hiding){
				$(this).parent("li").parents("ul", root).stop(true, true).show();
			}
			// submenu display if exists, if not return
      var submenu = getSubmenu(this);
      if (!submenu) return;
      $(submenu).show(options.showTime);
    }
		
		// auto adjust left submenu
		$('.subsubmenu', this).css('left', function(){ return $(this).parent().parent().css("width"); });
		// init triggers on menu items
    $('a', this).hover(show, hide);
		// init troggers on menu in/out
		
    $(this).hover(
		  function() { },
      function() {
			  timerHiding = setTimeout(
					function(){ 
						$.hiding = true; 
						$(root).find("ul:visible").fadeOut(options.fadeOutTime, function() { $.hiding = false; }); 
						$("a", root).removeClass('hover'); 
					}, options.hideAfterTime
				);
			}
		);
		$(document).click(function() {
			$(root).find("ul:visible").hide();
			$("a", root).removeClass('hover');
		});
  });
};
