/*
 * jQuery DOUBLE MINT Backstretch 1.0 by jlancaster after looking at intial backstretch
 * http://srobbin.com/jquery-plugins/jquery-backstretch/
 *
 * Add a dynamically-resized background image to the page
 *
 * Copyright (c) 2009 Scott Robbin (srobbin.com)
 * Dual licensed under the MIT and GPL licenses.
*/

(function($) {

  $.doublebackstretch = function(src, options, callback) {
    var settings = {
          hideUntilReady: true, // Hide the image until it's finished loading
          speed: 1000 // fadeIn speed for background after image loads (e.g. "fast" or 500)
        },
        imgRatio;
    
    // Extend the settings with those the user has provided
    if(options && typeof options == "object") $.extend(settings, options);
    
    // Initialize
    $(document).ready(_init);
  
    // For chaining
    return this;
    
    
    function _init() {
    	var width = $(window).width();
    	var height = $(document).height();
    	var ratio = 0;

		$('#background').css({'height':height});

	    $('#background #top').css("left", ( $(window).width() - $('#background #top').width() ) / 2+$(window).scrollLeft() + "px");

		$('#background #bot').css({'width':width});
	    $('#background #bot').css("left", ( $(window).width() - $('#background #bot').width() ) / 2+$(window).scrollLeft() + "px");
		
		
/*
		$('#background img').each(function(index) {
			//alert(this.naturalWidth + 'x' + this.naturalHeight);
			//console.log(this);
			
			//alert(index + '|' + value);
			
			if (index == 0) {
				//first index will always be the top
				ratio = 1.2;
			} else {
				ratio = .8;
				//place bottom piece	
			}			
			
			height = Math.round(height-this.naturalHeight);

			if (index == 1) {
//				if (width < 1600)
				$('#background #' + this.id).css({'width':width});
			}
			
		    $('#background #' + this.id).css("position","absolute");		    
		    $('#background #' + this.id).css("top",previousHeight+'px');
		    $('#background #' + this.id).css("left", ( $(window).width() - $('#background #' + this.id).width() ) / 2+$(window).scrollLeft() + "px");

			previousHeight = this.naturalHeight + previousHeight;
		});
	
    
/*    	
    	var topwidth = width;
    	var botwidth = width;
    	var topheight = Math.round(height/2*1.2);
    	var botheight = Math.round(height/2*.8);
    	//alert("Start: " + width + 'x' + height + "\nTop: " + topwidth + 'x' + topheight + "\nBottom: " + botwidth + 'x' + botheight);
    	
		$('#background #top').css({'width':topwidth, 'height':topheight});
		$('#background #bot').css({'width':botwidth, 'height':botheight});
*/
    }    
  };
  
})(jQuery);
