//  if (!("console" in window) || !("firebug" in console))
//  {
//      var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
//     "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
// 
//     window.console = {};
//     for (var i = 0; i < names.length; ++i)
//         window.console[names[i]] = function() {};
// }

var blogTransSpeed = 1000;
var blogSpeed = 5000;
var blogCount = jQuery('#blog-items li').size();
var emailVal;
jQuery(function($){
	
	$('.script').removeClass('script');
	$('.noscript').css('display', 'none');
	$('.scriptHide').css('display', 'none').removeClass('scriptHide');

	// :first-child fix
	$('#main-footer li:first-child, #main-cart .row a:first-child').addClass('first');
	
	if ($.browser.msie) {
		$('ul li a, ol li a').css('display', 'inline-block');
		$(window).load(function(){
			$('a.button').corner('12px');
			$('#global-kickers button').corner('10px');
		});
		
		$('button').click(function(){
			$(this).parents('form').submit();
			return false;
		});
	} else {
		$('a.button').corner('12px');
		$('#global-kickers button').corner('10px');
	}
	
	$('#kicker-email-text').click(function(){
		emailVal = $(this).val();
		$(this).val('');
	}).blur(function(){
		if ('' == $(this).val()) {
			$(this).val(emailVal);
		}
	});
	
	$('.mission_link').click(function(){
		newWin($(this).attr('href'), 480, 360, 'mission');
		return false;
	});
	
	// Blog ticker
	if (blogCount > 0) {
		$('#blog-target')
		.append(':&nbsp;')
		.append($('#blog-items'))
		.parent().css('width', '500px');
		
		if (blogCount > 1) {
			// Start the ticker by hiding all items
			$('#blog-items li').css('display', 'none');
			
			// Store elements in array
			var items = $('#blog-items').children().get();
			var last = null;
			var current = 1;
			
			var continueFade = function() {
				if (last != null) {
					$(items[last-1]).slideUp(blogTransSpeed, function(){
						$(items[current-1]).slideDown(blogTransSpeed);
					});
				} else {
					$(items[current-1]).slideDown(blogTransSpeed);					
				}
				
				
				last = current;
				if (current == blogCount) {
					current = 1;
				} else {
					current++;
				}
				
				setTimeout(continueFade, blogSpeed);
			};
			
			// Start the looping
			continueFade();
		}		
	}
	
});

function newWin(url, w, h, winName) {
	l = (screen.width/2) - (w/2);
	t = (screen.height/2) - (h/2);
	var win = window.open(url, winName, 'width='+w+',height='+h+',left='+l+',top='+t+',resizable=yes,status=no,toolbar=no,menubar=no,location=no,scrollbars=no');
	win.focus();
}

/**
*
* Javascript trim, ltrim, rtrim
* http://www.webtoolkit.info/
*
*
**/

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}