$(document).ready(function() {

/* Use this js doc for all application specific JS */
$(window).resize(function() {
	console.log($(window).width());
	//
	var _w = $('.who').outerHeight();
	var _h = $('.who h4').outerHeight();
	var _h2 = -(_w)+_h;
	$('.who').css({"bottom": _h2});
	//
	var _menuW = $('.leftmenu').width();
	$("#menu").width(_menuW);
	//
	if ($(window).width() < 767){
		 $("#menu").css({ "position": "static" });
	} else {
		if ($(this).scrollTop() > 400) { 
        	$("#menu").css({ "position": "fixed", "top": "0"});
		} else {
        	$("#menu").css({ "position": "static"});
    	}
	}
	
});

$(window).load(function()	{
	//
	
});

$(window).scroll(function() {
var _menuW = $('.leftmenu').width();
$("#menu").width(_menuW);
console.log(_menuW);
   if ($(window).width() < 767){
		 $("#menu").css({ "position": "static" });
	} else {
		if ($(this).scrollTop() > 400) { 
        	$("#menu").css({ "position": "fixed", "top": "0"});
		} else {
        	$("#menu").css({ "position": "static"});
    	}
	}                         
 });

/* TABS --------------------------------- */
/* Remove if you don't need :) */
	
var tabs = $('dl.tabs');
tabsContent = $('ul.tabs-content');
	
tabs.each(function(i) {
//Get all tabs
var tab = $(this).children('dd').children('a');
tab.click(function(e) {
			
//Get Location of tab's content
var contentLocation = $(this).attr("href")
contentLocation = contentLocation + "Tab";
			
//Let go if not a hashed one
if(contentLocation.charAt(0)=="#") {
			
	e.preventDefault();
			
	//Make Tab Active
	tab.removeClass('active');
	
	$(this).addClass('active');
				
	//Show Tab Content
	$(contentLocation).parent('.tabs-content').children('li').css({"display":"none"});
	$(contentLocation).css({"display":"block"});
				
} 
});
});
	
	
/* PLACEHOLDER FOR FORMS ------------- */
/* Remove this and jquery.placeholder.min.js if you don't need :) */

$('input, textarea').placeholder();


/* SLIDER */
$('#slider01').orbit({
	animationSpeed: 900,
	directionalNav: false,
	bullets: true,
	centerBullets: false
});
$('#slider02').orbit({
	animationSpeed: 900,
	directionalNav: false,
	bullets: true,
	centerBullets: false
});

/* BOURSIER */
var _w = $('.who').outerHeight();
var _h = $('.who h4').outerHeight();
var _h2 = -(_w)+_h;
$('.who').css({"bottom": _h2});	
$('.pictholder').hover(function(){
	// get var
	var _who = $(this).find('.who');
	
		_who.stop(true, true).animate({ bottom:'0' },"fast");
		$(this).find('img').stop(true, true).fadeTo("fast", 0.6);
	},function(){
	// get var
	var _who = $(this).find('.who');
	var _whoh4 = $(this).find('.who h4');
	
	var _w = _who.outerHeight();
	var _h = _whoh4.outerHeight();
	var _h2 = -(_w)+_h;
	console.log(_h2);
   		_who.stop(true, true).animate({ bottom: _h2 },"fast");
   		$(this).find('img').stop(true, true).fadeTo("fast", 1.0);
	});	

$('.profilenav a').click(function(e){
	var l = $(this).attr("href");
	//l = l.substr(1);
	console.log(l);
	$.scrollTo(l, 800, 'easeOutCubic');
	$('.profilenav li').removeClass('selected');
	$(this).closest('li').addClass('selected');
	e.preventDefault();
});

/* DETECT SCROLLING POSITION */
$('a[href=#top]').click(function(e){
    $('html, body').animate({scrollTop:0}, 1000);
    e.preventDefault();
});

function isScrolledIntoView(elem) {
    var docViewTop = $(window).scrollTop();
    var docViewBottom = docViewTop + $(window).height();

    var elemTop = $(elem).offset().top;
    var elemBottom = elemTop + $(elem).height();

    return ((elemBottom >= docViewTop) && (elemTop <= docViewBottom));
}
/*
    var myelement = $('.partners');
    var mymessage = $('#backtotop');
    $(window).scroll(function() {
        if(isScrolledIntoView(myelement)) {
            mymessage.fadeIn('500'); 
        }
         else {
            mymessage.fadeOut('100')
        }
	});
*/	
	
/* GALLERIE */
$("a.group_image").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	true
});

//target _blank
$('a[rel="external"]').click( function() {
	window.open( $(this).attr('href') );
	return false;
});

//
});
