var loader = { 
  imgs: [],
  load: function(src) {img=this.imgs; var ct=img.length; img[ct]=new Image();img[ct].src=src;}
};
var spark_id = new Array();
var tp = 0.01;

$(function() {

	$("#globalnav li").hide().css({opacity: 0, filter:"alpha(opacity=0)"});

  /* roll over */
  $("a.ro").each(function() { loader.load($(this).children('img').attr('src').replace(/(\.[a-z]{3})$/i,"_o$1"));});
  $("a.ro").mouseover(function() {
    var src=$(this).children('img').attr('src');
    $(this).children('img').attr('src', src.replace(/(\.[a-z]{3})$/i,"_o$1"));
  });
  $("a.ro").mouseout(function() {
    var src=$(this).children('img').attr('src');
    $(this).children('img').attr('src', src.replace(/_o\./,"."));
  });
	
	if (/*@cc_on!@*/false) { t=0;} else { t=200;}
	$("a.over").hover(function(){ $(this).children('img').animate({opacity:0.7,filter:"alpha(opacity=70)"},t);}, function(){ $(this).children('img').animate({opacity:1,filter:"alpha(opacity=100)"},t);});
  
	// global navigation
  var i = 0;
	$("#globalnav li a").each(function() {
		$(this).hover(
			function() { $(this).parent().stop().animate({ top: "-24px"}, {duration: 200}); },
			function() {
			  $(this).parent().stop().css('opacity', 1).css('filter', "alpha(opacity=100)").animate({ top: "0px"}, {duration: 200, complete:function() {$(this).css({top: "0px"});}});}
	  );
		i++;
	});
	
	tid = setInterval("navslide()", 180);
	
	// page top
	$(".pagetop img").click(function() {
		$.scrollTo( $("#top"), { speed: 1000, axis: 'y', queue: true});
		return false;
	}).hover(
    function() {
      $(this).parents("section").animate({ top: "10px" }, { duration: 200 });
    },
    function() {
      $(this).parents("section").animate({ top: "15px" }, { duration: 200 });
    }
  );
  
  //
  $("#page-news h3 a, #page-schedule h3 a").hover(
    function() {
      $(this).animate({ marginLeft: '0px' }, { duration: 200 } )
    },
    function() {
      $(this).animate({ marginLeft: '-20px' }, { duration: 200 } )
    }
  );

});

var ct=0;
function navslide() {
	$("#globalnav li a:eq("+ct+")").parent().show().animate({top: "0px", opacity: 1}, {duration: 350});
  ct++;
	if (ct > 6) {
	  clearInterval(tid);
  }
}


function topPage() {
	$(".sparkle").css('filter', 'alpha(opacity=0)');
	if (!/*@cc_on!@*/false) {
		tp_t = setInterval("showMainPic()", 100);
	} else {
		startSparkle();
	}
}
function showMainPic() {
	$("#mainpic div img").css('opacity', tp);
	tp+=0.05;
	if (tp>=1) {
		$("#mainpic div img").css('opacity', 1);
		clearInterval(tp_t);
		startSparkle();
	}
}
function startSparkle() {
		// sparkle
		var c=0;
		$(".sparkle").each(function() {
			spark_id[c] = setInterval("sparkle("+c+")", Math.random()*1000);
			c++;
		});
}
function sparkle(c) {
	clearInterval(spark_id[c]);
	x = Math.random() * 300+200;
	y = Math.random() * 420;
	d = Math.random() * 3000 + 500;
	if (/*@cc_on!@*/false) { d = Math.random() * 1000 + 500;}
	w = Math.random() * 150 + 100 + "px";
	$(".sparkle:eq("+c+")").css({left: x, top: y, opacity: 0, width: w, height: w}).animate({opacity: 1, filter:"alpha(opacity=100)"}, {direction: d, complete: function() {$(this).animate({opacity: 0, filter:"alpha(opacity=0)"}, {direction: d*3, complete: function() { spark_id[c] = setInterval("sparkle("+c+")", Math.random()*2000);} });} });
}

