var menu=function(){
	var t=15,z=50,s=12,a;
	function dd(n){this.n=n; this.h=[]; this.c=[]}
	dd.prototype.init=function(p,c){
		a=c; var w=document.getElementById(p), s=w.getElementsByTagName('ul'), l=s.length, i=0;
		for(i;i<l;i++){
			var h=s[i].parentNode; this.h[i]=h; this.c[i]=s[i];
			h.onmouseover=new Function(this.n+'.st('+i+',true)');
			h.onmouseout=new Function(this.n+'.st('+i+')');
		}
	}
	dd.prototype.st=function(x,f){
		var c=this.c[x], h=this.h[x], p=h.getElementsByTagName('a')[0];
		clearInterval(c.t); c.style.overflow='hidden';
		if(f){
			p.className+=' '+a;
			if(!c.mh){c.style.display='block'; c.style.height=''; c.mh=c.offsetHeight; c.style.height=0}
			if(c.mh==c.offsetHeight){c.style.overflow='visible'}
			else{c.style.zIndex=z; z++; c.t=setInterval(function(){sl(c,1)},t)}
		}else{p.className=p.className.replace(a,''); c.t=setInterval(function(){sl(c,-1)},t)}
	}
	function sl(c,f){
		var h=c.offsetHeight;
		if((h<=0&&f!=1)||(h>=c.mh&&f==1)){
			if(f==1){c.style.filter=''; c.style.opacity=1; c.style.overflow='visible'}
			clearInterval(c.t); return
		}
		var d=(f==1)?Math.ceil((c.mh-h)/s):Math.ceil(h/s), o=h/c.mh;
		c.style.opacity=o; c.style.filter='alpha(opacity='+(o*100)+')';
		c.style.height=h+(d*f)+'px'
	}
	return{dd:dd}
}();


$(document).ready(function() {	
	
	//select all the a tag with name equal to modal
	$('a[class=modal]').click(function(e) {
		//Cancel the link behavior
		e.preventDefault();
		 $('#RegularContent').fadeIn('slow'); 
		
		//Get the A tag
		//var id = $(this).attr('href');
		var id='#'+$(this).attr('name');
		
		var title = $(this).attr('rel');
		$(id).find(".title").html(title);
		
	
		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
	
		//Set heigth and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight});
		
		//transition effect		
		$('#mask').fadeIn(500);	
		$('#mask').fadeTo("slow",0.8);	
	
		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();
		
		var xScroll, yScroll;
		if (self.pageYOffset) {
			yScroll = self.pageYOffset;
			xScroll = self.pageXOffset;
		} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
			yScroll = document.documentElement.scrollTop;
			xScroll = document.documentElement.scrollLeft;
		} else if (document.body) {// all other Explorers
			yScroll = document.body.scrollTop;
			xScroll = document.body.scrollLeft;	
		}
		
		//alert(yScroll);
	//	winH =  $(document).height() yScroll;
              
		//Set the popup window to center
		$(id).css('top',  yScroll + (winH/2-$(id).height()/2));
		$(id).css('left', winW/2-$(id).width()/2);

		//transition effect
		$(id).fadeIn(2000); 
	
	});
	
	//if close button is clicked
	$('.window .close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		
		$('#mask').hide();
		$('.window').hide();
	});		
	
	//if mask is clicked
	$('#mask').click(function () {
		$(this).hide();
		$('.window').hide();
	});				
	
});


function showModal(e)
{

		var id='#'+$(e).attr('name');
		var title = $(e).attr('rel');
		$(id).find(".title").html(title);

		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
	
		//Set heigth and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight});
		
		//transition effect		
		$('#mask').fadeIn(500);	
		$('#mask').fadeTo("slow",0.8);	
	
		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();
		
		var xScroll, yScroll;
		if (self.pageYOffset) {
			yScroll = self.pageYOffset;
			xScroll = self.pageXOffset;
		} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
			yScroll = document.documentElement.scrollTop;
			xScroll = document.documentElement.scrollLeft;
		} else if (document.body) {// all other Explorers
			yScroll = document.body.scrollTop;
			xScroll = document.body.scrollLeft;	
		}
		
		//alert(yScroll);
	//	winH =  $(document).height() yScroll;
              
		//Set the popup window to center
		$(id).css('top',  yScroll + (winH/2-$(id).height()/2));
		$(id).css('left', winW/2-$(id).width()/2);

		//transition effect
		$(id).fadeIn(2000); 


	return false;
}


$(document).ready(function(){
						   
						   
	// textarea default text value on focus
	$(".search-inpt").focus(function(srcc)
    {
        if ($(this).val() == $(this)[0].title)
        {
            $(this).val("");
        }
    });
    
    $(".search-inpt").blur(function()
    {
        if ($(this).val() == "")
        {
            $(this).val($(this)[0].title);
        }
    });
	
    $(".search-inpt").blur(); 
	

	
	$(".search").submit(function()
	{
		var input = $(this).find(".search-inpt");
		var sel = $(this).find(".search-opt");
		if ( $(input).val() ==  $(input)[0].title || $(input).val().length < 3 )
		{
			alert($(this).find(".label-word").text());
			return false;
		}else
		if ($(sel).val()=='0')
		{
			alert($(sel)[0].title);
			return false;
		}
		
		
	});
	/*
	jQuery('.prfl_menu').click(function() {
		jQuery('.popup_menu').toggle();
	});
*/

//top submenu
jQuery('.prfl_menu').bind("mouseenter mouseleave", function(e)
	{
	    jQuery('.prfl_menu').toggleClass('pb10');
		jQuery('.popup_menu').toggle();
	});


//rss

					   
   //Setup header tooltips
  $('.tip').each(function()
   {
      var offset = -5;
      var position = 'top';
      var content = '<div class="tooltip-1">' + $(this).attr('title') + '</div>';
      
     if($(this).hasClass('top'))
         {
            position = 'top';
            offset = -5;
         }
      
      $(this).simpletip({
         position: 'top',
         offset: [0, offset],
         boundryCheck: false,
         content: content
      });
   });
  
  
  
  //load articles
  $(".showArt").click( function(e){
		var obj=this;
		
		if (!$(obj).parent().find('.articles-list').html())
		{
		$.post("modules/articles/ajax_art.php", { url:$(this).attr('href') },
   			function(data,e){
				
				var art = $(obj).parent().find('.articles-list');
			//	alert(art.style.display);
				//if (art.style.display=='block') 
				if (!$(obj).hasClass("selected"))
					$(art).html(data);
				
				//$(obj).parent().find('.articles-list').slideToggle('slow',function () {
				$(art).slideToggle('slow',function () {
					 if (this.style.display=='block')  $(obj).addClass('selected'); 
					 else $(obj).removeClass('selected');
  					});
				
   				});
		}
		else
		{
			var art = $(obj).parent().find('.articles-list');	
			$(art).slideToggle('normal',function () {
			if (this.style.display=='block')  $(obj).addClass('selected'); 
				else $(obj).removeClass('selected');
  			});
		}
		return false;
		
	});
		
  //load articles mainpages
  $(".showArt2").click( function(e){
		var obj=this;
		var art = $(obj).parent().find('.articles-list');
		$(art).slideToggle('slow',function () {
				if (this.style.display=='block')  $(obj).addClass('selected'); 
					 else $(obj).removeClass('selected');
  					});	
		return false;
	});
		
 


})
