var itemWidth = 173;
var itemInRow = 3;
var exampleFx = new Object();

var galleryLoad = function()
{
	var itemCount = $('hul').getChildren().length;
	$('hul').setStyle('width', itemCount * itemWidth + "px");

	var curWidth = itemCount * itemWidth;    

	Fx.Styles.implement(	{ move:	function(leftTo)
									{
    									var curLeft = this.element.getStyle('left', true).toInt();
	
										if (leftTo < 0) // left
										{
											if (Math.abs(curLeft) + (itemWidth * itemInRow) < curWidth)
											{
												$('left_a').setOpacity(1);
												$('left_a').setStyle('background-position','');
												this.custom({'left': [curLeft, curLeft + leftTo]});
											}
											else
											{
												$('right_a').setOpacity(.5);
												$('right_a').setStyle('background-position','0 0');
											}
										}
										else // right
										{
											if (curLeft != 0)
											{
												$('right_a').setOpacity(1);
												$('right_a').setStyle('background-position','');
												this.custom({'left': [curLeft, curLeft + leftTo]});
											}
											else
											{
												$('left_a').setOpacity(.5);
												$('left_a').setStyle('background-position','0 0');
											}
										}
	
										var cn = "f" + (((Math.abs(curLeft) + (itemWidth * itemInRow)) / 684) - 1);
										cn = cn.substring(0,2);
									}	
    
							});

	exampleFx = new Fx.Styles('hul', { duration: 300, transition: Fx.Transitions.linear });
}



window.onload = function(){
	FixBackground();
}

function FixBackground(){
	var bg = document.getElementsByTagName("form")[0];
	var container = document.getElementById("container");
	var containerInner = document.getElementById("container-inner");
	var arrayPageSize = getPageSize();

	var height = Max(bg.clientHeight, container.clientHeight, arrayPageSize[1]);

	bg.style.height = height + "px";
	container.style.height = height + 80 + "px";
	containerInner.style.height = height - 57 + "px";
}

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//

function getPageSize(){

	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		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
		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 = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function Max(a,b,c){
	if(a > b){
		return ((a > c)? a : c);
	}else{
		return ((b > c)? b : c);
	}
}

// Transparent png in IE6 -------------------------------------
function fixPNG(element)
{

  //if IE 5.5-6
  if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent))
  {
    var src;
    if (element.tagName=='IMG') // if IMG
    {
        src = element.src;
        element.src = "/images/branding/blank.gif"; //replace the image by transparent gif
    }
    else // if not IMG
    {
      src = element.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i);
      if (src)
      {
        src = src[1]; 
        element.runtimeStyle.backgroundImage="none"; 
      }
    }
    // use AlphaImageLoader
    if (src) element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='image')";
  }
  
}