// JavaScript Document
//Current Image Visible
var currentImg = 0;

//Image Left
var imgLeft = ['0px', '-1005px', '-2001px'];
//Indicator Left
var indLeft = ['69px', '289px', '508px'];

	    var ua = navigator.userAgent;
		
//Add ipad splash screen and hide home page content
$(document).ready(function(e) {


			//console.log(ua);
        if($.browser.msie && $.browser.version=="6.0") {
		$('#splashArrow').css('display','none');	
		}

            var checker = {
                iphone: ua.match(/iPhone/),
                blackberry: ua.match(/BlackBerry/),
                android: ua.match(/Android/),
                safari: ua.match(/Safari/)
                };
            if  (checker.iphone) {
			$('meta[name=viewport]').attr('content','initial-scale=0.50,height=device-height, user-scalable=yes');
				console.log('iphone device');
                
            } else if (checker.blackberry) {
                
            } else {
               
				//console.log('unknown device');    
				$('#imgHolder').draggable({
        axis: 'x',
        start: function(event, ui) {
            tmpStart = ui.offset.left;
        },
        stop: function(event, ui) {
            checkPosition(event, ui);
            //console.log(ui.offset.left);
            }
    });
            }
       

	
	
    var tmpStart;
    var tmpEnd;


    document.documentElement.style.webkitTouchCallout = "none";
    document.documentElement.style.webkitTapHighlightColor = "rgba(0,0,0,0)";

    //Animate to position depending on the swipe/drag direction
    function checkPosition(event, ui) {

        tmpEnd = ui.offset.left;
        var end = tmpEnd - tmpStart;
       // console.log(end);
        if (end > 30) {
            //console.log('more than 20');
            if (currentImg == 0) {
                currentImg = 2;
            } else {
                currentImg--;
            }
        } else if (end < -30) {
            //	console.log('less than 20');
            if (currentImg >= 2) {
                currentImg = 0;
            } else {
                currentImg++;
            }
        }
     //   console.log('currentImg ' + currentImg + ' ' + imgLeft[currentImg]);
        $('#imgHolder').animate({
            left: imgLeft[currentImg]
            }, 'fast');
        $('#splashArrow').animate({
            left: indLeft[currentImg]
            }, 'fast');

    }//End checkPosition

//Button Click Events
    $('#splashBtn1').click(function(e) {
        $('#splashArrow').animate({
            left: indLeft[0]
            }, 'fast');
        $('#imgHolder').animate({
            left: imgLeft[0]
            }, 'fast');
			currentImg=0;
    });
    $('#splashBtn2').click(function(e) {
        $('#splashArrow').animate({
            left: indLeft[1]
            }, 'fast');
        $('#imgHolder').animate({
            left: imgLeft[1]
            }, 'fast');
			currentImg=1;
    });
    $('#splashBtn3').click(function(e) {
        $('#splashArrow').animate({
            left: indLeft[2]
            }, 'fast');
        $('#imgHolder').animate({
            left: imgLeft[2]
            }, 'fast');
			currentImg=2;
    });
    $('#splashBtn4').click(function(e) {
		window.location = 'home.htm';
		
        //$('#splashArrow').css('left','821px');
        
    });

//Clear Background Image to reset load function
   $('#navBar').attr('src', 'images/ipad_splash/transparent.png');
    //$('#splashBg').attr('src', 'images/ipad_splash/pattern.png');
//Load function called after splashBg is fully loaded
    $('#navBar').load(function() {

        $('#ipad_splashHolder').fadeIn('fast');
    });
	
   $('#navBar').attr('src', 'images/ipad_splash/nav_bar.png');


});

//Backup incase load function does not get called - wait a few seconds and fade in screen
window.setTimeout(fadeSplash,3500);

function fadeSplash(){
	console.log('fadeSplash');
        $('#ipad_splashHolder').fadeIn('fast');
}
