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 = ''; $("#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('' + displayTime(y.date) + '
No photos for this time.
'); } $("#photoArea").append(''); 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('' + displayTime(y.date) + '
$' + currFormat(item.amount) + '
' + item.desc + 'Remove - Change Quantity
$' + currFormat(photo.total) + '
TOTAL THIS ITEM
$' + currFormat(data.subtotal) + '
Subtotal
$' + currFormat(data.shipping) + '
Shipping
$' + currFormat(data.discount) + '
'; html = html + '' + data.disctype + ' DISCOUNT
'; if(data.disctype == 'COUPON'){ html = html + 'Remove Coupon'; $("#couponCodeForm").hide(); }else{ $("#couponCodeForm").show(); } html = html + '$' + currFormat(data.total) + '
'; html = html + 'TOTAL