var MSIE = navigator.userAgent.indexOf('MSIE') >= 0 ? true : false;
var MSIE7 = navigator.userAgent.indexOf('MSIE 7') >= 0 ? true : false;
var MSIE8 = navigator.userAgent.indexOf('MSIE 8') >= 0 ? true : false;
var __scrollTop = 0;

function switchDisplay(element) {
	if (element.style.display == 'block' || element.style.display == '') {
		element.style.display = 'none';
	} else {
		element.style.display = 'block';
	}
}

function f_clientWidth() {
	return f_filterResults(
			window.innerWidth ? window.innerWidth : 0,
			document.documentElement ? document.documentElement.clientWidth : 0,
			document.body ? document.body.clientWidth : 0);
}

function f_clientHeight() {
	return f_filterResults(window.innerHeight ? window.innerHeight : 0,
			document.documentElement ? document.documentElement.clientHeight
					: 0, document.body ? document.body.clientHeight : 0);
}

function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function getDocumentScrollTop() {
	var scrollTop = 0;
	// if(document.documentElement)
	scrollTop = document.documentElement.scrollTop;
	// else
	// scrollTop = document.body.scrollTop;
	__scrollTop = scrollTop;
	return (scrollTop + 10);
}

function getWindowScroll() {
	var T, L, W, H;
	w = window;
	with (w.document) {
		if (w.document.documentElement && documentElement.scrollTop) {
			T = documentElement.scrollTop;
			L = documentElement.scrollLeft;
		} else if (w.document.body) {
			T = body.scrollTop;
			L = body.scrollLeft;
		}
		if (w.innerWidth) {
			W = w.innerWidth;
			H = w.innerHeight;
		} else if (w.document.documentElement && documentElement.clientWidth) {
			W = documentElement.clientWidth;
			H = documentElement.clientHeight;
		} else {
			W = body.offsetWidth;
			H = body.offsetHeight;
		}
	}
	return {
		top : T,
		left : L,
		width : W,
		height : H
	};
}
function getWinSize() {
	var iWidth = 0, iHeight = 0;
	var document = window.document;
	if (document.documentElement && document.documentElement.clientHeight) {
		iWidth = parseInt(document.documentElement.clientWidth);
		iHeight = parseInt(document.documentElement.clientHeight);
	} else if (document.body) {
		iWidth = parseInt(document.body.offsetWidth);
		iHeight = parseInt(document.body.offsetHeight);
	}

	var marginHeight = 40;
	var marginWidth = 35;
	
	if(MSIE)
	{
		marginHeight = 65;
		marginWidth = 30;
	}
	return {
		width : (iWidth-marginWidth),
		height : (iHeight-marginHeight)
	};
}

function resize_id(obj, percentage, options) {
	var oContent;
	
	if(!(oContent = $(obj))){ return }

	var oWinSize = getWinSize();
	
	options = Object.extend({
		margin: {
			height: 0,
			width: 0
		}
	},	options || {});
	try{
		oContent.style.height = (((oWinSize.height) - parseInt(oContent.offsetTop))-options.margin.height)+'px';
	}catch(err){}

	if(percentage > 0){
		oContent.style.width = (((oWinSize.width)*(percentage/100))-options.margin.width)+'px';
	}
}

function resize_image(id){
	var image = $(id);
	if(!image) return;
	var oWinSize = getWinSize();
	
	if((image.offsetTop+image.offsetHeight) > oWinSize.height){
		var newHeight = (oWinSize.height-image.offsetTop)-10;
		var perc = (newHeight/image.offsetHeight);
		var newWidth = Math.round(image.offsetWidth*perc, 1);
		image.style.height = newHeight+'px';
		image.style.width = newWidth+'px';
	}

	if((image.offsetLeft+image.offsetWidth) > oWinSize.width){
		var newWidth = (oWinSize.width-image.offsetLeft)-25;
		var perc = (newWidth/image.offsetWidth);
		var newHeight = Math.round(image.offsetHeight*perc, 1);
		image.style.height = newHeight+'px';
		image.style.width = newWidth+'px';
	}
}
