$(document).ready(function() {

    $("#schoolmonitoring li").hover(
        function(){$(this).children('em').css('display','block');},
        function(){$(this).children('em').css('display', 'none');
    });

    $("#schoolmonitoring #date, #start_date, #end_date").datepicker({dateFormat: 'dd/mm/yy'});


    $("a[rel='colorboxgallery']").colorbox();
    $("a[rel='colorboximages']").colorbox();

    $('<span class="textSize"><span>Increase text size</span> <a href="#" class="normal" title="Change text size">A</a> <a href="#" class="big" title="Change text size">A</a> <a href="#" class="large" title="Change text size">A</a> <a href="#" class="extralarge" title="Change text size">A</a></span>').prependTo('#c');
    $('#c span.textSize a').click(function(){$('#content').removeClass(); $('#content').addClass($(this).attr('class')); $.cookie('ccysize', $(this).attr('class'), { expires: 999, path: '/'}); return false;});
    if($.cookie('ccysize') != '') {
        $('#content').addClass($.cookie('ccysize'));
    }

    $('#weather .daylight, #weather .wind').hide();

    $('#weather .detail a').toggle(function() { $(this).parent().siblings('p.daylight, p.wind').show(); 
                                                $(this).css('background-image', 'url(\'/images/common/weather-hide.jpg\')');
                                                $('#weather, .weather-inner').css('height', (parseInt($('#weather').css('height')) + 50) + 'px'); }, 
                                   function() { $(this).parent().siblings('p.daylight, p.wind').hide(); 
                                                $(this).css('background-image', 'url(\'/images/common/weather-more.jpg\')'); 
                                                $('#weather, .weather-inner').css('height', (parseInt($('#weather').css('height')) - 50) + 'px'); });



        var i = 0;
        var j = 0;
        var ulMenu = document.getElementById('navigation');
        var liSubs = ulMenu.childNodes;

        for (i = 0; i < liSubs.length; i++) {
            if (liSubs[i].nodeName == 'LI') {
                for (j = 0; j < liSubs[i].childNodes.length; j++) {

                    if (liSubs[i].childNodes[j].nodeName == 'UL') {
	
                        liSubs[i].onmouseover = ( function(n,m){ return function() {semlyenHoverOver(n,m);} } )(liSubs[i], liSubs[i].childNodes[j])
                        liSubs[i].onmouseout = ( function(n,m){ return function() {semlyenHoverOut(n,m);} } )(liSubs[i], liSubs[i].childNodes[j])
                    }
                }
            }
        }

	
	$('#comment_form').submit(function() {

		var empty_input = false;

		$('#comment_form input[type="text"], #comment_form textarea').each(function() {
			if ( ! $(this).val()) {
				empty_input = true;
			}
		});

		if (empty_input) {
			alert("Please make sure you enter your name, a valid email address, comment and image verification code.");
			return false;
		}
	});

	if ($(this).is(":checked")) {
		$(".feed-page").attr('disabled', true)
	}
	else {
		$(".feed-page").attr('disabled', false)
	}
		
	$("#feed-site").change(function() {
		
		if ($(this).is(":checked")) {
			$(".feed-page").attr('disabled', true)
		}
		else {
			$(".feed-page").attr('disabled', false)
		}
	});


function semlyenHoverOver(li, ul) {
    ul.style.display = 'inline';
}
function semlyenHoverOut(li, ul) {
    ul.style.display = 'none';
}
});    

function rotatePics(currentPhoto) {
  var numberOfPhotos = $('#slideshow_photos img').length;
  
  currentPhoto = currentPhoto % numberOfPhotos;
    
  $('#slideshow_photos img').eq(currentPhoto).fadeOut(function() {
    // re-order the z-index
    $('#slideshow_photos img').each(function(i) {
      if ($(this).is(':hidden')) {
        $(this).show();
      }
      $(this).css(
        'zIndex', ((numberOfPhotos - i) + currentPhoto) % numberOfPhotos
      );
    });
    setTimeout(function() {rotatePics(++currentPhoto);}, 15000);
  });
}

// Preload header
var headerOverlay = new Image();
headerOverlay.src="/images/common/header-overlay.png";

