jQuery(document).ready(function($){
	
	$('.topmenupages').hover(
		function(){
			if($(this).hasClass('topmenu_active')){
				$(this).addClass('topmenu_over topmenu_over_active').removeClass('topmenu_active');
			}	
			else{
			$(this).removeClass('topmenu_normal').addClass('topmenu_over');
			}
		},
		function(){
			if($(this).hasClass('topmenu_over_active')){
				$(this).removeClass('topmenu_over topmenu_over_active').addClass('topmenu_active');}
			else{
				$(this).removeClass('topmenu_over').addClass('topmenu_normal');
			}
		}
	);
	
	$('.accordion').accordion({
		header: "h3",
		autoHeight:false,
		collapsible:true,
		navigation:true

	
	});
	
	$('.leftmenuheader').css({'backgroundColor':'#235a7d'});
	
	$('.customslideshow').fadeIn('slow').cycle({
		fx: 'fade',
		autostop:0,
		pause:1,
		delay:0,
		speed:3000
	});
	
	$('.topmenupages').each(
		function(){
			if($(this).text()=="Home"){
				$(this).addClass('ishome');
			}
		}
	);
	
	$('.showcontent').live('click',function(){
		// set the class of the current item and the class of the others. The function above for #topmenupages handles the hover event, this covers the click
		$('.sidemenu_active').removeClass('sidemenu_active');
		if($(this).hasClass('topmenupages')){// this is a top menu item
			if($(this).hasClass('topmenu_over')){// set the active top menu page and clear the others
				$('.topmenu_active').removeClass('topmenu_active').addClass('topmenu_normal');
				$(this).addClass('topmenu_active').removeClass('topmenu_normal');
			}
		}
		else{
			// the side menu options just require us to set all of the top menu items to normal
			$('.topmenu_active').removeClass('topmenu_active').addClass('topmenu_normal');
			$(this).addClass('sidemenu_active');
		}
		// the main content mechanism. This action is used on the top and side menus to call content from either menu and populate the main post div
		var postid=$(this).attr('data');// each menu element must include its ID
		var posttype;
		if($(this).hasClass('topmenupages')){
			posttype='page';
		}
		else{
			posttype='post';
		}
		
		if($(this).hasClass('ishome')){
			// if this is the home page, show the slide show and set the helper classes and show the featured post
			$('#slideshowcontainer').addClass('isshowing').removeClass('ishidden');
		}
		else{
			if($('#slideshowcontainer').hasClass('isshowing')){// hide the slide show and add a helper class to show that it's hidden
				$('#slideshowcontainer').removeClass('isshowing').addClass('ishidden');
			}
					
		}
		$.post('/wp-content/themes/HouseofHearing2011/show-main-content.php',
			{
				'ajaxrequest':'retrievecontent',
				'posttype':posttype,
				'postid':postid
			},
				function (data){
					// do something with returned data
			
					$('#maincontentpane').animate({
						opacity:0
						}, 600, function() {
							if($('#slideshowcontainer').hasClass('isshowing')){
								$('#slideshowcontainer').show();
								$('#featuredpost').show();
							}
							else{
								$('#slideshowcontainer').hide();
								$('#featuredpost').hide();
							}
							$('#maincontentpane').html(data);
							// get the font size preferences
							var fontchoice=$('#fontchoice').html();
							if(fontchoice!=''){
								fca=fontchoice.split(",");
								if(fca.length==2){
									var nfcafont=fca[0].split("=");
									var nfcaline=fca[1].split("=");
									$(".entry").css({fontSize:nfcafont[1] +'px',lineHeight: nfcaline[1] +'px'});// end of animation
								}
							}
							$('#maincontentpane').animate({
								opacity:1.0
								},700,function(){
									// animation is done
								});
								
							});
				}
			);// end post statement	
	});
	
	  // Reset Font Size
  var originalFontSize = $('html').css('font-size');
    $(".resetFont").click(function(){
    $('html').css('font-size', originalFontSize);
  });
  // Increase Font Size
  $(".largestfont").click(function(){
    var currentFontSize = $('html').css('font-size');
	if(currentFontSize=='small'){
		currentFontSize=10;
	}
    var currentFontSizeNum = parseFloat(currentFontSize, 10);
    var newFontSize = currentFontSizeNum*1.2;
	var entryFontSize=$('.entry').css('font-size');
    var currentEntryFontSizeNum = parseFloat(entryFontSize, 10);
    var newEntryFontSize = currentEntryFontSizeNum*1.2;
	var newEntryLineHeight=newEntryFontSize+4;
//    $('html').css('font-size', newFontSize);
    $(".entry").css({fontSize:newEntryFontSize +'px',lineHeight: newEntryLineHeight+'px'});
    $('#fontchoice').html('fontsize=' + newEntryFontSize + ',lineheight=' + newEntryLineHeight);

    return false;
  });
  // Decrease Font Size
  $(".normalfont").click(function(){
    var entryFontSize = $('.entry').css('font-size');
    var currentEntryFontSizeNum = parseFloat(entryFontSize, 10);
    var newEntryFontSize = currentEntryFontSizeNum*0.8;
	var newEntryLineHeight=newEntryFontSize+4;
    $(".entry").css({fontSize:newEntryFontSize +'px',lineHeight: newEntryLineHeight+'px'});
    $('#fontchoice').html('fontsize=' + newEntryFontSize + ',lineheight=' + newEntryLineHeight);
    return false;
  });


});


