window.preloaders=[];
$(document).ready(function(){
	$('#nav>ul>li>a>img').each( function(i){
		window.preloaders[i]=document.createElement("img");
		var s=this.src;		
		s=s.replace(".gif","_on.gif");
		window.preloaders[i].src=s;
		
		$(this).mouseover(function(){						
							var s=this.src;
							s=s.replace(".gif","_on.gif");				
							this.src=s;					
						})
			   .mouseout(function(){
							var s=this.src;
							s=s.replace("_on.gif",".gif");					
							this.src=s;	 
						});		
	});
	
	$('#war_logo>a>img').each( function(i){
		window.preloaders[i]=document.createElement("img");
		var s=this.src;		
		s=s.replace(".png","_on.png");
		window.preloaders[i].src=s;
		
		$(this).mouseover(function(){						
							var s=this.src;
							s=s.replace(".png","_on.png");				
							this.src=s;					
						})
			   .mouseout(function(){
							var s=this.src;
							s=s.replace("_on.png",".png");					
							this.src=s;	 
						});		
	});
	
	$('.lightbox_link').lightBox({
		overlayBgColor:  '#fff',
		overlayOpacity: 0.4
		
	});
	if(window.browserIe6){
		$('div, h1').each(function(i){
			var im=$(this).css('background-image');
			if(im.indexOf(".png")!=-1){
				var type='crop';								
				if($(this).css('background-repeat')!='no-repeat') type='scale';
				$(this).css("background","none");
				var div=document.createElement("div");
				$(div).css("position","absolute");		
				$(div).css("top","0");	
				$(div).css("left","0");	
				$(div).css("z-index","-1");	
				var pb=$(this).css("padding-bottom");
				pb=parseInt(pb.substr(0,pb.length-2));
				var pt=$(this).css("padding-top");
				pt=parseInt(pt.substr(0,pt.length-2));				
				var pl=$(this).css("padding-left");
				pl=parseInt(pl.substr(0,pl.length-2));
				var pr=$(this).css("padding-right");
				pr=parseInt(pr.substr(0,pr.length-2));						
				var h=$(this).height();
				var w=$(this).width();
	
				$(div).css("height",h+pb*2+pt*2+"px");
				$(div).css("width",w+pl*2+pr*2+"px");	
				$(div).css("padding",pt+"px "+pr+"px "+pb+"px "+pl+"px");			
				$(this).height(h+pb*2+pt*2+"px");
				$(this).width(w+pl*2+pr*2+"px");				
				im=im.substr(4);
				im=im.substr(0,im.length-1);
				$(div).css("filter",'progid:DXImageTransform.Microsoft.AlphaImageLoader(src='+im+', sizingMethod="'+type+'");');				
				$(this).append(div);				
			}		
		});
	}
});


var events=[];
function addEvent(day,details){
 if(!events[day]){
	events[day]="<h2>"+day+" "+monthStr+"</h2>";
 }
 events[day]+='<div class="list_event">'+details+'</div>';
}
eventShowing=false;
function showDay(day){

	if(eventShowing) closeEventLightbox();
	eventShowing=true;
	settings ={
			// Configuration related to overlay
			overlayBgColor: 		'#fff',		// (string) Background color to overlay; inform a hexadecimal value like: #RRGGBB. Where RR, GG, and BB are the hexadecimal values for the red, green, and blue values of the color.
			overlayOpacity:			0.6,		// (integer) Opacity value to overlay; inform: 0.X. Where X are number from 0 to 9
			// Configuration related to navigation
			fixedNavigation:		false,		// (boolean) Boolean that informs if the navigation (next and prev button) will be fixed or not in the interface.
			// Configuration related to images
			imageLoading:			'images/lightbox-ico-loading.gif',		// (string) Path and the name of the loading icon
			imageBtnPrev:			'images/lightbox-btn-prev.gif',			// (string) Path and the name of the prev button image
			imageBtnNext:			'images/lightbox-btn-next.gif',			// (string) Path and the name of the next button image
			imageBtnClose:			'images/lightbox-btn-close.gif',		// (string) Path and the name of the close btn
			imageBlank:				'images/lightbox-blank.gif',			// (string) Path and the name of a blank image (one pixel)
			// Configuration related to container image box
			containerBorderSize:	10,			// (integer) If you adjust the padding in the CSS for the container, #lightbox-container-image-box, you will need to update this value
			containerResizeSpeed:	400,		// (integer) Specify the resize duration of container image. These number are miliseconds. 400 is default.
			// Configuration related to texts in caption. For example: Image 2 of 8. You can alter either "Image" and "of" texts.
			txtImage:				'Image',	// (string) Specify text "Image"
			txtOf:					'of',		// (string) Specify text "of"
			// Configuration related to keyboard navigation
			keyToClose:				'c',		// (string) (c = close) Letter to close the jQuery lightBox interface. Beyond this letter, the letter X and the SCAPE key is used to.
			keyToPrev:				'p',		// (string) (p = previous) Letter to show the previous image
			keyToNext:				'n',		// (string) (n = next) Letter to show the next image.
			// Donīt alter these variables in any way
			imageArray:				[],
			activeImage:			0
		};
	eventLightbox(settings,events[day]);
	return false;
	
}


