$(function(){
    if (/Windows/.test(navigator.userAgent) && getIEVersion() < 9 ){
	    initCufon();
	}
	else{
	    initCufon_transitional();
	}
	if(!navigator.platform.match(/iphone/i) && !navigator.platform.match(/ipad/i)){
    	initPosSidebar();
    	initPosHeader();
    	initPosScroll();
	    initNav();
    }
})
function getIEVersion() {
  var rv = -1;
  if (navigator.appName == 'Microsoft Internet Explorer') {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}
// init Navigation
function initNav(){
    $(document).ready( function(){
        var thisBody = document.body || document.documentElement,
        thisStyle = thisBody.style,
        support = thisStyle.transition !== undefined || thisStyle.WebkitTransition !== undefined || thisStyle.MozTransition !== undefined || thisStyle.MsTransition !== undefined || thisStyle.OTransition !== undefined;
    
        if(!support){
        	$('#nav').removeClass('css3transition');
            $('#nav li').hover(function(){
                $(this).find('span').stop().animate({
                   duration: 1,
                       width: 12,
                       easing: 'linear' });
               }, function(){
                $(this).find('span').stop().animate({
                  duration: 300,
                      width: 1 });
              });
        }
});
}
// initCufon
function initCufon(){
	Cufon.replace ('#content p, .list a, #content h3, #content a, form label, table', {fontFamily: 'DIN-Regular' } );
	Cufon.replace('#nav a , #content h2', { fontFamily: 'DIN-medium'});
	Cufon.replace('.date, .comments, .category', { fontFamily: 'DIN-bold'});
	Cufon.replace('.table th, .logo-holder a', { fontFamily: 'DIN-black'});
}
function initCufon_transitional(){
    Cufon.replace('.logo-holder a', { fontFamily: 'DIN-black'});
	Cufon.replace('#nav a , #content h2', { fontFamily: 'DIN-medium'});
}
// initPosSidebar
function initPosSidebar(){
	var sidebar = $('#sidebar');
	var scTop = sidebar.find('.sidebar-holder').offset().top - 54;
	var _window = $(window);
	_window.scroll(function(){
		var top = _window.scrollTop();
		posSide(top);
	})
	function posSide(top){
		if(top - 32 >= scTop){
			sidebar.css({
				position:'fixed',
				top: -scTop
			});
		}else{
			sidebar.css({
				position: 'relative',
				top: 0
			})
		}
	}
}
// initPosHeader
function initPosHeader(){
	var heading = $('#content .heading');
	var scTop = heading.offset().top - 34;
	var _window = $(window);
	_window.scroll(function(){
		var top = _window.scrollTop();
		posSide(top);
	})
	function posSide(top){
		if(top -32 >= scTop){
			heading.css({
				position:'fixed',
				zIndex: 10,
				top: 0
			});
		}else{
			heading.css({
				position: 'absolute',
				top: 0
			})
		}
	}
}
// initPosScroll
function initPosScroll(){
	var sidebar = $('#sidebar');
	var heading = $('#content .heading');
	var _window = $(window);
	_window.scroll(function(){
		var left = _window.scrollLeft();
		elPos(left)
	});
	function elPos(left){
		sidebar.css({
			marginLeft: -left
		})
		heading.css({
			marginLeft: -left
		})
	}
}

