$(document).ready(function() {
    /* Each ShadowBox call is wrapped in a empty try-catch to stop failing on
    pages which might not have that content. Rather than sticking each one of
    these in individual files there's not a lot of them. */
	$("img[id^='BLOGGER_PHOTO_ID_']").each(function(index) {
		 $(this).parent('a').attr('rel', 'shadowbox');
		 $(this).parent('a').attr('onblur', ' ');
	});
	Shadowbox.init({
		'overlayOpacity': 0.8,
		height:     350,
        width:      350

	});
	$.ajaxSettings.cache = false;
	//$('.rounded').corner();
	$('.dropdown').mouseover(function(){
		$('#dropdown-item').css({'display' : 'block', 'z-index' : '9999999'});
	});
	$('.dropdown').mouseout(function(){
		$('#dropdown-item').css('display','none');
	});
	$('#dropdown-item').mouseover(function(){
		$('#dropdown-item').css('display','block');
	});
	$('#dropdown-item').mouseout(function(){
		$('#dropdown-item').css('display','none');
	});

    try {
        Shadowbox.setup('a.add-comment'); // rebind SB to comment links
    } catch (e) {

    }
    try {
        Shadowbox.setup('.gallery-link', {
            gallery: 'gallery'
        }); // bind to gallerys
    } catch (e) {

    }
	try {
        Shadowbox.setup('.rules', {
            gallery: 'content'
        }); // bind to content
    } catch (e) {

    }
    
    function displayFirstImage() {
        var image = $('.thumbs li a img').attr('src');

            if (image) {
                if(image.indexOf('/_120x90/') == -1){
                    var userName = image.replace("_120x90", "");//.substring(0, image.lastIndexOf('/')+1);
                    console.log(userName);
                    $('.jqgallery .bigImage img').attr('src', userName);
                }
                else {
                    alert('Something went wrong');
                }
            } else {
                $('#error').css('display', 'block');
            }

    }
	displayFirstImage();
    $('.thumbs a img').click(function() {
        $('.thumbs a').css('background-color','#fff');

        if ($(this).attr('src').search('_120x90') != -1) {
            thumb = ($(this).attr('src').replace(/_120x90/g, ""));

        }
        else {
            thumb = ($(this).attr('src').replace(/_jpg_100x100_crop_upscale_q85/, ""));
        }
        jQuery(this).parent().css('background-color','#ddd');
        $('.jqgallery .bigImage img').attr('src', thumb);
    });
});

function slideSwitch() {
	var $active = $('#slideshow div.active');
		if ( $active.length == 0 ) { 
			$active = $('#slideshow div:last');
		}
	var $next =  $active.next().length ? $active.next() : $('#slideshow div:first');

	$active.addClass('last-active');
	$next.css({opacity: 0.0})
		.addClass('active')
		.animate({opacity: 1.0}, 1000, function() {
		$active.removeClass('active last-active');
	});		   
}


