var transparentImage = "images/none.gif";
function fixTrans() {
	if (typeof document.body.style.maxHeight == 'undefined') {
		var imgs = document.getElementsByTagName("img");
		for (i = 0; i < imgs.length; i++) {	
			if (imgs[i].src.indexOf(".png") != -1){
					var src = imgs[i].src;
					imgs[i].src = transparentImage;
					imgs[i].runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='crop')";
				}
			}	
		}
}

if (document.all && !window.opera)
	attachEvent("onload", fixTrans);

function browser() {
    var cssFix = function(){
        var u = navigator.userAgent.toLowerCase(),
        addClass = function(el,val){
        if(!el.className) {
            el.className = val;
        } else {
            var newCl = el.className;
            newCl+=(" "+val);
            el.className = newCl;
        }
    },
    is = function(t){return (u.indexOf(t)!=-1)};
    addClass(document.getElementsByTagName('html')[0],[
        (!(/opera|webtv/i.test(u))&&/msie (\d)/.test(u))?('ie ie'+RegExp.$1)
        :is('firefox/2')?'gecko ff2'
        :is('firefox/3')?'gecko ff3'
        :is('gecko/')?'gecko'
        :is('chrome/')?'chrome'
        :is('opera/9')?'opera opera9':/opera (\d)/.test(u)?'opera opera'+RegExp.$1
        :is('konqueror')?'konqueror'
        :is('applewebkit/')?'webkit safari'
        :is('mozilla/')?'gecko':'',
        (is('x11')||is('linux'))?' linux'
        :is('mac')?' mac'
        :is('win')?' win':''
    ].join(" "));
}();
}
if (window.addEventListener)
	window.addEventListener("load", browser, false);
else if (window.attachEvent)
	window.attachEvent("onload", browser);

window.onload = function(){
	textChanger.init();
}
var textChanger = {
	cpanel : 'textchanger',  //set here the id of the element (div, p) within you want to insert the control panel
	defaultFS : 0.625,         //set here the default font size in 'em'
	init: function() {
		var cpel = document.getElementById(textChanger.cpanel);
		var el = document.body;
		if (cpel == null || el == null) {/*alert('The elements with the \"'+textChanger.cpanel+'\" and/or \"'+textChanger.element+'\" ID do not exist in HTML source.');*/} else {
		var u = document.createElement('ul');
		cpel.appendChild(u);
		u.innerHTML = 
		'<li id="decrease"><a href="#" title="Decrease font size">Smaller</a></li>'+
		'<li id="reset"><a href="#" title="Default font size">Reset</a></li>'+
		'<li id="increase"><a href="#" title="Increase font size">Lager</a></li>'
		var sz = textChanger.getCookie();
		el.style.fontSize = sz ? sz + 'em' : textChanger.defaultFS + 'em';
		var incr = document.getElementById('increase');
		incr.onclick = function(){textChanger.changeSize(1); return false;};
		var decr = document.getElementById('decrease');
		decr.onclick = function(){textChanger.changeSize(-1); return false;};
		var reset= document.getElementById('reset');
		reset.onclick = function(){textChanger.changeSize(0); return false;};
		}
	} ,
	changeSize: function(val) {
		var el = document.body;
		var fSize = parseFloat(el.style.fontSize);
		if (val == 1) {
			fSize += 0.1;
			if (fSize > 0.825) fSize = 0.825;
		} 
		if (val == -1) {
			fSize -= 0.1;
			if (fSize < 0.425) fSize = 0.425;
		}		
		if (val == 0) {
			fSize = textChanger.defaultFS;
		}
		el.style.fontSize = fSize + 'em';
		textChanger.updateCookie(fSize);
		} ,
		
	updateCookie: function(vl) {
		var today = new Date();
		var exp = new Date(today.getTime() + (365*24*60*60*1000)); //the cookie will expire in one year  
		document.cookie = 'textChangerL=size=' + vl + ';' +'expires=' + exp.toGMTString() + ';' +'path=/';
	} ,

	getCookie: function() { 
		var cname = 'textChangerL=size=';	
		var start = document.cookie.indexOf(cname);
		var len = start + cname.length;
		if ((!start) && (cname != document.cookie.substring(0,cname.length))) {return null;}
		if (start == -1) return null;
		var end = document.cookie.indexOf(";",len);
		if (end == -1) end = document.cookie.length;
		return unescape(document.cookie.substring(len, end));
	}
}

function initPopup(){
	var _duration = 400;
	if(typeof($) == 'function'){
		$('a.popup-btn').click(function(){
			var _box = this.href.substr(this.href.indexOf("#") + 1);
			if(_box){
				_box = $('#'+_box);
				if(_box.length){
					_popup = _box;
					displayPopup();
					return false;
				}
			}
		});
		/*--- function's ---*/
		function initH(){
			var _h = $('body').height();
			if(_h < $(window).height()) _h = $(window).height();
			return _h;
		}
		var _popup, popup_h;
		if($('#popup-fader').length == 0) $(document.body).append('<div id="popup-fader"></div>');
		popup_h = $('#popup-fader');
		popup_h.css({
			position:'absolute',
			top: 0,
			left: 0,
			zIndex: 300,
			background: '#000',
			opacity: 0,
			height: initH(),
			width: '100%',
			display: 'none'
		});
		function displayPopup(){
			_popup.css({top: $(window).scrollTop(), zIndex: 400});
			popup_h.css({opacity: 0, height: initH(), display: 'block'});
			popup_h.fadeTo(_duration, 0.7, function(){
				_popup.fadeIn(_duration/2);
			});
			_popup.find('.btn-close').one('click', function(){
				_popup.fadeOut(_duration/2, function(){
					popup_h.fadeOut(_duration, function(){
						_popup = false;
					});
				});
				return false;
			});
		}	
		
		
		$(window).resize(function(){
			if(popup_h.is(':visible') && _popup) popup_h.height(initH());
		});
	}
}
if (window.addEventListener) window.addEventListener("load", initPopup, false);
else if (window.attachEvent && !window.opera) window.attachEvent("onload", initPopup);