// Agile Toolkit (c) Agile Technologies // http://www.agiletech.ie/

$(document).ready(function() {
	
	$('a.email').each(function(i) {
        var text = $(this).text();
        var address = text.replace(" at ", "@");
        $(this).attr('href', 'mailto:' + address);
            $(this).text(address);
    });
	
	$('#header .current_page_item, #header .current_page_ancestor').prepend("<b></b>").append("<b></b>");
	$('#form-contact, #form-newsletter').find('.atk-form-buttons input').addClass("atk-button blue");
	$('#sub-navigation .current_page_item').prepend("<i></i>");
	
	$('.searchform #s').focus(function(){
		$(this).attr("value","");
	}).blur(function(){
		if ($(this).attr("value") == "") {
			$(this).attr("value","Search...");
		}
	});
	
	$('.pages>span').each(function(){
		$(this).find('a').addClass("atk-button blue");
		if ($(this).text() == "") {	
			$(this).remove();
		}

	});
	// slider
	var $holder = $('#carousel-holder');
	var $trigger = $('#carousel-nav a');
	$selected = $("#carousel-nav a:first");
	$selected.addClass("current");	
	
	$holder.cached_top=-1;
	$holder.cached_name='show-cframe-1';
	$trigger.each(function() {
		$(this).click(function() {

            clearTimeout(tim);
			$(this).blur();
			$(this).parent('#carousel-nav').find('.current').removeClass("current");
/* 			$selected = $(this).parent(); */
			$(this).addClass("current");			
			
			var top=-1;
			if ($(this).attr("id") == 'show-cframe-1') {
				top=-1;
			} else if ($(this).attr("id") == 'show-cframe-2') {
				top=-421;
			} else if ($(this).attr("id") == 'show-cframe-3') {
				top=-841;
			} else if ($(this).attr("id") == 'show-cframe-4') {
				top=-1261;
			} else if ($(this).attr("id") == 'show-cframe-5') {
				top=-1681;
			} else if ($(this).attr("id") == 'show-cframe-6') {
				top=-2101;
			} else if ($(this).attr("id") == 'show-cframe-7') {
				top=-2521;
			}				

			if(Math.abs(top-$holder.cached_top)>500){
			    $holder.fadeOut(function(){
				    $holder.css({"top": top+"px"});
				    $holder.fadeIn();
				});
			}else{
				$holder.animate({"top": top+"px"});
			}

			var oldname=$holder.cached_name;
			var name=$(this).attr('id');

			$("#text-"+oldname).fadeOut(350,function(){
				$("#text-"+oldname).removeClass('current');
				$("#text-"+name)
					.addClass('current').hide().fadeIn(350);
			});


			$holder.cached_top=top;
			$holder.cached_name=name;
		});
	});

    var t=1; var tim;

    sliderNext=function (){
        $trigger.eq(t++).click();
        if(t>=$trigger.length)t=0;
        tim=setTimeout('sliderNext()',10000);
    }
    if($trigger.eq(0).attr('id')=='show-cframe-1'){
        tim=setTimeout('sliderNext()', 10000);
    }else{
        $trigger.eq(0).click();
    }
    

	
});


function init() {
    if(!document.getElementById('map_canvas'))return;
  var map = new google.maps.Map(document.getElementById("map_canvas"), {
    scaleControl: true,mapTypeControl: false, scaleControl: false});
  	map.setCenter(new google.maps.LatLng(53.289334,-6.172771));
 	map.setZoom(13);
 	map.setMapTypeId(google.maps.MapTypeId.ROADMAP);
	
  var marker = new google.maps.Marker({map: map, position:
    map.getCenter()});
  var infowindow = new google.maps.InfoWindow();
  infowindow.setContent('<b>Newpark Comprehensive School</b>');
  google.maps.event.addListener(marker, 'click', function() {
    infowindow.open(map, marker);
  });
}

