// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults


//  Suckerfish for jQuery
//
var jSucker = function(css_id, css_class){
		return {
			
			css_class: "",
			css_id: "",
			
			init: function( css_id, css_class ){
				// if this is ie6
				if( document.all && document.getElementById){
					this.css_id = css_id;
					this.css_class = css_class;
					var lis = css_id + " li";
					jQuery(lis).mouseover( this.over );
					jQuery(lis).mouseout( this.out );
				}
			},
			
			over: function(){
				jQuery(this).addClass(jSucker.css_class);
			},
			
			out: function(){
				jQuery(this).removeClass(jSucker.css_class);
			}
			
		};
}();

var init_sucker = function(){
	jSucker.init("#primary-nav", "over");
	jSucker.init("#main-nav", "over");
}

jQuery(document).ready(init_sucker);

// For add_another_image_field_link
$(document).ready(function() {
	$('#add_another_image_field_link').click(function(event){ 
			var div = $('#add_another_image_field').prev();
			number = parseInt(div.attr("id").split('_')[1]) + 1;

			var new_div = div.clone();
			new_div.children("input").val("");
			new_div.attr("id","image_"+number);
			new_div.children("label").text("Image #" + number);
			$("#add_another_image_field").before(new_div);
			return false;
		});
});

$(document).ready(function() {
  $('#add_another_video_field_link').click(function(event) {
    var div = $('#add_another_video_field').prev();
    number = parseInt(div.attr("id").split('_')[1]) + 1;
    
    var new_div = div.clone();
    new_div.children("input").val("");
    new_div.attr("id","video_"+number);
    new_div.children("label").text("Video #"+number);
    $("#add_another_video_field").before(new_div);
    return false;
  });
});


// To setup scrolling windows
$(document).ready(function() {
  // alert("inside jScrollPane Init");
  if ($('.scroll-pane').length > 0) {
    $('.scroll-pane').jScrollPane({showArrows:true, reinitialiseOnImageLoad:true, topCapHeight:20, scrollbarWidth:7 });    
  }
	
});

function setNewWindow() {
  // Rewriting this function to use jQuery and use class external instead of rel external -Spencer
  $("a.external").click(function() {
    window.open($(this).attr("href"));
    return false;
  });
}
jQuery(document).ready(setNewWindow);


$(document).ready(function() {
	if ($("#about_accordion").length > 0) {
		$("#about_accordion").accordion({ autoHeight: false, header: '.title', navigation: true});
		
	}
	if ($(".linkMenu").length > 0) {
	  $(".linkMenu").accordion({ autoHeight: false, header: '.title', navigation: true });
	}
	
	if ($("#newsHeader").length > 0) {
	  $("#community-link-home").mouseover(function() {
      // alert("mouseover function fired.");
	    $(this).addClass('mainsite-hover');
      $("#community-link").addClass('mainsite-hover');
	  });
	  $("#community-link-home").mouseout(function() {
      // alert("mouseout function fired");
      $(this).removeClass('mainsite-hover');
      $("#community-link").removeClass('mainsite-hover');
	  });
	  
	  $("#community-link").mouseover(function() {
      // alert("mouseover function fired.");
	    $(this).addClass('community-hover');
      $("#community-link-home").addClass('community-hover');
	  });
	  $("#community-link").mouseout(function() {
      // alert("mouseout function fired");
      $(this).removeClass('community-hover');
      $("#community-link-home").removeClass('community-hover');
	  });
	  
	}
});
var init_fade_in_class = function() {
  // alert("hello!");
  $(".fade-in").css('display', 'none');
  if(typeof init_image_rotate == 'function') {
    // alert("inside image_rotate!");
    $(".fade-in").fadeIn(500, init_image_rotate);
  } else {
    // alert("not inside image_rorate!");
    $(".fade-in").fadeIn(500);
  }
}
jQuery(document).ready(init_fade_in_class);

