﻿$(function() {
    //$('#Bottles').fadeIn("slow");
    //alert('here');
    var img = new Image();
    var bgimg = new Image();


    // wrap our new image in jQuery, then:
    $(img)
    // once the image has loaded, execute this code
			.load(function() {
			    // set the image hidden by default    
			    $(this).hide();

			    // with the holding div #loader, apply:
			    $('#Bottles')
			    // remove the loading class (so no background spinner), 
				.append(this);

			    // fade our image in to create a nice effect
			    $(this).fadeIn(1000);
			})

    // if there was an error loading the image, react accordingly
			.error(function() {
			    // notify the user that the image could not be loaded
			})

    // *finally*, set the src attribute of the new image to our image
			.attr('src', 'images/Bottles.gif');

});

var resizeTimer = null;
$(window).bind('resize', function() {
    //if (resizeTimer) clearTimeout(resizeTimer);
    //resizeTimer = setTimeout(resizeFrame, 100);

    resizeFrame();
});

function resizeFrame() {
    var viewport_Height = $(window).height();
    var viewport_Width = $(window).width();

    if (viewport_Height < 740) viewport_Height = 740;
    if (viewport_Width < 1000) viewport_Width = 1000;

    $('body').height(viewport_Height - 64);
    $('#Bottles').width(viewport_Width - 14);
    $('#Bottles').height(viewport_Height - 7);
    $('#MainContentContainer').width(viewport_Width - 14);
    $('#MainContentContainer').height(viewport_Height - 64);
    $('body').css('overflow', 'auto');
    //alert('resized to ' + viewport_Width + 'x' + viewport_Height);
}

function addWatermarks() {
    $('input#month').watermark("MM");
    $('input#day').watermark("DD");
    $('input#year').watermark("YYYY");
}

function addAutoTab() {
    $('input#month').autotab({ target: 'day', format: 'numeric' });
    $('input#day').autotab({ target: 'year', format: 'numeric', previous: 'month' });
    $('input#year').autotab({ target: 'submitter', format: 'numeric', previous: 'day' });
}

function windowPopUp(URL) {
    window.open(URL, "WH", "status=no,scrollbars=no,width=500,height=620");
}

$(document).ready(function() {

    resizeFrame();
    addWatermarks();
    addAutoTab();
});