/* 	jPreview jQuery Plugins
	Plugin: jPreview Plugin
	Author: Shariq Torres
	File: jpreview.js
	Description: The jQuery plugin */
(function($) {
  $.fn.jpreview = function(options) {
	/* set default options 
    var options = $.extend({
			firstOption: 'default value',
			anotherOption: 'default value',
			groupedOptions: { optionA: 'default value' , optionB: 100, optionC: true }
    }, options);
	*/

	
	
	/* iterate over the matched elements passed to the plugin */
	/*example would be $('#content').jpreview(); */
	$(this).each(function() {
			//get the id attribute of the div
			var obj = $(this).children('div');
			$(this).addClass('jpreview');
			obj.each(function(){
				//find the parent
				var parent = $(this).parent();
				//get the title
				var title = $(this).attr('title');
				//create the link
				parent.append("<a href='#' rel='"+title+"' class='navlinks'>"+title+"</a>");
				//hide the element
				$(this).hide();
				});
			//show the first element
			obj.first().show();
			
			//add event listener that will show the correct div
			$('.navlinks').click(function(e){
						e.preventDefault();
						var titleOfSelectedDiv = $(this).attr('rel');
						$(".jpreview div[title!="+titleOfSelectedDiv+"]").hide();
						$(".jpreview div[title="+titleOfSelectedDiv+"]").show();	
						
					});
			
		
			
			
    });
  }
})(jQuery);
