var bigData; var items; var cart; var startTime; var endTime; var offset; $(document).ready(function(){ $.post('api.php',{action:'items'},function(data){ items = data; },"json"); loadCartDetails(); $("#date_shown").datepicker({ onClose: function(dateText, inst){ loadPhotosPerDate(); } }); $("#datePickinCal").datepicker({ onSelect: function(dateText, inst){ $("#time_wrapper").fadeIn(); $("#date_shown").val(dateText); loadPhotosPerDate(); } }); }); function currFormat(amount){ return amount.toFixed(2); } function loadPhotosPerDate(){ $.post('somePhotoInfo.php',{date:$("#date_shown").val()},function(data){ offset = 0; bigData = data; $("#startTime").empty().append(displayTime(bigData.baseTime)); $("#endTime").empty().append(displayTime(bigData.baseTime + 57600)); drawPhotos(bigData.baseTime,(bigData.baseTime + 57600)); $("#slider").slider({ range: true, min: 0, step: 900, max: 57600, values: [ 0,57600], slide: function(event, ui){ $("#startTime").empty().append(displayTime(bigData.baseTime + ui.values[0])); $("#endTime").empty().append(displayTime(bigData.baseTime + ui.values[1])); }, change: function(event, ui){ offset = 0; startTime = bigData.baseTime + ui.values[0]; endTime = bigData.baseTime + ui.values[1]; loadPhotosFromServer(0) drawPhotos(bigData.baseTime + ui.values[0],bigData.baseTime + ui.values[1]); } }); },"json"); } function viewCartDetails(){ $('html, body').animate({scrollTop:0}, 'slow'); $("#cart_wrapper").slideDown(); } function hideCartDetails(){ $("#cart_wrapper").slideUp(); } function showDetails(id){ var nextImg = ''; var prevImg = ''; var thisImg = ''; for(x in bigData.photos){ if(bigData.photos[x].id == id){ thisImg = bigData.photos[x]; if(bigData.photos[parseInt(x)+1]){ nextImg = bigData.photos[parseInt(x)+1]; } if(parseInt(x) > 0){ prevImg = bigData.photos[parseInt(x)-1]; } } } if(typeof thisImg == "undefined"){ $.ajax({ url: 'api.php', type: 'POST', data: {action:'getPhotoInfo',id:id}, dataType: "json", success: function(data){ thisImg = data; }, async: false }); } // Add overlay var html = ''; $("body").append(html); $("#preview_wrapper").click(function(){ return false; }); $("#previewNext").click(function(){ $(".details_overlay").fadeOut(function(){ $(this).remove(); showDetails(nextImg.id) }); }); $("#previewPrev").click(function(){ $(".details_overlay").fadeOut(function(){ $(this).remove(); showDetails(prevImg.id) }); }); $("#closePreview").click(function(){ $(".details_overlay").click(); }); $("#addToCart").click(function(){ $(this).hide(); $("#cartImage").animate({'width':'50%'},1000,function(){ var itemsHtml = '
Add Items to Cart
'; $("#preview_wrapper").prepend(''); $("#cart_form").submit(function(){ return false; }); $("#preview_wrapper").append(''); $(".show_after_resize_preview").fadeIn(); }); return false; }); $(".details_overlay").fadeIn('fast',function(){ $(".details_overlay").click(function(){ $(this).fadeOut(function(){ $(this).remove(); }); }); }); // Show big photo } function loadPhotosFromServer(){ $.post('somePhotoInfo.php',{startTime:startTime,endTime:endTime,date:$("#date_shown").val(),start:offset},function(data){ bigData = data; drawPhotos(); },"json"); } function nextPage(){ offset = offset + 100; loadPhotosFromServer(); } function prevPage(){ if(offset > 100){ offset = offset - 100; }else{ offset = 0; } loadPhotosFromServer(); } function drawPhotos(){ var count = 0; $("#photoArea").fadeOut(function(){ $("#photoArea").empty(); for(x in bigData.photos){ var y = bigData.photos[x]; count++; $("#photoArea").append('

View or Order

Loading...

' + displayTime(y.date) + '

'); } if(count == 0){ $("#photoArea").append('

No photos for this time.

'); } $("#photoArea").append('
Previous PageNext Page
'); var activeScroll = false; /* $(window).scroll(function(){ var windowBottom = $(window).scrollTop()+$(window).height(); var itemBottom = $(".photoDisplay:last").offset().top - 300; var itemBottomNum = $("#.photoDisplay:last").data("count"); console.log(itemBottomNum); if(windowBottom > itemBottom && activeScroll == false && itemBottomNum == count){ console.log('Load Additional 100'); activeScroll = true; $.post('somePhotoInfo.php',{date:$("#date_shown").val(),start:count},function(data){ for(x in data.photos){ var y = data.photos[x]; bigData.photos.push(y); if(y.date < endTime){ count++; $("#photoArea").append('

View or Order

Loading...

' + displayTime(y.date) + '

'); } } activeScroll = false; console.log(bigData); $(".photoDisplay").hover(function(){ // $(this).prepend('

View or Order

'); $(this).children(".detailsHover").fadeIn(); },function(){ $(this).children(".detailsHover").hide(); }); },"json"); } }); */ $("#photoArea").fadeIn(); $(".photoDisplay").hover(function(){ // $(this).prepend('

View or Order

'); $(this).children(".detailsHover").fadeIn(); },function(){ $(this).children(".detailsHover").hide(); }); }); } function displayTime(stamp){ var time = new Date(stamp*1000); var amp = "AM"; var hours = time.getHours(); if(hours > 12){ hours = hours - 12; amp = "PM"; } if(hours == 12){ amp = "PM"; } var display = hours + ':' + ("0" + time.getMinutes()).slice(-2) + " " + amp; return display; } function removeItem(item,photo){ $.post('api.php',{action:'removeItem',item:item,photo:photo},function(data){ loadCartDetails(); },"json"); } function couponCodeApply(){ code = $("#couponcodeapply").val(); $.post('api.php',{action:'applyCouponCode', code:code},function(data){ $("#couponcodeapply").val(''); console.log(data); loadCartDetails(); },"json"); } function removeCoupon(){ $.post('api.php',{action:'removeCouponCode'},function(){ loadCartDetails(); },"json"); } function emptyCart(){ $.post('api.php',{action:'emptyCart'},function(){ loadCartDetails(); hideCartDetails(); },"json"); } function addToCart(){ var details = $("#cart_form").serialize(); $.post('api.php',details,function(data){ loadCartDetails(); },"json"); $(".details_overlay").fadeOut(function(){ $(this).remove(); }); } function loadCartDetails(){ $.post('api.php',{action:'getCart'},function(data){ if(data != null && data.items!=0){ cart = data; var html = ''; html += ''; $("#cartDetailWrapper").empty().append(html); var headerCartMessage = '' + data.items + ' Items in Cart - $' + data.total + 'View & Checkout'; } else { var headerCartMessage = 'No Items in Cart'; hideCartDetails(); } $("#header_cartCount").empty().append(headerCartMessage); },"json"); }