var currentItem;

function getHeight(id){return parseInt(document.getElementById(id).offsetHeight);}
function getWidth(id){return parseInt(document.getElementById(id).offsetWidth);}

function sortNumber(a,b){return a - b;}

window.addEvent('load', function(){
	// First Example
	
	var el  = $('myElement'),	
	thumbs = $$('#thumbs .thumbcontainer'),
	thumbInterior = $$('#thumbs .thumbInterior'),
	thumbTables = $$('#thumbs .thumbcontainer table');
	
	thumbHeights = new Array;
	for(x=0; x<thumbs.length; x++){
		thumbHeights.push(thumbs[x].offsetHeight);
	}
	
	thumbHeights = thumbHeights.sort(sortNumber);
	thumbHeights = thumbHeights.reverse();
	thumbHeightUniversal = thumbHeights[0];
	document.getElementById('thumbs').style.height=140+'px';
	thumbs.setStyle('height',thumbHeightUniversal);
	
	thumbInterior.setStyle('width',(thumbTables.length*163));
	
	for(x=0; x<thumbTables.length; x++){
		thumbTables[x].setStyle('marginTop' , parseInt((thumbHeights[0] - thumbTables[x].offsetHeight)/2));
		//thumbTables[(x-1)].setStyle('marginRight' , (parseInt((thumbs[0].offsetWidth - thumbTables[x].offsetWidth)/2) == 0 ? parseInt((thumbs[0].offsetWidth - thumbTables[x].offsetWidth)/2) : parseInt((thumbs[0].offsetWidth - thumbTables[x].offsetWidth)/2)+5));
		mGin = (parseInt((thumbs[0].offsetWidth - thumbTables[x].offsetWidth)/2) == 0 ? parseInt((thumbs[0].offsetWidth - thumbTables[x].offsetWidth)/2) : parseInt((thumbs[0].offsetWidth - thumbTables[x].offsetWidth)/2)+5)
		if(navigator.userAgent.indexOf('IE')>=0){mGin = parseInt(mGin/2)}
		thumbTables[(x)].setStyle('marginLeft' , mGin);
	}
	
	
	// Create the new slider instance
	sliderA = new Slider(el, el.getElement('.knob'), {
		steps: (thumbTables.length*163) - getWidth('thumbs'),	// There are 35 steps
		range: [0],	// Minimum value is 8
		onChange: function(value){
			// Everytime the value changes, we change the width of an element
			//thumbs.setStyle('width', value);
			$('thumbs').scrollTo(value,0);
			
		}
	});//.set(0);
	
	var el2  = $('myElement2'),	
	thumbs2 = $$('#thumbs2 div.thumbcontainer'),
	thumbsFrameA = $$('#thumbs2 div.thumbFrameA img'),
	thumbsFrameB = $$('#thumbs2 div.thumbFrameB img'),
	thumbFrameACont = $$('#thumbs2 td.thumbFrame img'),
	colA = $$('#rowB .colA'),
	colB = $$('#rowB .colB');
	
	sliderB = new Slider(el2, el2.getElement('.knob'), {
		steps: 316,	// There are 35 steps
		range: [153],	// Minimum value is 8
		onChange: function(value){
			// Everytime the value changes, we change the width of an element
			
			
			
			
			
			
			thumbs2.setStyle('width', value);
			colB.setStyle('height' , 'auto');
			colA.setStyle('height' , 'auto');
			thumbsFrameB.setStyle('width',parseInt(thumbs2.getStyle('width'))-5);
			thumbFrameACont.setStyle('width',parseInt(thumbs2.getStyle('width'))-13);
			thumbsFrameA.setStyle('height',parseInt(thumbFrameACont.getStyle('height')) + 8);
			
			thumbs2.setStyle('height','auto');
			thumbHeights1 = new Array;
			for(x=0; x<thumbs2.length; x++){
				thumbHeights1.push(thumbs2[x].offsetHeight);
			}
			thumbHeights1 = thumbHeights1.sort(sortNumber);
			thumbHeights1 = thumbHeights1.reverse();
			thumbHeightUniversal = thumbHeights1[0];
			thumbs2.setStyle('height',thumbHeightUniversal);
			
			cA = getHeight('rBcA');
			cB = getHeight('rBcB');
			//alert( cA + ' ' + cB)
			if(cA > cB){
				colB.setStyle('height' , cA);
			}else{
				colA.setStyle('height' , cB);
			}
			
		}
	}).set(0);
	contentSet(startingIndex);
	
			thumbs2.setStyle('height','auto');
			thumbHeights1 = new Array;
			for(x=0; x<thumbs2.length; x++){
				thumbHeights1.push(thumbs2[x].offsetHeight);
			}
			thumbHeights1 = thumbHeights1.sort(sortNumber);
			thumbHeights1 = thumbHeights1.reverse();
			thumbHeightUniversal = thumbHeights1[0];
			thumbs2.setStyle('height',thumbHeightUniversal);
}
);

	