function eventLightbox(settings,html){
	$('embed, object, select').css({ 'visibility' : 'hidden' });
	// Apply the HTML markup into body tag
	$('body').append('<div id="jquery-overlay"></div><div id="jquery-lightbox">'+
	'<div id="event_lightbox"><div id="event_lightbox_header"></div><div id="event_lightbox_content"><a name="event_lightbox"></a>'+html+'</div><div id="event_lightbox_footer"></div></div>'+
	'</div>');	
	// Get page sizes
	var arrPageSizes = ___getPageSize();
	// Style overlay and show it
	$('#jquery-overlay').css({
		backgroundColor:	settings.overlayBgColor,
		opacity:			settings.overlayOpacity,
		width:				arrPageSizes[0],
		height:				arrPageSizes[1]
	}).fadeIn();
	// Get page scroll
	var arrPageScroll = ___getPageScroll();
	// Calculate top and left offset for the jquery-lightbox div object and show it
	$('#jquery-lightbox').css({
		top:	arrPageScroll[1] + (arrPageSizes[3] / 10),
		left:	arrPageScroll[0]
	}).show();
	// Assigning click events in elements to close overlay
	$('#jquery-overlay,#jquery-lightbox').click(function() {
		closeEventLightbox();								
	});
	// Assign the _finish function to lightbox-loading-link and lightbox-secNav-btnClose objects
	$('#event_lightbox,#event_lightbox_close').click(function() {
		closeEventLightbox();
		return false;
	});
	// If window was resized, calculate the new overlay dimensions
	$(window).resize(function() {
		// Get page sizes
		var arrPageSizes = ___getPageSize();
		// Style overlay and show it
		$('#jquery-overlay').css({
			width:		arrPageSizes[0],
			height:		arrPageSizes[1]
		});
		// Get page scroll
		var arrPageScroll = ___getPageScroll();
		// Calculate top and left offset for the jquery-lightbox div object and show it
		$('#jquery-lightbox').css({
			top:	arrPageScroll[1] + (arrPageSizes[3] / 10),
			left:	arrPageScroll[0]
		});
	});
}


function closeEventLightbox() {
	eventShowing=false;
	$('#jquery-lightbox').remove();
	$('#jquery-overlay').fadeOut(function() { $('#jquery-overlay').remove(); });
	// Show some elements to avoid conflict with overlay in IE. These elements appear above the overlay.
	$('embed, object, select').css({ 'visibility' : 'visible' });
}

/**
 / THIRD FUNCTION
 * getPageSize() by quirksmode.com
 *
 * @return Array Return an array with page width, height and window width, height
 */
function ___getPageSize() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
};
/**
 / THIRD FUNCTION
 * getPageScroll() by quirksmode.com
 *
 * @return Array Return an array with x,y page scroll values.
 */
function ___getPageScroll() {
	var xScroll, yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}
	arrayPageScroll = new Array(xScroll,yScroll);
	return arrayPageScroll;
};

