var is_opera =  navigator.userAgent.indexOf('Opera') > -1;
var is_safari = navigator.userAgent.indexOf('AppleWebKit/') > -1;
var is_chrome = navigator.userAgent.indexOf('Chrome') > -1;
var is_firefox = navigator.userAgent.indexOf('Firefox') > -1;
var is_mac = navigator.platform.toLowerCase().indexOf('mac') > -1;
var is_linux = navigator.platform.toLowerCase().indexOf('linux') > -1;
var ie6 = false;
var ie7 = false;
var ie8 = false;

$(document).ready(function() {

	if(is_safari) {
		$('body').addClass('browser-safari');
	}

	if(is_opera) {
		$('body').addClass('browser-opera');
	}
	
	$("#location a").colorbox({width:"630px", height:"500", iframe:true, opacity: 0.3});
	
	$("#gallery-items a").colorbox({rel:'photos'});
	$("#letters-items a").colorbox({rel:'photos'});
	

	$('a').map(function(i, el){
		if($(el).attr('rel') == 'external') {
			$(el).attr('target', '_blank');
		}
	})
	
    if(typeof slideshow_handler == 'object') {
        slideshow_handler.setup();
    }	
});


var slideshow_handler = {
    container: null,
    total_items: 4,
    last_item: null,
    delay: 4000,
    
    setup: function()  {
		setTimeout(function(){ slideshow_handler.changePic(); }, slideshow_handler.delay);
		last_item = 0;
    },
    
    changePic: function() {
		var last_pic = $('#home-slideshow .active');
		var next_index = this.last_item + 1;
		if(next_index == this.total_items) {
			next_index = 0;
		}
		
		var last_pic = $('#home-slideshow .active');
		$(last_pic).animate({
			opacity: 0
		  }, 1000, function() {
			// Animation complete.
		});
		setTimeout(function(){$(last_pic).removeClass('active')}, slideshow_handler.delay + 1000);
	
		var next_pic = $('#home-slideshow li')[next_index];
		$(next_pic).css({'opacity':'0'});
		$(next_pic).addClass('active');
		$(next_pic).animate({
			opacity: 1
		  }, 1000, function() {
			// Animation complete.
		});
		
		this.last_item = next_index;
		setTimeout(function(){ slideshow_handler.changePic(); }, slideshow_handler.delay + 1000);
    }
}