var highlight= 0;
function showThumb(obj){
	thumbTables = $$('#thumbs .thumbcontainer table');	
	thumbTables[highlight].set('class', 'nonhighlight');
	highlight = obj;
	thumbTables[highlight].set('class', 'highlight');
	setFlashPhoto(obj);
	contentSet(obj)
}

function photoSet(obj){
	thumbTables = $$('#thumbs .thumbcontainer table');
	obj = parseInt(obj);
	setLeft = parseInt(thumbTables[obj].getPosition($('thumbs')).x) - (parseInt(getWidth('thumbs')/2)) +81;
	setLeft = setLeft<=0 ? 0 : setLeft;
	sliderA.set(setLeft);
	thumbTables = $$('#thumbs .thumbcontainer table');	
	thumbTables[highlight].set('class', 'nonhighlight');
	highlight = obj;
	thumbTables[highlight].set('class', 'highlight');
	contentSet(obj);
	
}

function contentSet(obj){
	currentItem = obj;
	var of = (galleryContent[obj].lang == 'fr') ? ' de ' : ' of ';
	$('noOfTotal').set('html' , (obj+1)+ of + galleryContent.length);
	$('photoDesc').set('html' , galleryContent[obj].caption);
	$('photoTitle').set('html' , galleryContent[obj].title);
	
	if ($('photoLinks')) {
		if (galleryContent[obj].objectname && galleryContent[obj].objectname != '' && galleryContent[obj].objectname != '0') {
			$('photoLinks').setStyle('display','block');
			$('photoLinks').setStyle('visibility','inherit');
		}
		else {
			$('photoLinks').setStyle('display','none');
			$('photoLinks').setStyle('visibility','hidden');
		}
	}
}

function thumbRoll(state , indx){
	thumbTables = $$('#thumbs .thumbcontainer table');
	if(indx !=highlight){
		if(state==0){
			thumbTables[indx].set('class', 'nonhighlight');
		}else{
			thumbTables[indx].set('class', 'highlight');
		}
	}
}

	var ie = navigator.appName.indexOf("FlashObject") != -1;
function setFlashPhoto( id ) {
	
	photoGallery = (ie) ? window['photoViewer'] : document['photoViewer'];	
	photoGallery.photoSet( id );
}

function resizeFlashLarge(){
	$$('#rowA .colB')[0].setStyle('display','none');
	myflashTween = new Fx.Tween($$('#rowA .colA')[0],'width');
	myflashTween1 = new Fx.Tween($$('#rowA .colA')[0],'height');
	myflashTween11 = new Fx.Tween($('rowA'),'height');
	myflashTween12 = new Fx.Tween($$('#rowTweenAB .colA')[0], 'marginTop');
	myflashTween13 = new Fx.Tween($$('#rowTweenAB .colB')[0], 'marginTop');
	
	
	myflashTween2 = new Fx.Tween($$('.flashBox')[0],'width');
	myflashTween3 = new Fx.Tween($$('.flashBox')[0],'height');
	
	myflashTween6 = new Fx.Tween($('photoViewer'),'width');
	myflashTween7 = new Fx.Tween($('photoViewer'),'height');
	
	myflashTween.start(662, 970);
	myflashTween2.start(652, 960);
	//myflashTween6.start(662, 970);
	
	myflashTween1.start(405, 577);
	myflashTween11.start(405, 577);
	myflashTween12.start(0,8);
	myflashTween13.start(0,8);
	
	
	//myflashTween3.start(418, 496);
	myflashTween3.start(394, 567);
	
	//myflashTween7.start(418, 506);
	
	myflashTween5 = new Fx.Tween($$('#rowA .colB')[0],'marginLeft');
	myflashTween5.start(0,70006);
	
	$$('#rowTweenAB .colA .topcap')[0].setStyle('display','block');
	$$('#rowTweenAB .colB .topcap')[0].setStyle('display','block');
	$$('#rowA .colA')[0].setStyle('backgroundImage' , 'url(../images/gallery/nhl_rAcA_botcap.jpg)');
	
}

