/*	Creates a navigation menu out of a DIV and UL elements
 * 	- Creates a back ground color or image to overlay the navigation tiems
 *  - Uses animation when loading and on interaction
 *  - Suport roating background colors or images
 *  - custom call back on click?
 *  - font image titles
 */
(function($){
	$.fn.siteNavigation = function(method){				
			//Default plugin settings

			var controlClick = function(){
				var href = $("a", $(this)).attr("href");
				window.location = href;
			};
			
			var controlMouseOver = function(){
				$(this).fadeTo(250, 0.5);
			};
			
			var controlMouseOut = function(){
				$(this).fadeTo(250, 1);
			};
			
			var settings = {
					clickCallback : controlClick
				};
							
			var methods = {
				init:function(options){
					//If user as specified options then merge into the settings
					if(options) $.extend(settings, options);
					
					$("li a",this).each(function(){
						$(this).html('');
					})
					
					//Wire event handlers
					$("li",this).click(settings.clickCallback);
					$("li",this).mouseover(controlMouseOver);
					$("li",this).mouseout(controlMouseOut);
					
					//Set active control
					$("a",this).each(function(){
						if($(this).attr("href") == window.location.pathname){
							$(this).parent().css("border","1px solid #d1d1d1");
							$(this).parent().unbind();
						}
					})
					
				}
			};
			
			// Method calling logic
		    if ( methods[method] ) {
		      return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
		    } else if ( typeof method === 'object' || ! method ) {
		      return methods.init.apply( this, arguments );
		    } else {
		      $.error( 'Method ' +  method + ' does not exist' );
		    }    
	};
})(jQuery);

var siteIndex = {
	init:function(){
		$(".siteNavigation").siteNavigation(
		    {
			}
		);
	}
};

var bookmarks = {
	init:function(){
		$(".bookmark").click(this.bookmarkClick);
		$("#checkStatus").click(this.checkStatusClick);
	},
	bookmarkClick:function(){
		$("#siteTitle").val($(".title a",$(this)).html());
		$("#siteURL").val($(".title a",$(this)).attr("href"));
		$("#siteID").val($(":hidden",$(this)).val());		
	},
	checkStatusClick:function(){
		$.post("/services/checkStatus",{id:$("#siteID").val()},function(data){
			alert(data);
		})
	}
}
