/**********************************************************************************
* phpComasy, Open Source Web Content Management System                            *
* http://www.phpcomasy.org                                                        *
*                                                                                 *
* Copyright (c) 2005 - 2011 indual	 gmbh (http://www.indual.ch)	              *
*                                                                                 *
* phpComasy is released under his own licence (http://www.phpcomasy.com/licence)  *
**********************************************************************************/


Event.observe(window, 'resize', function() {	
	changeSize();	
});

document.observe("dom:loaded", function() {
	changeSize();
	new PeriodicalExecuter(changeSize, 0.1);
});

function changeSize() {
	var viewport = document.viewport.getDimensions();
	var width = viewport.width;
	var height = viewport.height;
	var divRatio = width / height;
	
	$('content_right').style.width = width-500+'px';
	$('content_right').style.height = height+'px';
	$$('.slider_arrows').each(function(s){
		s.style.width = width-500+'px';
	});
	

	$$('div#content_right div.slider', 'div#content_right div.slider_wrap', 'div#content_right div.slide').each(function(s){
		s.style.width = width-500+'px';
		s.style.height = height+'px';
	});
	
	var tempWidth = width-500;
	var i = 1;
	
	$$('div#content_right .slider img').each(function(s) {
		imgRatio = s.getWidth() / s.getHeight();
		if ((tempWidth / imgRatio) > height) {
			s.style.width = tempWidth + 'px';
			s.style.height = 'auto';			
		}
		else {
			s.style.width = 'auto';
			s.style.height = height + 'px';
		}
		if (imgRatio > 1) {
			widthDiff = s.getWidth() - tempWidth;
			if (widthDiff > 0) {
				s.style.margin = '0 0 0 -'+(widthDiff/2)+'px';
			}	
			else {
				s.style.margin = '0';
			}	
		}
		else {
			heightDiff = s.getHeight() - height;			
			if (heightDiff > 0) {
				s.style.margin = '-'+(heightDiff/2)+'px'+' 0 0 0';
			}
			else {
				s.style.margin = '0';
			}
		}
	});
	
	$$('div#content_right div.slider_track').each(function(s) {	
		s.style.height = height+'px';
		s.style.width = tempWidth*i+'px';
	});
}
