﻿Drupal.behaviors.headerSlideShow = function()
{
	var DBG=false;
	$.slideImages = [];
	$.slideTitles = [];
	$.currentImage = "";
	var currurl = $('#header div.slidebox img').attr('src');
	$.lastindex = -1;	
	
	$.getJSON('/get-images',{ size: '_original', term:'slideshow',json:'1' },
		function(data)
		{
			var idx = 0;
			$(data).find('img').each( function() {
				var imgurl = $(this).attr('src');
				if(imgurl==currurl)
				{
					$.currentImage=idx;
					$.lastindex=idx;
				}
				$.slideImages.push($(this).addClass('image'))
				idx++;
			})
			$(data).find('dt').each( function() { $.slideTitles.push($(this).text()) })
			
			var startdate = (new Date()).valueOf();
			if($.slideImages.length==0||$.slideTitles.length==0)
			{
				return;
			}
			$.timer = setInterval( function(e)
			{
				var cdate = (new Date()).valueOf();
				var rnd = $.lastindex;
				while(rnd==$.lastindex)
				{
					rnd = parseInt(Math.random()*$.slideImages.length);
				}
				$.lastindex = rnd;
				
				var timg = $('#header img.image');
				$('div.slidebox').append($.slideImages[rnd].fadeIn(250,function(){timg.fadeOut(100,function(){$(this).remove()}) }))
				$('#header div.block-block h2').animate({opacity:0, right:30+'px'},200,function(){ $(this).text($.slideTitles[rnd]).css('right','50px').animate({opacity:1, right:40+'px'},200) })
			},10000)
		
		}
	)

}

Drupal.behaviors.sendInfoForm = function()
{
	if($('#edit-sendinfo-publicuserselect')==null
		|| $('#edit-sendinfo-publicuserselect')[0]==null) return;
		
	var sel = $('#edit-sendinfo-publicuserselect')[0].value;
	//var emailh = $('#edit-sendinfo-emailbody-wrapper').css({display:'none'});
	if(sel==-1)
	{
		$('#edit-sendinfo-publicuserpassword-wrapper').hide();
		$('#edit-sendinfo-emailbody-wrapper').hide();
		$('#edit-sendinfo-emailsubject-wrapper').hide();
		$('#edit-submit[value="Enable"]').attr('disabled','disabled');
	}	
	
	$('#edit-sendinfo-publicuserselect').change(function(i){
		if(this.value==-1)
		{
			if(sel>1)
			{
				sel=-1;
				$('#edit-sendinfo-publicuserpassword-wrapper').hide('fast')
				$('#edit-sendinfo-publicuserpassword').attr('disabled','disabled').value='';
				$('#edit-sendinfo-emailsubject-wrapper').hide('fast')
				$('#edit-sendinfo-emailbody-wrapper').hide('fast')
				$('#edit-sendinfo-emailbody').attr('disabled','disabled')
				$('#edit-submit[value="Enable"]').attr('disabled','disabled');
			}
		}
		else
		{
			if(sel==-1)
			{
				sel = this.value;
				$('#edit-sendinfo-publicuserpassword-wrapper').show('fast');
				$('#edit-sendinfo-emailbody-wrapper').show('fast');
				$('#edit-sendinfo-emailsubject-wrapper').show('fast');
			}
			$('#edit-submit[value="Enable"]').removeAttr('disabled');
			$('#edit-sendinfo-publicuserpassword').removeAttr('disabled').focus()[0].value='';
			$('#edit-sendinfo-emailsubject-wrapper').removeAttr('disabled');
			$('#edit-sendinfo-emailbody').removeAttr('disabled');
		}
	})
	
}





















/*
Drupal.behaviors.headerSlideShow = function()
{
	var DBG=false;
	$.slideImages = [];
	$.slideTitles = [];
	$.currentImage = "";
	var currurl = $('#header div.slidebox img').attr('src');
	$.lastindex = -1;	
	
	$.getJSON('/school/get-images',{ size: '_original', term:'slideshow',json:'1' },
		function(data)
		{
			var idx = 0;
			$(data).find('img').each( function() {
				var imgurl = $(this).attr('src');
				if(imgurl==currurl)
				{
					$.currentImage=idx;
					$.lastindex=idx;
				}
				$.slideImages.push($(this).addClass('image'))
				idx++;
			})
			$(data).find('dt').each( function() { $.slideTitles.push($(this).text()) })
			
			var startdate = (new Date()).valueOf();
			if($.slideImages.length==0||$.slideTitles.length==0)
			{
				return;
			}
			$.timer = setInterval( function(e)
			{
				var cdate = (new Date()).valueOf();
				var rnd = $.lastindex;
				while(rnd==$.lastindex)
				{
					rnd = parseInt(Math.random()*$.slideImages.length);
				}
				$.lastindex = rnd;
				
				var timg = $('#header img.image');
				$('div.slidebox').append($.slideImages[rnd].fadeIn(250,function(){timg.fadeOut(100,function(){$(this).remove()}) }))
				$('#header div.block-block h2').animate({opacity:0, right:30+'px'},200,function(){ $(this).text($.slideTitles[rnd]).css('right','50px').animate({opacity:1, right:40+'px'},200) })
			},10000)
		
		}
	)

}

*/