/* addLoadEvent for multiple onload functions */

//function addLoadEvent(func) {
//    var oldonload = window.onload;
//    if (typeof window.onload != 'function') {
//        window.onload = func;
//    } else {
//        window.onload = function() {
//            if (oldonload) {
//                oldonload();
//            }
//            func();
//        }
//    }
//}

/* col2: photo gallery */

function photoGallery(dir) {	 
if(photoGallery != 0) {

	//move left
	if(dir != 0) {
		if(photoGalleryCounter == 0) { $('ms-global-img-mover2').style.left = photoGalleryWidth }
		//reset the photo containers and the counter 
		if(photoGalleryCounter == (photoGalleryTotal-(photoGalleryTotal*2))) { 
			$('ms-global-img-mover1').style.left = '0px'; 
			$('ms-global-img-mover2').style.left = photoGalleryWidth;
			photoGalleryCounter = 0}	
				photoGalleryCounter = photoGalleryCounter -1;
				Effect.MoveBy( 'ms-global-img-mover1', 0, -91, { 
				beforeStart: function() { disablepGalleryBtns(0); }, afterFinish: function() { disablepGalleryBtns(1); }, duration:1} ); 
				Effect.MoveBy( 'ms-global-img-mover2', 0, -91, {duration:1} );
							
		} else { 
		
		//move right
		if(photoGalleryCounter == 0) { $('ms-global-img-mover2').style.left = photoGalleryWidthRight; }
		//reset the photo containers and the counter 
		if(photoGalleryCounter == photoGalleryTotal) { 
			$('ms-global-img-mover1').style.left = '0px'; 
			$('ms-global-img-mover2').style.left = photoGalleryWidthRight;
			photoGalleryCounter = 0}
				photoGalleryCounter = photoGalleryCounter +1;
				Effect.MoveBy( 'ms-global-img-mover1', 0, 91, { 
				beforeStart: function() { disablepGalleryBtns(0); }, afterFinish: function() { disablepGalleryBtns(1); }, duration:1} ); 
				Effect.MoveBy( 'ms-global-img-mover2', 0, 91, {duration:1} ); 
		}
	}
}	

//this function deactivates button while photo gallery is moving
function disablepGalleryBtns(active) {	
	if(active == 0) { 
		$('ms-col2-img-container').style.width = '546px';
		$('ms-col2-img-container').style.clip = 'rect(auto auto auto auto)';
		$('ms-col2-pGallery-rightBtn').onclick = null;
		$('ms-col2-pGallery-leftBtn').onclick = null;
		}
	if(active == 1) { 
		$('ms-col2-img-container').style.width = '546px';
		$('ms-col2-img-container').style.clip = 'rect(auto auto auto auto)';
		$('ms-col2-pGallery-rightBtn').onclick =  photoGallery;
		$('ms-col2-pGallery-leftBtn').onclick =  new Function("photoGallery("+0+")");
		}
}

//gallery customization
var photoGalleryTotal = 9;
var photoGalleryWidth = (91 * photoGalleryTotal)+'px';
var photoGalleryWidthRight = '-'+(91 * photoGalleryTotal)+'px';
var photoGalleryCounter = 0;

//check to see if more than 3 images in column 2 photo gallery then show scroll arrows if needed
if(photoGalleryTotal < 4) {
	$('ms-col2-pGallery-leftBtn').style.visibility = 'hidden';
	$('ms-col2-pGallery-rightBtn').style.visibility = 'hidden';
}

addLoadEvent(new Function("disablepGalleryBtns("+1+")"));


