$(document).ready(function(){

	/*Tweets*/
	
	
	
    $(".tweets").tweet({
        username: "odysseytheatre",
        join_text: "auto",
        avatar_size: 32,
        count: 3,
        auto_join_text_default: "we said,", 
        auto_join_text_ed: "we",
        auto_join_text_ing: "we were",
        auto_join_text_reply: "we replied to",
        auto_join_text_url: "we were checking out",
        loading_text: "loading tweets..."
    });
    
    //Side bar rollover 
    
    $('.rollover .over').hide();
    
    $('.rollover').hover(function() {
        $(".over", this).show();
        $(".out", this).hide();
    }, function() {
        $(".over", this).hide();
        $(".out", this).show();
    });

    
    //trigger ajax on submit
	$('#mailingForm').submit( function(){
		

		
		//hide the form
		//$('#contactForm').hide();
		
		//send the ajax request  
		$.get('http://www.odysseytheatre.ca/wp-content/themes/Odyssey/mailinglist.php',{email:$('#email').val()},
	
		//return the data
		function(data){
			
			if(data != "Please enter your valid email address<br>"){
			$('#mailingForm .submit').hide(); 
			}
			//hide the graphic
			$('#contact-errors').html(data);
			 
		});	
	
		//stay on the page					
		return false;	
	});
    
    /* View More Config*/
    
    $('.entry-content .panel').jMultiTruncate(); 
    
    $('.entry-content').jTruncate(); 
    
	
	/* CHANGE THE BACKGROUND*/
	
	function changeBg(_image){
		if(_image){
		
			$(document.body).css("background-image", "url(" + themeFolder + "/images/bgs/" + _image + ")");
		}
	}
	
	/*MENU FADE IN FUNCTION */
	 $("#menu ul li").each(function(i) {
		if ($("a", this).attr("title") == "Events") {
	
				$("ul", this).css({"background-image":"url(" + themeFolder + "/images/subnav/1.png)", 
									"border-bottom": '8px solid #2054b3'})
	
			} else if ($("a", this).attr("title") == "Behind the Mask") {
	
				$("ul", this).css({"background-image":"url(" + themeFolder + "/images/subnav/2.png)", 
									"border-bottom": '8px solid #b91b04'})
	
			} else if ($("a", this).attr("title") == "Artistic Development") {
	
				$("ul", this).css({"background-image":"url(" + themeFolder + "/images/subnav/3.png)", 
									"border-bottom": '8px solid #FFCC00'})
	
			} else if ($("a", this).attr("title") == "Get Involved") {
	
				$("ul", this).css({"background-image":"url(" + themeFolder + "/images/subnav/4.png)", 
									"border-bottom": '8px solid #3cad04'})
	
			}
	});

	
	
	var toggle = function(direction, display) {
	    return function() {
	      var self = this;
	      var ul = $("ul", this);
	      if( ul.css("display") == display && !self["block" + direction] ) {
	        self["block" + direction] = true;
	        ul["fade" + direction]("fast", function() {
	          self["block" + direction] = false;
	        });
			
	      }
	    };
	  }
	  $("#menu ul li").hover(toggle("In", "none"), toggle("Out", "block"));
	  $("#menu ul li ul").hide();
    
	  
	  changeBg(image);
	  
	  /*ACCORDION */
	  
	  //slides the element with class "menu_body" when paragraph with class "menu_head" is clicked 
	$("#accordion .accordionItem .entry-content").hide();
	$("#accordion .accordionItem .title").click(function()
    {
    	
		$(this).next("div.entry-content").slideToggle(500).siblings("div.entry-content").slideUp("slow");

	});
	
	/* Fancybox settings */
	
	$("a[rel=image_gallery]").fancybox();
	
	/* Using custom settings */
	
	$("a#inline").fancybox({
		'hideOnContentClick': true
	});

	$("a.group").fancybox({
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	false
	});
	
	
	
	/* Sidebar Image rollover */
	

/*
$("#sidebar-pages li.widget_sp_image img").hover(function () {
  $(this).stop().animate({opacity: 0.5}, "fast");
  }, function () {
  $(this).stop().animate({opacity: 1}, "fast");
  });
*/


	
	
	
	 
});



