$(document).ready(function(){
	$("a[rel^='prettyPhoto']").prettyPhoto({

			animationSpeed: 'normal', /* fast/slow/normal */
			padding: 30, /* padding for each side of the picture */
			opacity: 0.7, /* Value betwee 0 and 1 */
			showTitle: false, /* true/false */
			allowresize: false, /* true/false */
			counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
			theme: 'light_rounded' /* light_rounded / dark_rounded / light_square / dark_square */
		});
	
	markActiveLink();
	$('a').click(markActiveLink);
	setupAjaxCalendar();
	initSlider();
	$('#flashMessage').animate({"opacity": "1"}, 3000).fadeOut();
	
	$('ul.event-list > li.event-item:last').addClass('last');
	$('ul.event-list > li.event-item:first').addClass('first');
	$('ul.home-profile-thumbnails > li:last').addClass('last');
	$('table.calendar div.cell-data a:last').addClass('last');
	
	$("table.calendar td").mouseover(function () {
    $(this).toggleClass('hover');
  });
	$("table.calendar td").mouseout(function () {
    $(this).toggleClass('hover');
  });
	$("table.calendar td.hover div.cell-data").mouseover(function () {
    $(this).toggleClass('hover');
  });
	$("table.calendar td.hover div.cell-data").mouseout(function () {
    $(this).toggleClass('hover');
  });
	$('a[rel=print]').click(function(){window.print(); return false});
	$('a[rel=bookmark]').jFav();
	
	$('.inputs-toggle').hide();
	$('#inputs-toggle').click(function(){
		$('.inputs-toggle').toggle();
	});
	
	if(typeof sIFR == "function"){
		sIFR.bHideBrowserText = false; 
		
		sIFR.replaceElement("h2.alt-color", named({ sWmode:'transparent', 
			sFlashSrc: "/flash/avantgarde_book.swf",
			sBgColor: '#111111', 
			sColor: '#DB0D7E' , 
			sCase: "upper"})
			);
		sIFR.replaceElement(".home h2", named({ sWmode:'transparent',
			sFlashSrc: "/flash/avantgarde_book.swf",
			sColor: '#ffffff' ,
			sBgColor: '#111111'})
			);
		sIFR.replaceElement("h2", named({ sWmode:'transparent',
			sFlashSrc: "/flash/avantgarde_book.swf",
			sColor: '#ffffff' , 
			sCase: "upper",
			sBgColor: '#111111'})
			);
		sIFR.replaceElement(".home .intro h3", named({ sWmode:'transparent', 
			sFlashSrc: "/flash/avantgarde_book.swf",
			sBgColor: '#111111', 
			sColor: '#DB0D7E'})
			);
		sIFR.replaceElement("h3.alt-color", named({ sWmode:'transparent', 
			sFlashSrc: "/flash/avantgarde_book.swf",
			sBgColor: '#111111', 
			sColor: '#DB0D7E'})
			);
		sIFR.replaceElement("h3.section_heading", named({ sWmode:'transparent', 
			sFlashSrc: "/flash/avantgarde_book.swf",
			sBgColor: '#111111', 
			sColor: '#666666' , 
			sCase: "upper"})
			);
		/*sIFR.replaceElement("h4.profile-name", named({ sWmode:'transparent', 
			sFlashSrc: "/flash/avantgarde_book.swf",
			sBgColor: '#111111', 
			sColor: '#FFFFFF'})
			);*/
		sIFR.replaceElement("h4.section_heading", named({ sWmode:'transparent', 
			sFlashSrc: "/flash/avantgarde_book.swf",
			sBgColor: '#111111', 
			sColor: '#666666' , 
			sCase: "upper"})
			);
	};
});

var sliding = true;
var slideInt;
var scrollSpeed = 2;
var containerWidth = 950;
var itemWidth = 185;
var items;


function initSlider(){
	items = $('.home-profile-list li').get();
	$('.home-profile-list ul').css('position', 'relative')
	$('.home-profile-list ul').css('width', itemWidth*items.length+ 'px');
	
	$('.home-profile-list li').each(function(i){
		$(this).css('position', 'absolute');
		this.style.left = itemWidth * i + 'px';
		
	})
	
	$('.home-profile-list ul').mouseover(function(){
		sliding = false;
	});
	$('.home-profile-list ul').mouseout(function(){
		sliding = true;
	})
	
	slideInt = setInterval(doSlide, 40)
	
}
function doSlide(){
	
	if(sliding == true){
		
		for(var i=0; i<  items.length; i++){
			
			var ci = items[i]; 
			
			pos = ci.style.left.substring(0, ci.style.left.indexOf('px'));
			
			if(pos < 0-itemWidth){
				if(i == 0){
					prevItem = items[items.length-1];
				}else{
					prevItem = items[i-1];
				}
				pos = parseInt(prevItem.style.left.substring(0, prevItem.style.left.indexOf('px')) ) + 185;	
				//pos = containerWidth
				//debug(prevpos)
			}else{
				
				pos =  pos - scrollSpeed;
				
			}
			
			ci.style.left = pos +'px';
		}
		
	}
	
	//clearInterval(slideInt)
	
}

// Adds class "active" to currently active link
function markActiveLink(){
	$('a').each(function(){
		if(window.location.href == this.href){
			$(this).addClass('active');
		}
	})
}

function setupAjaxCalendar(){
	$('.ajax .cell-prev a').click(function(){
		loadAjaxCalendar(this.href);
		return false;
	});
	$('.ajax .cell-next a').click(function(){
		
		loadAjaxCalendar(this.href +'/1');
		return false;
	});
}


function loadAjaxCalendar(url){
	$('table.calendar').parent().load(url, null, setupAjaxCalendar);
}

function debug(msg) {
		if (window.console && window.console.log) 
			window.console.log('debug: ' + msg);
	};
	

jQuery.fn._offset = jQuery.fn.offset;
jQuery.fn.extend({
    offset: function() {
        var a = arguments;
        return (a.length) ? this.animate({ top: a[0].top || a[0], left: a[0].left || a[1] }, (a[0].top ? a[1] : a[2]) || 1) :
this._offset();
    }

}); 
