/*
	Author: The Bridge
	Copyright (c): 2011 The Bridge
	Created: 14-11-2011
	Last Modified: 154-11-2011
	Name: NavItem
	Description: Handle main navigtion links
*/

(function( $ ){
	$.fn.navitem = function( options ) {  

    var settings = {
      'url'         :  ''
    };

    return this.each(function() {        
    	// If options exist, lets merge them
      	// with our default settings
      	if ( options ) { 
        	$.extend( settings, options );
      	}
      	
		var $this = $(this);
        var text = $('span', $this);
        var id = $this.attr("id");
        var bits = id.split('_');
        var pos = parseInt(bits[1]);
        var w = $this.width();
        var l = 0;
        var maxpos = $('#nav span').length;
        
        if(pos == maxpos) w = w + 20;

        if (pos > 1){
        	var prevItemPos = parseInt($("#navl_"+(pos-1)).css("left"));
        	var m = (pos == maxpos) ? 50 : 80;
        	l = prevItemPos + w + m;
        }
        
        $this.css("left", l+"px");
        //text.css("left", l+"px");
           	
        $this.hover(
			function () {
				text.animate( { top : '-=20px' }, { duration: 180, easing : 'easeOutCubic' } );
			}, 
			function () {
				text.animate( { top : '0px' }, { duration: 180, easing : 'easeOutCubic' } );
			}
		).click(function(e){
			e.preventDefault();
			if (typeof $this.attr("target") != 'undefined'){
				window.open($this.attr("href"), $this.attr("target"));
			}else{
				system.ScrollTo($this.attr("rel"));
			}
		});
    });
  };
})( jQuery );

