﻿
$(document).ready(function(){

  //animated scroll for Question and Answer pages.
  $('#qalist').localScroll();

  $("a.fancybox").fancybox();


   $('a.contentstoggle').click(function() {
        $('ul.publicationcontents li:not(.selected) ul').slideToggle('fast');
        return false;
   });

   //$('a.fancybox').fancyZoom({ scaleImg: true, closeOnClick: true, directory: '/gfx/zoom' });


   var focustimerconfig = {    
        sensitivity: 7, // number = sensitivity threshold (must be 1 or higher)    
        interval: 400, // number = milliseconds for onMouseOver polling interval    
        over: focushover, // function = onMouseOver callback (REQUIRED)    
        timeout: 500, // number = milliseconds delay before onMouseOut    
        out: focusout // function = onMouseOut callback (REQUIRED)    
   };

   $('a.focustab').hoverIntent( focustimerconfig );
   
  	$("a[rel='email']").safeMailTo();

  	$('a.external').newWin();
  	$('a.readmore_external').newWin();
  	
  	$('body, body div').click(function(){
        if('#submenu:visible'){
            $('#submenu:visible').slideUp('normal');
        }
  	});
  	
  	$('.dropdownlink').click(function(){
  	    $('#submenu').hide();
  	});
  	
  	
   $('#submenu').css({'top': $('#top').height() + $('#topmenu').height() + 2 + 'px'})
   
   $('#submenutoggle').click(function () {
      
      var page = $('#page').offset();
      
      var pageleft = page.left + 28;
            
      var smTopLeft = $('#topmenu li:first').width() + $(this).width() + 4;
      var smTopWidth = 666 - smTopLeft;
      
      $('#submenutop').css({'left': smTopLeft + 'px','width': smTopWidth + 'px' })
      
      $('#submenu').css({'left': pageleft + 'px', 'top': $('#top').height() + $('#topmenu').height() + 2 + 'px'})
      
      $('#submenubottom').css({'max-height': $('#submenu').height() + 3 + 'px' });
      
      $('#submenu').slideToggle('normal');
            
      if($('#submenu').css('height')!=='1px'){
         $('#topmenu a:first').focus().blur();
      }
      
      $('#submenu a:last').blur(function(){
         $('#topmenu a:first').focus();
      });
           
      return false;
    });
    
    $('a.focustab').click(function(){
      var fc = $(this).next('.hidden').html();
      $('#focustemp').html(fc).slideDown('slow', function(){
         $('#focuscontent').html(fc);
         $('#focustemp').html('').hide();
      });
      $('#focustabs li').removeClass('selected');
      $(this).blur().parent().addClass('selected');
      return false;
    });
    
    function focushover(){
      var fc = $(this).next('.hidden').html();
      $('#focustemp').html(fc).slideDown('slow', function(){
         $('#focuscontent').html(fc);
         $('#focustemp').html('').hide();
      });
      $('#focustabs li').removeClass('selected');
      $(this).blur().parent().addClass('selected');
      return false;
    }
    
    function focusout(){
    }   
   
   $('.plus').toggle(function () {
      $(this).parents('.contentblock').find('.extra').slideDown('fast');
      $(this).addClass('minus');
      return false;      
   },function (){
      $(this).parents('.contentblock').find('.extra').slideUp('fast');
      $(this).removeClass('minus');
      return false;}
   );
   
   $('img[src$=.png]').ifixpng(); 
   $('input[src$=.png]').ifixpng();
      
   if($('#left .measure').is(":visible)")){
   
      var leftheight = $('#left .measure').offset().top;
      var rightheight = $('#right .measure').offset().top;
      
      if(leftheight > rightheight){
         var diff = leftheight-rightheight;
         
         var height = $('#right .content:last').height() + diff;
         
         $('#right .content:last').height(height);
      }
      
      if(leftheight < rightheight){
         var diff = rightheight-leftheight;
         
         var height = $('#left .content:last').height() + diff;
         
         $('#left .content:last').height(height);
      }
      
   }; 
   
   $('#selCategori').change(function(){
      document.location = $(this).children('[@selected]').attr('value');
   });
   
    $("#frmEducation").goToUrlFromSelect();

   $('a.print').click(function(){
      window-print();
      return false;
   });
   
   $('input:text').focus(function(){
      if(this.value == this.defaultValue){
         this.value = '';
      }   
   });
   
   $("table.uvm_table tbody tr:odd").addClass('odd');
   
   $('#pagerate1').click(function(){
      $('#pagerating').css({'background-position': '0 -17px'});
      $('.opinion .content').slideDown('fast');
      $('.feedbackgrade input').attr({'value':'1'});
      return false;
   });
   
   $('#pagerate2').click(function(){
      $('#pagerating').css({'background-position': '0 -34px'});
      $('.opinion .content').slideDown('fast');
      $('.feedbackgrade input').attr({'value':'2'});
      return false;
   });
   
   $('#pagerate3').click(function(){
      $('#pagerating').css({'background-position': '0 -51px'});
      $('.opinion .content').slideDown('fast');
      $('.feedbackgrade input').attr({'value':'3'});
      return false;
   });
   
   $('#pagerate4').click(function(){
      $('#pagerating').css({'background-position': '0 -68px'});
      $('.opinion .content').slideDown('fast');
      $('.feedbackgrade input').attr({'value':'4'});
      return false;
   });
   
   $('#pagerate5').click(function(){
      $('#pagerating').css({'background-position': '0 -85px'});
      $('.opinion .content').slideDown('fast');
      $('.feedbackgrade input').attr({'value':'5'});
      return false;
   });
   
   $('#pagerate6').click(function(){
      $('#pagerating').css({'background-position': '0 -102px'});
      $('.opinion .content').slideDown('fast');
      $('.feedbackgrade input').attr({'value':'6'});
      return false;
   });
   
});

(function($) {
	$.fn.goToUrlFromSelect = function() {
		currentForm = this;
		$("select", this).bind("change", function(event) {
			currentForm.submit();
		}),
		this.bind("submit", function(event) {
			selectedOption = $(":selected", this);
			if(selectedOption.val() == '/'){
			   return false;
			}
			this.action = selectedOption.val();
			this.target = '_blank';
		});
		return this;
	};
	
	$.fn.newWin = function() {
	   return this.each(function(){
		   $(this).attr('target','_blank');			
	   })
	};
	
	
	$.fn.safeMailTo = function() {
	return this.each(function(){
 
		var mailtoHref = $(this).attr('title');
		mailtoHref = mailtoHref.replace(mailtoHref,"mailto:" + mailtoHref);
		mailtoHref = mailtoHref.replace(" [at] ","@");
		mailtoHref = mailtoHref.replace(" [dot] ",".");
		mailtoHref = mailtoHref.replace(" [dot] ",".");
		mailtoHref = mailtoHref.replace(" [dot] ",".");
		mailtoHref = mailtoHref.replace(" [dot] ",".");
 
		var mailtoText = $(this).text();
		mailtoText = mailtoText.replace(" [at] ","@");
		mailtoText = mailtoText.replace(" [dot] ",".");
		mailtoText = mailtoText.replace(" [dot] ",".");
		mailtoText = mailtoText.replace(" [dot] ",".");
		mailtoText = mailtoText.replace(" [dot] ",".");
		
		$(this).children('span').text(mailtoText);
 
		var mailtoTitle = mailtoHref.replace("mailto:","Email: ");
		$(this).attr('title',mailtoTitle);
		$(this).attr('href',mailtoHref);
 
		$(this).click(function(){
			window.location.href = mailtoHref;
			return false;
		});
	});


	
	
};


})(jQuery);