/* Author:

*/

$(window).load(function(){

//  $('a.lightbox').lightBox(); // Select all links with lightbox class
//  $('area.lightbox').lightBox(); // Select all links with lightbox class

  // changes the background color on hover on the news block on the front page
  $("div.newsblock").hover(
    function(){$(this).css(
            {'background-image':'url(assets/images/news-bg-highlight.jpg)',
            'background-color':'#F1A2A2'})},
    function(){$(this).css(
            {'background-image':'url(assets/images/news-bg.jpg)',
            'background-color':'#D8D8D8'})}
  );
  $("a[rel^=external]").attr({ target: "_blank" });
  $("a.external").attr({ target: "_blank" });

  $("a[rel='colorbox']").colorbox();

  // fits image to container
  $(".imagefit").imagefit().css({'visibility':'visible'});

  $('a.email').each(function(i) {
    var text = $(this).text();
    var address = text.replace(" /at/ ", "@");
    $(this).attr('href', 'mailto:' + address);
    $(this).text(address);
  });

  if (($("form#fashion-form").length > 0) && ($("p.form-msg").length > 0)) {
    $("form#fashion-form").hide();
  }

  if ($("form#awardsform").length > 0) {
    // counters for textareas
    $("#summary").counter({type: 'char',goal: 400,count: 'down'});
    $("#orgstructure").counter({type: 'char',goal: 600,count: 'down'});
    $("#keyexperience").counter({type: 'char',goal: 1000,count: 'down'});
    $("#keyservices").counter({type: 'char',goal: 600,count: 'down'});
    $("#aim").counter({type: 'char',goal: 600,count: 'down'});
    $("#objectives").counter({type: 'char',goal: 600,count: 'down'});
    $("#excellence").counter({type: 'char',goal: 2000,count: 'down'});

    // descriptions of categories
//    for (var i=0; i<6; i++) {
//      $("a#category"+i+"a").click(function() {
//          //$("#category"+i+"text").css({'display':'block'});
//        alert(i);
//      });
//    }

    var descs = [0,1,2,3,4,5];

    $("#categories a").each(
      function( intIndex ){

      // Bind the onclick event to perform the function
      $(this).bind (
          "click",
          function(){
            //$("#category"+intIndex+"text").css({'display':'block'});
            if ($("#category"+intIndex+"text").css('display')!='block'){
              $("#category"+intIndex+"text").slideDown().css({'display':'block'});
            } else {
              $("#category"+intIndex+"text").slideUp().css({'display':'none'});
            }
          }
        );

      }
    );

  }



  // slider for front page
  $('.flexslider').flexslider({
        animation: "slide",              //Select your animation type (fade/slide)
        slideshow: true,                //Should the slider animate automatically by default? (true/false)
        slideshowSpeed: 4000,           //Set the speed of the slideshow cycling, in milliseconds
        animationDuration: 1500,         //Set the speed of animations, in milliseconds
        directionNav: false,             //Create navigation for previous/next navigation? (true/false)
        controlNav: true,               //Create navigation for paging control of each clide? (true/false)
        keyboardNav: false,              //Allow for keyboard navigation using left/right keys (true/false)
        touchSwipe: false,               //Touch swipe gestures for left/right slide navigation (true/false)
        prevText: "Previous",           //Set the text for the "previous" directionNav item
        nextText: "Next",               //Set the text for the "next" directionNav item
        pausePlay: false,               //Create pause/play dynamic element (true/false)
        randomize: false,               //Randomize slide order on page load? (true/false)
        slideToStart: 0,                //The slide that the slider should start on. Array notation (0 = first slide)
        animationLoop: true,            //Should the animation loop? If false, directionNav will received disabled classes when at either end (true/false)
        pauseOnAction: true,            //Pause the slideshow when interacting with control elements, highly recommended. (true/false)
        pauseOnHover: false,            //Pause the slideshow when hovering over slider, then resume when no longer hovering (true/false)
        controlsContainer: ".flex-container",          //Advanced property: Can declare which container the navigation elements should be appended too. Default container is the flexSlider element. Example use would be ".flexslider-container", "#container", etc. If the given element is not found, the default action will be taken.
        manualControls: ""             //Advanced property: Can declare custom control navigation. Example would be ".flex-control-nav" or "#tabs-nav", etc. The number of elements in your controlNav should match the number of slides/tabs (obviously).
//        start: function(){},            //Callback: function(slider) - Fires when the slider loads the first slide
//        before: function(){},           //Callback: function(slider) - Fires asynchronously with each slider animation
//        after: function(){},            //Callback: function(slider) - Fires after each slider animation completes
//        end: function(){}               //Callback: function(slider) - Fires when the slider reaches the last slide (asynchronous)

    });

  $('.newsletter-title:contains(April 2010)').append('<br/><br/><a href="ninedots.php"><strong>View solution to the puzzle.</strong></a>');
	$("#navigation li").hover(
		function(){ $("ul", this).fadeIn("fast"); },
		function() { }
	);
	if (document.all) {
		$("#navigation li").hoverClass ("sfHover");
	}
});

$.fn.hoverClass = function(c) {
	return this.each(function(){
		$(this).hover(
			function() { $(this).addClass(c);  },
			function() { $(this).removeClass(c); }
		);
	});
};







