/*if (navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i)) {
var viewportmeta = document.querySelectorAll('meta[name="viewport"]')[0];
if (viewportmeta) {
viewportmeta.content = 'width=device-width, minimum-scale=1.0, maximum-scale=1.0';
document.body.addEventListener('gesturestart', function() {
viewportmeta.content = 'width=device-width, minimum-scale=0.25, maximum-scale=1.6';
}, false);
}
}*/
$(document).ready(function() {

    $('.blueberry').blueberry();

    $('#parallax-dancers').scrollingParallax({
        staticSpeed: 1.01,
        staticScrollLimit: false
    });
    $('#parallax-2-dancers').scrollingParallax({
        staticSpeed: 0.8,
        staticScrollLimit: false
    });
    
    $('#parallax-3-dancers').scrollingParallax({
        staticSpeed: 1.1,
        staticScrollLimit: false
    });

    $('#parallax-planet10').scrollingParallax({
        staticSpeed: 1.7,
        staticScrollLimit: false
    });
    $('#parallax-planet12').scrollingParallax({
        staticSpeed: 1.2,
        staticScrollLimit: false
    });
	$('#parallax-2-planet1').scrollingParallax({
    	staticSpeed: 1.6,
	    staticScrollLimit: false
	});

    $('#parallax-2-planet2').scrollingParallax({
        staticSpeed: 1.3,
        staticScrollLimit: false
    });
    $('#parallax-3-planet1').scrollingParallax({
        staticSpeed: 1.7,
        staticScrollLimit: false
   	});
    
    $('#parallax-3-planet2').scrollingParallax({
        staticSpeed: 1.1,
		staticScrollLimit: false
	});
    

    function isFixedSupported() {
        var container = document.body;
        if (document.createElement &&
        container && container.appendChild && container.removeChild) {
            var el = document.createElement("div");
            if (!el.getBoundingClientRect) {
                return null;
            }
            el.innerHTML = "x";
            el.style.cssText = "position:fixed;top:100px;";
            container.appendChild(el);
            var originalHeight = container.style.height,
            originalScrollTop = container.scrollTop;
            container.style.height = "3000px";
            container.scrollTop = 500;
            var elementTop = el.getBoundingClientRect().top;
            container.style.height = originalHeight;
            var isSupported = elementTop === 100;
            container.removeChild(el);
            container.scrollTop = originalScrollTop;
            return isSupported;
        }
        return null;
    }

    var not_position_fixed_supported = !(isFixedSupported());

    if (not_position_fixed_supported) {
        $('body *').css('-webkit-transform', "translate3d(0,0,0)");
        $('#bannersmall').css('position', "absolute").css("-webkit-transition", "top linear 1s, opacity liear 1s").css('top', (window.pageYOffset - 60) + 'px');
    }
    
    
        $('header').localScroll({
        	hash:true, 
        	easing: "linear",
        	duration: 1500,
        	onBefore: function() {
        	//	$(window).unbind( "scroll" );
        	//	console.log('before:' + window.pageYOffset);
        	},
            onAfter: function() {
            /*	var offset = window.pageYOffset
            	        || document.documentElement && document.documentElement.scrollTop
            	        ||  document.body.scrollTop;
            	
            	if (not_position_fixed_supported) {
                	$('#bannersmall').css('top', (offset) + 'px');
                }
                
                
                if (parseInt(offset, 10) > 420) {
                    $("#bannersmall").css("display", "block");
                } else {
                    $("#bannersmall").css("display", "none");
                }
               
                $(window).scroll(function() {
                
                	var offset = window.pageYOffset
                	        || document.documentElement && document.documentElement.scrollTop
                	        ||  document.body.scrollTop;
               	// console.log('after:' + offset + "|" + window.pageYOffset);
                    if (not_position_fixed_supported) {
                        $('#bannersmall').css('top', (offset) + 'px');
                    }
                    
                    if (parseInt(offset, 10) > 420) {
                        $("#bannersmall").css("display", "block");
                    } else {
                        $("#bannersmall").css("display", "none");
                    }
                });
                */
                // console.log($('#bannersmall').css('top'));
            }
        });

    $(window).scroll(function() {
        
        var offset = window.pageYOffset
                || document.documentElement && document.documentElement.scrollTop
                ||  document.body.scrollTop;
        // console.log(offset);
        if (not_position_fixed_supported) {
            $('#bannersmall').css('top', (offset) + 'px');
        }
        
        if (parseInt(offset, 10) > 420) {
            $("#bannersmall").css("display", "block");
        } else {
            $("#bannersmall").css("display", "none");
        }
    });

	var offset = window.pageYOffset
	        || document.documentElement && document.documentElement.scrollTop
	        ||  document.body.scrollTop;

    if (parseInt(offset, 10) > 420) {
        $("#bannersmall").css("display", "block");
    } else {
        $("#bannersmall").css("display", "none");
    }


});

