var aboutSliderHeight = "80px";
var aboutSliderState = "closed";

jQuery(function($){

	// start readmore links
	
	// hide the expanded text
	$('.moretext').hide();
	
	// add the readmore links
	$('.introtext').append('<a href="#" class="readmore">Read More</a>');
	$('.introtext p').css('margin','0px');
	$('.introtext').css('margin-bottom','20px');
	
	//$('.moretext').after('<p><a href="#" class="readmore">Read More</a></p>');

	// bind readmore link event
	$('.readmore').click(function(){
		$(this).parent().next().toggle( 'slow' );
		$(this).remove();
		return false;
	});
	
	// end readmore links
	
	// Special handling of About section
	$('#aboutSlider').attr("box_h", $('#aboutSlider').height());
	$('#aboutSlider').css("overflow", "hidden");
	$('#aboutSlider').css("height", aboutSliderHeight);
	$('#aboutSlider').after('<p><a href="#" id="aboutSliderReadMore">Read More</a></p>');

	$('#aboutSliderReadMore').click(function(){
		
		if(aboutSliderState == "closed") {
			var openHeight = $("#aboutSlider").attr("box_h") + "px";
			$("#aboutSlider").animate({"height": openHeight}, {duration: "slow" });
			aboutSliderState = "open";
		} else {
			$("#aboutSlider").animate({"height": aboutSliderHeight}, {duration: "slow" });
			aboutSliderState = "closed";
		}
		
		$(this).remove();

		return false;
		
	});
	
	
	
	// start dialog links

	// define dialog settins
	$('#dialog_video').dialog({
		modal:true,
		autoOpen:false,
		resizable:false,
		draggable:false,
		width:690,
		height:520
	});
	
	// custom close button
	$('.dialog_buttons a.close').click(function(){
		$(this).parent().parent().dialog('close');
		return false;
	});
	
	$('#dialog_scribd').dialog({
		modal:true,
		autoOpen:false,
		resizable:false,
		draggable:false,
		width:690,
		height:520,
		buttons: {
			close: function() {
				$(this).dialog("close");
				
			}
		}
	});
	
	// bind link to dialog
	$(".video_link").click(function(){
		var title = $(this).attr("title");
		$('#dialog_video').dialog('option', 'title', title );
		$('#dialog_video').dialog('option', 'height', 520);
		$("#dialog_video").dialog("open");

		
		
		return false;
	});

	// bind link to dialog
	$('.scribd_link').click(function(){
		var title = $(this).attr("title");
		$('#dialog_scribd').dialog('option', 'title', title );
		$('#dialog_scribd').dialog('option', 'height', 750);
		$("#dialog_scribd").dialog("open");
		return false;
	});

	// end dialog links

	// start quotes
	
	var items = $('.quote'); // the items to scroll through
	var i = 0; // the counter to select the current item
	var speed = 5000; // delay to wait for next quote
	
	// execute the loop
	setInterval ( function(){
		
		// hide all but the currently active item
		items.not( items.eq( i ) ).fadeOut();
		
		// show thew current item
		items.eq( i ).fadeIn();

		// increment the counter
		i++;

		// if the counter has hit the maximum items, reset it
		if( i === items.length ) {
			i = 0;
		}

	}, speed );
	
	// end quotes

	
});

