/*---
 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;
		// hover-out trigger /hide/
    function hoverOut() {
    }
		// hover-in trigger /show/
    function hoverIn() {
			// 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 = $(this).next('ul');
			var parmenu = $(this).parent();
			
      if (!($(submenu))) return;
			if($(submenu).hasClass('subsubmenu')){ 
			  var pos_left = $(this).parent().width() + $(this).parent().offset().left + $(submenu).width();
				if(pos_left>=$(window).width()){
  				pos_left = - $(submenu).width();
				}else{
					pos_left = $(this).parent().width();
				}				
				$(submenu).css('width', $(submenu).width());
				$(submenu).css('left', pos_left);
			}
			$(submenu).show(options.showTime);
    }
		
		/* set basic attributes */
		// main menu
		$(this).attr('depth', 0);
		var menuZindex = $(this).css('z-index')?parseInt($(this).css('z-index')):0;
		// sub menus
		var submenus = $(this).children('li').children('ul');
		$(submenus).addClass('submenu');
		$(submenus).css('z-index', menuZindex);
		$(submenus).attr('depth', 1);
		$(submenus).prev('a').addClass('subcall');
		// sub sub menus
		var subsubmenus = $('ul', submenus);
		$(subsubmenus).addClass('subsubmenu');
		$(subsubmenus).each(function( intIndex ){
			var depth = parseInt($(this).parent('li').parent('ul').attr('depth'));
			$(this).attr('depth', depth + 1);
			$(this).css('z-index', menuZindex + depth + 1);
		});
		$(subsubmenus).prev('a').addClass('subsubcall');
		/* end: set basic attributes */
		/* initialize triggers */
		// on menu items
    $('a', this).hover(hoverIn, hoverOut);
		// on menu in/out
    $(this).hover(
		  function(){ },
      function(){
			  timerHiding = setTimeout(
					function(){ 
						$.hiding = true; 
						$('ul:visible', root).fadeOut(options.fadeOutTime, function() { $.hiding = false; }); 
						$('a.hover', root).removeClass('hover'); 
					}, options.hideAfterTime
				);
			}
		);
		$(document).click(function(){
			$('ul:visible', root).hide();
			$('a.hover', root).removeClass('hover');
		});
		/* end: initialize triggers */
  });
};