/*  UX JS starts here: */
$(document).ready(function(){
var ih = $(window).height();
var hpx = ih + 'px'
if (navigator && navigator.platform && navigator.platform.match(/^(iPad|iPod|iPhone)$/)) {
    $('#footer').animate({
    top: hpx 
  });
}  
                      
 /*  Scroll position States DETECTION */
 $(window).scroll(function(){
  // get the height
  var h = $('.inner-wrapper').height();
  var y = $(window).scrollTop();
  if( y <= (h*.27) ){
   // if we are within 'welcome-page'
       $('.welcome').css('background-position', '0 0');
    $('.survey').css('background-position', '-110px -45px');
    $('.sponsors').css('background-position', '-225px -45px');
  }
  else if( y >= (h*.27) && y <= (h*.6) ){
   // if we are within 'survey-page'
       $('.survey').css('background-position', '-110px 0');
    $('.welcome').css('background-position', '0 -45px');
    $('.sponsors').css('background-position', '-225px -45px');
  }
  else if( y >= (h*.6) && y <= (h) ) {
    // if we are within 'sponsors-page'
    $('.sponsors').css('background-position', '-225px 0');
    $('.welcome').css('background-position', '0 -45px');
    $('.survey').css('background-position', '-110px -45px');
  }
 });
});

/*  BODY ONLOAD FUNCTION: */
function scrollReset() {
    $(window).scrollTo({top:'0px', left:'0px',easing:'easeInOutExpo'}, 600);
    $('#panes').scrollTo({top:'0px', left:'0px',easing:'easeInOutExpo'}, 600);
    }
  
$(document).ready(function() {
jQuery(function( $ ){
/*  Vertical Window Scroll: */
    $('.welcome-state').localScroll({axis:'y', target: window,duration: 1000,easing:'easeInOutExpo', 
                                   onBefore:function(){
                                $('.welcome').css('background-position', '0 0');
                                $('.survey').css('background-position', '-110px -45px');
                                $('.sponsors').css('background-position', '-225px -45px');
                                }
                        });
    $('.survey-state').localScroll({axis:'y', target: window,duration: 1000,easing:'easeInOutExpo', 
                                   onBefore:function(){ 
                                $('.survey').css('background-position', '-110px 0');
                                $('.welcome').css('background-position', '0 -45px');
                                $('.sponsors').css('background-position', '-225px -45px');
                                }
                        });
    $('.sponsors-state').localScroll({axis:'y', target: window,duration: 1000,easing:'easeInOutExpo', 
                                   onBefore:function(){ 
                                $('.sponsors').css('background-position', '-225px 0');
                                $('.welcome').css('background-position', '0 -45px');
                                $('.survey').css('background-position', '-110px -45px');
                                }
                        });
    $('#banner').localScroll({axis:'y', target: window,duration: 1000,easing:'easeInOutExpo', 
                                   onBefore:function(){ 
                                $('.sponsors').css('background-position', '-225px -45px');
                                $('.welcome').css('background-position', '0 -45px');
                                $('.survey').css('background-position', '-110px 0');
                                }
                        });
});
jQuery(function( $ ){
/*  Horizontal form tabs Scroll: */
$('#con1').click(function(){$(this).parents('div#panes').scrollTo({top:0,left:2006,easing:'easeInExpo'}, 600); });    
$('#con2').click(function(){$(this).parents('div#panes').scrollTo({top:0,left:4015,easing:'easeInExpo'}, 600); });    
$('#con3').click(function(){$(this).parents('div#panes').scrollTo({top:0,left:6022,easing:'easeInExpo'}, 600); });    
$('#con4').click(function(){$(this).parents('div#panes').scrollTo({top:0,left:10032,easing:'easeInExpo'}, 600); }); //button 

$('#back1').click(function(){$(this).parents('div#panes').scrollTo({top:0,left:0,easing:'easeInExpo'}, 500); });
$('#back2').click(function(){$(this).parents('div#panes').scrollTo({top:0,left:2006,easing:'easeInExpo'}, 500); });    
$('#back3').click(function(){$(this).parents('div#panes').scrollTo({top:0,left:4015,easing:'easeInExpo'}, 500); });   
});

/*  Grab the Postcard and Make MySource Jquery / Thanks Nicholas Hubbard */
$(".contact").colorbox();
$('#page_asset_builder_126').matrixForm(

{
loading: 'http://www.pubaid.net/__data/assets/image/0006/411/ajax-loader.gif', 
errorArray: true,
errorSource:'#errorHold',
errorMessage: 'You have a bunch of errors:',
onComplete: function() {

$('div#panes').scrollTo({top:0,left:10032,easing:'easeInExpo'}, 600);

}
}
);


$("input#metadata_field_select_111_Other").click(function () {
$("#page-3 p.other").toggle();
});

$("input#metadata_field_select_121_Other").click(function () {
$("#page-5 p.other").toggle();
});


/* This pulls the jar in - Needed for MySource to trawl elegantly */

//$('#jarholder').html('<span id="jar-loading"><img src="http://www.pubaid.com/__data/assets/image/0010/271/loading.gif"></span>');
//$('#jarholder').fadeOut().load('http://www.pubaid.com/calls/jar', function() {
//$("#jarholder").fadeIn("slow")
//});


});

