var debug = false;
var isiPad = navigator.userAgent.match(/iPad/i) != null;
var	productsamount = 0;
var	totalwidth = 0;

$(document).ready(function(){

	productsamount = $("#prodnav ul li").length;
	totalwidth = 192 * productsamount;

	$('#navitem21 a').click(function(){
		animateScroller('down');
		return false;
	});
	
	$('#scrollerwrapper').hover(function(){
		clearTimeout(scrollertimeout);
	},function(){
		scrollertimeout = setTimeout("animateScroller('up')",2000);
	});
	
	//$('#prodnav ul').css({'width': totalwidth + 'px'});
	
	if(isiPad) {
		$('html').addClass('ipad');
		initipad();
	} else {
		initnormal();
	}
});




function initnormal() {
	/*
	 *	supersize background image
	 */

	supersizeimage = typeof supersizeimage == 'undefined' ? '/image/photo.jpg' : supersizeimage;	//var supersizeimage is declared in <head>
	applysupersize = typeof applysupersize == 'undefined' ? false : applysupersize;

	if(!debug && applysupersize) {
		$.supersized({
			slides	:  [ {image : supersizeimage} ],
			vertical_center : 0,
			horizontal_center : 1
		});
	} else {
		//hide supersized preload-icon
		$('#supersized, #supersized-loader').hide();
	}


	/*
	 *	product carousel
	 */
	/*
	$('#prodnav ul').jcarousel({
		scroll: 1
	}).css({'margin':'0 auto'});
	*/
}






function initipad() {
	//document.addEventListener('touchmove', function(e){ e.preventDefault(); });
	//myScroll = new iScroll('scroller',{hScrollbar:false});

	$('#ipadbg').css({'display':'block'}).click(function(){
		animateScroller('up');
	});
}



var scrollertimeout = false;
function animateScroller(dir) {
		//console.log('animateScroller '+ dir);
		if(dir == 'up') {
			$('#scrollerwrapper').animate({'top':'-100px','opacity':'0'}, {duration:400, easing:'swing', queue:false});
		} else if (dir == 'down'){
			$('#scrollerwrapper').animate({'top':'0px','opacity':'1'}, {duration:300, easing:'swing', queue:false});
			scrollertimeout = setTimeout("animateScroller('up')",2000);
		} else {
			return false;
		}
}

