jQuery.noConflict();

segments = window.location.pathname.split('/');
if(/\/$/.test(window.location.pathname)) {
	segments.pop();
}
segments.reverse();
segments.pop();
if(segments[segments.length - 1] == 'admin') {
	segments.pop();
}
segments.reverse();

Request = {
	segment: function(id) {
		return segments[id];
	},
	controller: segments[0],
	action: segments[1],
	id: segments[2],
	isAdmin: (/^\/admin/.test(window.location.pathname))
}

function returnExtension(name) {
	array = name.split('.');
	array.reverse();
	return array[0];
}
function openCart() {
	var myHorizontalSlide = new Fx.Slide('cart_slide', {mode: 'horizontal'});
	if(browser.safari) {
		if($('cart_button').getStyle('background-image') == "url(http://gotmine.woofti.co.uk/cssimages/close_cart.png)") {
		} else {
			$('cart_button').setStyle('background-image', 'url(/cssimages/close_cart.png)');
			jQuery('#cart_button').attr('rel', 'open');
			myHorizontalSlide.toggle();
		}
	} else {
		if($('cart_button').getStyle('background-image') == "url(/cssimages/close_cart.png)") {
		} else {
			$('cart_button').setStyle('background-image', 'url(/cssimages/close_cart.png)');
			jQuery('#cart_button').attr('rel', 'open');
			myHorizontalSlide.toggle();
		}
	}
}

jQuery(document).ready(function() {
	previews = jQuery("img.preview");
	current = previews[0];
	jQuery.each(previews, function(i, x) {
		i = i + 1;
		jQuery(x).click(function() {
			rel = jQuery(this).attr('id');
			target = jQuery("img[id='big_"+rel+"']");
			current = jQuery('img.active');
			jQuery(target).addClass('active');
			jQuery(current).addClass('fade');
			jQuery(current).parent().hide();
			jQuery(current).css({visibility: 'hidden'});
			jQuery(target).parent().fadeIn(2000);
			jQuery(target).css({zIndex: '500', visibility: 'visible'});
			jQuery(target).parent().css({visibility: 'visible', display: 'block'});
		});
	});
	jQuery('form#addToBasket').submit(function() {
		str = jQuery('form#addToBasket').serialize();
		jQuery('#basket').load('/shop/ajaxAddProduct.php?'+str, function() {
				jQuery.getJSON("/shop/ajaxTriggerCart.php?"+str,
				        function(data){
				          if(data.openCart == 1) {
							openCart();
							jQuery('.gotmore').slideDown(0);
						}
				});

		});
		jQuery('.productStockWarning').remove();
		jQuery.get('/shop/ajaxCheckStock.php?'+str, function(data) {
			jQuery('#productcontent').append(data);
		});
		
		return false;
	});
});