/*
	main javascript file to run on all pages
*/

$(document).ready(function() {

	//set the opacity of main layout items
	$("#horiz-stripe, #vert-stripe").css({ opacity: 0.4 });
	$("#titletext-dropshadow, #titletext-dropshadow2").css({ opacity: 0.85 });
	$("#horiz-stripe2").css({ opacity: 0.2 });
    $(".navigation div.bg").css({ opacity: 0.2 });
	
	//add backgrounds to buttons
	$(".button").each(function() {
		$(this).prepend("<div class='buttonbg'></div>");
	});

    //replace any textareas with the ckeditor if it exists
    var commentExists = $("#comment");
        if(commentExists.length > 0) {
        CKEDITOR.replace('comment', {
            toolbar : 'MyToolbar'
        });
    }
	
	//button rollover
	$(".button").hover(function() {

		//do animation
		$(this).children(".buttonbg").animate({
			backgroundColor: "#48baef",
			height: "25px",
			top: "0px",
			opacity: 0.5
		}, 1000);
        $(this).children("a:link, a:visited, a:active, a:hover").animate({
            color: "#155bc4"
        }, 1000);

	}, function() {

		//do reverse animation
		$(this).children(".buttonbg").animate({
			backgroundColor: "#327ac4",
			height: "2px",
			top: "23px",
			opacity: 1
		}, 1000);
        $(this).children("a:link, a:visited, a:active, a:hover").animate({
            color: "#023c93"
        }, 1000);

	});

  //start fading bar effect
  fadingBarAnim("fader1", 5000, 1000, "horizontal");
  fadingBarAnim("fader2", 6000, 2000, "horizontal");

});

//begin the fading bar animation
function fadingBarAnim(divID, durationTime, waitTime, horizOrVert) {

  this.divID = divID;
  this.durationTime = durationTime;
  this.waitTime = waitTime;
  this.horizOrVert = horizOrVert;

  this.recall = function() {
    setTimeout(this.timeoutFunction, this.waitTime);
  }

  this.timeoutFunction = function() {
    fadingBarAnim(this.divID, this.durationTime, this.waitTime, this.horizOrVert);
  }

  //get our element
  var thisBar = $("#"+this.divID);

  //first, set up some variables
  if(this.horizOrVert == "horizontal") {

    var spanLength = thisBar.parent().width();
    thisBar.delay(waitTime).css({ opacity: 1, width: "0px" }).animate({ opacity: 0, width: spanLength+"px" }, this.durationTime, this.recall);

  } else {

    var spanLength = thisBar.parent().height();
    

  }

}
