/*
	Nike US Football Common JavaScript Library
	Author: Scott Kyle
*/

// adds new helper methods to the prototypes of String, Number, Array, Function, Date, and RegExp
// BEWARE of the consequences of overriding these methods...
NIKEOS.extendNatives();

var Gridiron = {
	
	features : function(features) {
		for (var id in features) {
			var ext = '';
			if (features[id].type) ext = 'swf';
			else if (features[id].src) ext = features[id].src.match(/\.(\w+)$/i)[1];
			
			if (ext == 'swf') {
				features[id].queries = 'param_';
				features[id].element_id = id;
				features[id].flash = '9.0.47';			// minimum version for some AS3 features
				NIKEOS.insertSWF(features[id]) || JQ('#no-flash').show();
			}
			else if (ext.test(/jpe?g|png|gif/i)) {
				var $target = JQ('#' + id).empty().append('<img src="' + features[id].src + '" />');
				if (features[id].href) $target.wrapInner('<a href="' + features[id].href + '" />');
			}
		}
	},
	
	changePosts : function(tag) {
		if (tag) {
			JQ('#posts').load('feed?tag=' + tag);
			JQ('#content').show();
		}
		else {
			JQ('#posts').empty();
			if (tag === false) JQ('#content').hide();
		}
	}
	
};

(function($) {
	
	// METHODS
	
	$.fn.extend({
		
		navigateSWF : function(section) {
			var id = this.find('embed, object')[0].id;
			var swf = $.browser.msie ? window[id] : document[id];
			swf.navigateSwfTo(section);
			return this;
		},
		
		hoverClass : function(klass) {
			return this.hover(
				function() {
					$(this).addClass(klass || 'hover');
				},
				function() {
					$(this).removeClass(klass || 'hover');
				}
			);
		},
		
		track : function(fn, click) {
			return this.click(function() {
				var name = (typeof fn == 'string') ? fn : fn.call($(this));
				if (!name) return;
				else name = tracker_obj.pageName.replace(/[^>]+$/, name);
				
				if (click)
					tracking.click_track(name);
				else {
					tracking.click({
						pageName : name,
						prop18 : tracker_obj.prop18,
						prop19 : tracker_obj.prop19
					});
				}
			});
		},
		
		// event delegating
		delegate : function(eventType, rules) {
			return this.bind(eventType, function(e) {
				var $targets = $(e.target).parents().andSelf();
				for (var selector in rules) {
					var $match = $targets.filter(selector);
					if ($match.size()) rules[selector].apply($match, arguments);
			 	}
			});
		}
		
	});
})(jQuery);

// IE stuff
is_ie = JQ.browser.msie;
is_ie6 = is_ie && JQ.browser.version < 7;


