
var cc = new CookieHandler();
var isopen = true;
$(function(){
	
	if(navigator.userAgent.match(/iPad/i) != null || navigator.userAgent.match(/iPod/i) != null || navigator.userAgent.match(/iPhone/i) != null){
		myScroll = new iScroll('scroll', {desktopCompatibility:true});
		document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
	}
	
	/*	
	var scroll = $("#scroll");
	$(":range").rangeinput({
		onSlide: function(ev, step)  {
			scroll.css({left: -step});
		},
		progress: true,
		value: 0,
		change: function(e, i) {
			scroll.animate({left: -i}, "fast");
		},
		speed: 0
	
	});
	*/
	if(navigator.userAgent.match(/iPad/i) != null || navigator.userAgent.match(/iPod/i) != null || navigator.userAgent.match(/iPhone/i) != null){
		$("#header").click(function(){	
			if(cc.getCookie('mobile_isopen')){									
				$(this).stop().animate({ top: '0px',backgroundColor: '#ffffff'}, 300, function() {});
				cc.deleteCookie('mobile_isopen');
			}else{
				$(this).stop().animate({ top: -($(this).height())+'px'}, 200, function() {$(this).stop().animate({ backgroundColor: '#f5acd9' });});	
			}
		});	
	}else{

		if(cc.getCookie('isopen')){
			$("#header").hover(function(){				 
				$(this).stop().animate({ top: '0px',backgroundColor: '#ffffff'}, 300, function() {});	
				},function(){
				$(this).stop().animate({ top: -($(this).height())+'px'}, 200, function() {$(this).stop().animate({ backgroundColor: '#f5acd9' });});		
			});	
		}
	}
	$(".thumb").hover(function(){				 
		$('.info',this).stop(true, false).fadeTo('medium', 0.7);
		},function(){
		$('.info',this).stop(true, false).fadeTo('medium', 0.0);
	});	

	$('#scroll img').each(function(i) {
		$(this).delay(i*400).fadeIn('slow')
	});
	
	animate({ backgroundColor: '#f5acd9' });
});	

$(document).ready(function(){
    //loadIMG(myJSON,0);
});

function loadIMG(myJSON,index){
    if(index<myJSON.images.length){
        $("#scroll").append('<img id="' + myJSON.images[index].name + '" src="' + myJSON.images[index].src + '" height="600px" width="'+myJSON.images[index].width+'px" style="display:none; margin-right:1px" />');
        $("#"+myJSON.images[index].name).load(function(){
            $(".loading").remove();
            $("#"+myJSON.images[index].name).fadeIn(400,function(){
                index++;
                loadIMG(myJSON,index);
            });
        });
    }
}




function CookieHandler() {

	this.setCookie = function (name, value, seconds) {
 
		if (typeof(seconds) != 'undefined') {
			var date = new Date();
			date.setTime(date.getTime() + (seconds*1000));
			var expires = "; expires=" + date.toGMTString();
		}
		else {
			var expires = "";
		}
 
		document.cookie = name+"="+value+expires+"; path=/";
		
	}
 
	this.getCookie = function (name) {
 
		name = name + "=";
		var carray = document.cookie.split(';');
 
		for(var i=0;i < carray.length;i++) {
			var c = carray[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
		}
 
		return null;
	}
 
	this.deleteCookie = function (name) {
		this.setCookie(name, "", -1);
	}
 
}