$(document).ready(function(){

	var playItem = 0;

	var myPlayList = [
		{name:"Morbid",mp3:"audio/morbid.mp3",ogg:"audio/morbid.ogg"},
		{name:"Another Prophet Song",mp3:"audio/another-prophet-song.mp3",ogg:"audio/another-prophet-song.ogg"},
		{name:"I Remember",mp3:"audio/i-remember.mp3",ogg:"audio/i-remember.ogg"},
		{name:"Mosquito",mp3:"audio/mosquito.mp3",ogg:"audio/mosquito.ogg"},
		{name:"Sleep",mp3:"audio/sleep.mp3",ogg:"audio/sleep.ogg"},
		{name:"Into the Everflow",mp3:"audio/into-the-everflow.mp3",ogg:"audio/into-the-everflow.ogg"},
		{name:"In This Place",mp3:"audio/in-this-place.mp3",ogg:"audio/in-this-place.ogg"},
		{name:"Nothing",mp3:"audio/nothing.mp3",ogg:"audio/nothing.ogg"}
	];

	// Local copy of jQuery selectors, for performance.
	var jpPlayTime = $("#jplayer_play_time");
	var jpTotalTime = $("#jplayer_total_time");

	$("#jquery_jplayer").jPlayer({
		ready: function() {
			displayPlayList();
			playListInit(false); // Parameter is a boolean for autoplay.
		},
		oggSupport: true,
		swfPath: "./libs"
	})
	.jPlayer("onProgressChange", function(loadPercent, playedPercentRelative, playedPercentAbsolute, playedTime, totalTime) {
		jpPlayTime.text($.jPlayer.convertTime(playedTime));
		jpTotalTime.text($.jPlayer.convertTime(totalTime));
	})
	.jPlayer("onSoundComplete", function() {
		playListNext();
	});

	$("#jplayer_previous").click( function() {
		playListPrev();
		
		return false;
	});

	$("#jplayer_next").click( function() {
		playListNext();
		
		return false;
	});

	function displayPlayList() {
		$("#jplayer_playlist ul").empty();
		for (i=0; i < myPlayList.length; i++) {
			var listItem = (i == myPlayList.length-1) ? "<li class='jplayer_playlist_item_last'>" : "<li>";
			listItem += "<a href='#' id='jplayer_playlist_item_"+i+"'>"+ myPlayList[i].name +"</a></li>";
			$("#jplayer_playlist ul").append(listItem);
			$("#jplayer_playlist_item_"+i).data( "index", i ).click( function() {
				var index = $(this).data("index");
				if (playItem != index) {
					playListChange( index );
				} else {
					$("#jquery_jplayer").jPlayer("play");
				}
				
				return false;
			});
		}
	}

	function playListInit(autoplay) {
		if(autoplay) {
			playListChange( playItem );
		} else {
			playListConfig( playItem );
		}
	}

	function playListConfig( index ) {
		$("#jplayer_playlist_item_"+playItem).removeClass("jplayer_playlist_current").parent().removeClass("jplayer_playlist_current");
		$("#jplayer_playlist_item_"+index).addClass("jplayer_playlist_current").parent().addClass("jplayer_playlist_current");
		playItem = index;
		$("#jquery_jplayer").jPlayer("setFile", myPlayList[playItem].mp3, myPlayList[playItem].ogg);
	}

	function playListChange( index ) {
		playListConfig( index );
		$("#jquery_jplayer").jPlayer("play");
	}

	function playListNext() {
		var index = (playItem+1 < myPlayList.length) ? playItem+1 : 0;
		playListChange( index );
	}

	function playListPrev() {
		var index = (playItem-1 >= 0) ? playItem-1 : myPlayList.length-1;
		playListChange( index );
	}
});
