/*
  *  function scroll();
  *  content: Content id
  *	 position up/down: 1/0
  *	 action start/stop: 1/0
  */
var time = false;
var limit = 0;
var speed = 25;
function scrollDiv( content, position, action ) {
	if (action == 0) {
		if ( time ) {
			clearTimeout( time );
		}
	} else {
		var scroll_content = $( content );
		var top_margin = parseInt(scroll_content.style.marginTop);
		var step;
		if ( position == 0 ) {
			limit = bot_limit;  
			step = -1;
		} else {
			limit = 0;
			step = 1;
		}
		if ( top_margin == limit ) {
			if ( time ) {
				clearTimeout( time );
			}
			return false;
		}
		
		scroll_content.style.marginTop = top_margin + step +'px';
		
		time = window.setTimeout("scrollDiv('"+ content +"', "+ position + ", " + action + ")", speed );
	}
}
function scrollHeight( outer, scroll ) {
	try {
		var bot_limit = $('outer').offsetHeight - $('scroll').offsetHeight;
		if ( bot_limit > 0) {
			bot_limit = 0;
		}
		return bot_limit;
	}
	catch ( e ) {
	
	}
}

/* showHideList */
var showHideListItem = false;
var showHideListTitle = false;
function showHideList ( title, content ) {
	var contentTitle = $( title );
	var contentBlock = $( content );
	
	/* from cookies */
	if ( contentBlock.style.display == 'block' ) {
		contentBlock.style.display = 'none';
		contentTitle.className = '';
		showHideListItem = false;
		showHideListTitle = false;
		
	} else {
		if ( ( showHideListTitle ) && ( showHideListItem ) ) {
			$( showHideListTitle ).className = '';
			$( showHideListItem ).style.display = 'none';
		}
		showHideListItem = content;
		showHideListTitle = title;
		/* cookies */
		setDataToCookie( 'showHideListItem', content );
		setDataToCookie( 'showHideListTitle', title );
		
		
		contentTitle.className = 'active';
		contentBlock.style.display = 'block';
	}
}
function updateList() {
	if (( !showHideListItem) && (!showHideListTitle)) {
		var activeItem = getDataFromCookie('showHideListItem');
		var activeTitle = getDataFromCookie('showHideListTitle');
		$( activeItem ).style.display = 'block';
		$( activeTitle ).className = 'active';
		showHideListItem = activeItem;
		showHideListTitle = activeTitle;
	}
}
/* showHideList */

function getDataFromCookie( cookieName ){
	labelName = cookieName;
	var labelLen = labelName.length;
	var cookieData = document.cookie;
	var cLen = cookieData.length;
	var i = 0;
	var cEnd;
	var selected_value = '';
	while (i < cLen) {
		var j = i + labelLen;
		if (cookieData.substring(i,j) == labelName) {
			cEnd = cookieData.indexOf(';',j);

		if (cEnd == -1) {
			cEnd = cookieData.length;
		}

		selected_value =  unescape(cookieData.substring(j+1, cEnd));
		}
		i++;
	}

	return selected_value;

}

function setDataToCookie( cookieName, value ){
	var exp = new Date();
	var oneYearFromNow = exp.getTime() + (365 * 24 * 60 * 60 * 1000);
	exp.setTime(oneYearFromNow);
	document.cookie = cookieName + "=" + value + "; expires=" + exp.toGMTString() + "; path=/;";
}

function showImageImage(url, width, height) {
	
	var config_w = 400;
	var config_h = 400;
	
	if( width != '' ) {
		config_w = width;
	}
	
	if( height != '' ) {
		config_h = height;
	}
	
	var config = {"url" : url, "scroll" : false, "width" : config_w, "height" : config_h }; 	
	
	createWindow(config);
}


function showObjectMediaPopup ( object_id ) {
	
	var oMedia = $('object_media');
	
	showHideObject( 'object_media' );
	if( oMedia.style.display != 'none' ) {
		showContent( '&object_id=' + object_id, 'js/object_media', 'object_media' );
	}
}