function resizeFlashSmall(){
	$$('#rowA .colB')[0].setStyle('display','block');
	
	myflashTween = new Fx.Tween($$('#rowA .colA')[0],'width');
	myflashTween1 = new Fx.Tween($$('#rowA .colA')[0],'height');
	myflashTween11 = new Fx.Tween($('rowA'),'height');
	myflashTween12 = new Fx.Tween($$('#rowTweenAB .colA')[0], 'marginTop');
	myflashTween13 = new Fx.Tween($$('#rowTweenAB .colB')[0], 'marginTop');
	
	myflashTween2 = new Fx.Tween($$('.flashBox')[0],'width');
	myflashTween3 = new Fx.Tween($$('.flashBox')[0],'height');
	
	myflashTween4 = new Fx.Tween($$('#rowA .colB')[0],'marginTop');
	myflashTween5 = new Fx.Tween($$('#rowA .colB')[0],'marginLeft');
	
	myflashTween6 = new Fx.Tween($('photoViewer'),'width');
	myflashTween7 = new Fx.Tween($('photoViewer'),'height');
	
	myflashTween.start(970, 662);
	myflashTween2.start(960, 652);
	//myflashTween6.start(970, 662);
	
	myflashTween1.start(567, 405);
	myflashTween11.start(567, 405);
	myflashTween12.start(8,0);
	myflashTween13.start(8,0);
	
	//myflashTween3.start(496, 418);
	myflashTween3.start(567, 394);
	
	//myflashTween7.start(506, 418);
	$$('#rowA .colB')[0].set('tween', {duration: 'long'});

	//myflashTween4.set(70006);
	myflashTween4.start(70006, 0);
	myflashTween5.start(70006,0);
	
	$$('#rowTweenAB .colA .topcap')[0].setStyle('display','none');
	$$('#rowTweenAB .colB .topcap')[0].setStyle('display','none');
	$$('#rowA .colA')[0].setStyle('backgroundImage' , 'none;');
}

function showAdvSearch(){
	L = parseInt($$('.flashBox')[0].getPosition().x) + parseInt(parseInt($$('.flashBox')[0].getStyle('width'))/2) - parseInt(parseInt($('advSearchArea').getStyle('width'))/2);
	T = parseInt($$('.flashBox')[0].getPosition().y) + parseInt(parseInt($$('.flashBox')[0].getStyle('height'))/2) - parseInt(parseInt($('advSearchArea').getStyle('height'))/2);
	$('advSearchAreaBG').setStyle('left',L);
	$('advSearchAreaBG').setStyle('top',T);
	$('advSearchAreaBG').setStyle('display','block');
	
	$('advSearchArea').setStyle('left',L);
	$('advSearchArea').setStyle('top',T);
	$('advSearchArea').setStyle('display','block');

	
}

function advSearchFilterSwap(y){
	for(x=1; x<7;x++){
		$('zone'+x).setStyle('display','none');	
	}
	$('dynZone').setStyle('overflow','hidden');
	myDynTween = new Fx.Tween($('dynZone'),'height');
	myDynTween.start($('dynZone').getStyle('height'),$('zone'+y).getStyle('height'));
	$('zone'+y).setStyle('display','block');	
}





























