﻿// shop.view.js
$(document).ready(function() {
	var count = $('dl.images dd .item').size();
	var index = 0;
	
	$('dl.images dd .item:not(:first)').css('display', 'none');
	
	if(count == 1) {
		$('dl.images dt a, dl.images dt span').remove();
	} else if(count < 1) {
		$('dl.images').remove();
	}
	
	// Center Images
	$('dl.images dd .item img').each(function() {
		imgwidth = $(this).attr("width");
		imgheight = $(this).attr("height");
		
		posx = parseInt(380/2 - imgwidth/2);
		posy = parseInt(420/2 - imgheight/2);
		
		$(this).css({
			left: posx,
			top: posy
		});
	});
	
	$('dl.images dt a').click(function() {
		if($(this).attr('class') == 'next') {
			index++;
			
			if(index + 1 > count)
				index = 0;
		} else {
			index--;
			
			if(index < 0)
				index = count - 1;
		}
		
		$('dl.images dd .item').hide(0);
		$('dl.images dd .item:eq(' + index + ')').show(0);
		
		return false;
	});
	
	
	var category = $('#submenu > li:first > a');
	
	if($('#submenu .newlevel').size() == 0) {
		url = category.attr('href');
		
		$.post(url, function(data) {
			category.parent().parent().find('.newlevel:first').remove();
			
			source = $(data).find('#submenu .newlevel:first');
			category.parent().after(source);
		});
	}
		
	$('#submenu > li:first > a').click(function() {
		return false;
	});
	
	$('.com-chkout-steps .step:last-child').css({display:'none'});

});
