$tmp = {
	find : function(element) {
		return $(element, $('#tmp_content'));
	},
	html : function(dat) {
		$('#tmp_content').html(dat);
	},
	update : function(element, tmp_element) {
		if (typeof (tmp_element) == 'undefined')
			tmp_element = element;
		var newValue = $(tmp_element, $('#tmp_content')).html();
		return $(element, $('#content')).html(newValue);
	},
	updateAttr : function(attr, element, tmp_element) {
		if (typeof (tmp_element) == 'undefined')
			tmp_element = element;
		var newValue = $(tmp_element, $('#tmp_content')).attr(attr);
		return $(element, $('#content')).attr(attr, newValue);
	}
}

function $load(href, callback, obj) {
	var href = href.replace(rootUrl, '/');

	if (typeof (history.pushState) == 'undefined') {
		$.history.load(href);
	} else {
		history.pushState(null, null, href);
		$loadpage(href, obj);
	}
}

var $loadpage = function(href, obj) {

	$.get(href, function(dat) {
        try {
		    slide_rifle(dat, obj);
        } catch(e) {

        }
	});
}

function checkHistory(hash) {

	if (typeof (hash) != 'string') {
		hash = window.document.location.hash;
		hash = hash.replace('#', '');
	}

	if (hash.search(/products/i)) {
		if (hash) {
            var forward = hash.indexOf('next') > -1;
            $loadpage(hash, forward);
        }
	}
}

$(function() {
	if (typeof (history.pushState) == 'undefined') {
		$.history.init(checkHistory);
	} else {
		window.onpopstate = checkHistory;
	}

	$('a[rel=ajax]').live('click', function() {
		if (!window.animated) {
			var href = $(this).attr('href');
			$('a[rel=ajax]').removeClass('active');
			$(this).addClass('active');
			var callback = $(this).attr('callback');
            var forward = $(this).hasClass('link_next');
			$load(href, callback, forward);
		}
		return false;
	});
})
