// back image resize

var main_image_original_width = 1500;
var main_image_original_height = 1000;
var pic_width = main_image_original_width;
var pic_height = main_image_original_height;


function resize_image_with_cropping() {
	var win_width = jQuery(window).width();
	var win_height = jQuery(window).height();
	var win_aspect_ratio = win_width / win_height;

	current_width = jQuery('#main_image').width();
	if (current_width > 1) {
		pic_width = current_width;
	}	

	current_height = jQuery('#main_image').height();
	if (current_height > 1) {
		pic_height = current_height;
	}
	
	pic_aspect_ratio = pic_width / pic_height;
	
	if (win_aspect_ratio > pic_aspect_ratio) {
		// scale pic to fit window width
		var new_height = (win_width / pic_width) * pic_height;
		var new_width = win_width;
	} else {
		// scale pic to fit window height		
		var new_height = win_height;
		var new_width = (win_height / pic_height) * pic_width;
	}
	
	// center image
	new_top = 0 - ((new_height - win_height) / 2);
	new_left =  0 - ((new_width - win_width) / 2);
	
	// center image only horizontal
	new_top = 0 ;
	new_left =  0 - ((new_width - win_width) / 2);

	
	
//	alert('new_top: ' + new_top + 'new_left: ' + new_left);
	jQuery('#main_image').css({top: new_top, left: new_left});

	jQuery('#main_image').css({height: new_height, width: new_width});
	jQuery('#bkg-wrapper').css({height: win_height, width: win_width});
	jQuery('#bkg-wrapper').css({visibility:"visible", display:"inline"});
	
}


// footer subnavig dropdown

var obj = null;

   function checkHover() {
      if (obj) {
         obj.find('ul').fadeOut('fast');
      }
   }

   $(document).ready(function() {
      $('#footer-main-navig > li').hover(function() {
         if (obj) {
            obj.find('ul').fadeOut('fast');
            obj = null;
         }
        $(this).find('ul').stop(true).fadeIn('fast')
      }, function() {
         obj = $(this);
         setTimeout(
            "checkHover()",
            400);
      });
   });
   



   

// slideshow

function slideSwitch() {
    var $active = $('#slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');

    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

// content remove

$(document).ready(function() {					   
	$("li.remove").click(function(){
		$("div#hide-content").fadeOut("fast");
		return false;
	});
	
	$("li.move").click(function(){
		$("div#hide-content").fadeIn("fast");
		return false;
	});
	
	$("ul.btn li").click(function () {
		$("ul.btn li").toggle();
	});	
});

