// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

/**************************************************************************
Main Functions
***************************************************************************/

window.onload = set_nav_height;

function set_nav_height( ) {
	var nav = document.getElementById( "nav" );
	var content = document.getElementById( "shop_content" );
	
	if( content.offsetHeight > nav.offsetHeight ) {
		nav.style.height = content.offsetHeight + "px";
	} else {
		nav.style.height = nav.offsetHeight + 40 + "px";
	}
	
	/*alert( "nav height: " + nav.offsetHeight
	 		+ "\ncontent height: " + content.offsetHeight );*/
}

/**************************************************************************
Gallery Functions
***************************************************************************/
function show_picture( id ) {
	var div_id = "picture_" + id;
	document.getElementById( div_id ).style.display = "block"
	
	center_picture( id );
}

function hide_picture( id ) {
	var div_id = "picture_" + id;
	document.getElementById( div_id ).style.display = "none";
}

function center_picture( id ) {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		win_width = window.innerWidth;
		win_height = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		win_width = document.documentElement.clientWidth;
		win_height = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		win_width = document.body.clientWidth;
		win_height = document.body.clientHeight;
	}
	
	var div_id = "picture_" + id;
	var pic_div = document.getElementById( div_id );
	var pic_width = pic_div.clientWidth;
	var x = (win_width - pic_width) / 2;
		
	//alert( "setting x to " + x );
	pic_div.style.left = x + "px";
	
	var pic_height = pic_div.clientHeight;
	var y = (win_height - pic_height) / 2;
	//alert( "y set to " + y );

	var scrOfY = 0;
		
	if( typeof( window.pageYOffset ) == 'number' ) {
	    //Netscape compliant
	    scrOfY = window.pageYOffset;
	  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
	    //DOM compliant
	    scrOfY = document.body.scrollTop;
	  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
	    //IE6 standards compliant mode
	    scrOfY = document.documentElement.scrollTop;
	  }
	
	pic_div.style.top = y + scrOfY + "px";
}

/**************************************************************************
Catalog Functions
***************************************************************************/

function get_window_size() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return [myWidth, myHeight];
}

function center_tabs( ) {
	var total_items_width = 0;
	var items = document.getElementsByTagName( "li" );
	for( var x = 0 ; x < items.length ; x++ ) {
		/*alert( "li " + x + "'s width = " + items[x].clientWidth );*/
		total_items_width += items[x].clientWidth;
	}

	/*alert( "Total items width: " + total_items_width );*/

	var window_size = get_window_size( );
	/*alert( "Window's width: " + window_size[0] );*/

	var new_position = (window_size[0] - total_items_width) / 2;

	/*alert( "new position should be " + new_position );*/

	var ul = document.getElementsByTagName( "ul" );
	ul[0].style.marginLeft = new_position + "px";
}

function make_current( index ) {
	var items = document.getElementsByTagName( "li" );
	items[index].id = "current";
}