// Loading jQuery
var $ = jQuery.noConflict();

var activeFooterInfo, activeFooterFlickr;

function featureClick(featUrl) {
	window.location = featUrl;
}

function openFooterInfo (id) {
	if (activeFooterInfo == null) {
	 	$('#'+id).slideToggle('normal');
		activeFooterInfo = id;
	}
	else if (activeFooterInfo == id ) {
	 	$('#'+id).slideToggle('normal');
		activeFooterInfo = null;
	}
	else {
		$('#'+activeFooterInfo).slideToggle('normal',function callback() {
		  $('#'+id).slideToggle('normal');
		});	
		activeFooterInfo = id;
	}

}

function showSociable(postID) {
	if ($('div.post-share-open#share-'+postID).css('visibility') == 'hidden') {
		$('div.post-share-open#share-'+postID).css('visibility','visible');
	}
	else {	
		$('div.post-share-open#share-'+postID).css('visibility','hidden');
	}
}

function resizeImg() {
	// resize backgrounds width
	var width = $('body').width();
	var height = $(window).height();

	// resize background
	var bg = $.find('.bg-image');
	$(bg).css('width', width).css('height', height);
	$(bg).children().css('width', width);

	$(bg).show();
/*
                windowRatio = $(window).width()/$(window).height();
                        if (imgRatio <= windowRatio) {
                                $('#bgimg').width($(window).width());
                                $('#bgimg').height($(window).width()/imgRatio);
                        }
                        if (imgRatio > windowRatio) {
                                $('#bgimg').height($(window).height());
                                $('#bgimg').width($(window).height()*imgRatio);
                        } */
}



$(document).ready(function(){
	
	var fadeTime;
	if (browserVar == "IE") {
		fadeTime = 0;
	}
	else {
		$('body').css({opacity: .9999}); 
		fadeTime = 2000;
	}
	
	$('#footerbar').mouseenter(function(){
		if (activeFooterInfo == null) {
			
			$('div#footer-flickr').slideToggle('normal');
			activeFooterInfo = 'footer-flickr';
		} 
	});
	
	$('#footer-wrapper').mouseleave(function(){
		$('#'+activeFooterInfo).slideToggle('normal');
		activeFooterInfo = null;
	});

	function cycleImages (imgId) {
		if (imgId == undefined) {
			$("#feature-img div:first").fadeIn(fadeTime).fadeTo(5000, 1).fadeOut(fadeTime, function(){
				cycleImages($(this).next("div").attr("id"));
				/*$("#feature-img div:first").css("display","none");
				$(this).next("div").css("display","block");*/
				
			});

		}
		else {
			
			$("#"+imgId).fadeIn(fadeTime).fadeTo(5000, 1).fadeOut(fadeTime, function(){
				cycleImages($(this).next("div").attr("id"));
				
				/*$("#"+imgId).css("display","none");
				$(this).next("div").css("display","block");*/
			});
		}
	}
	
	function noCycleImages (imgId) {
		$("#feature-img-nofade div:first").fadeTo(2000, 1);
	}
	
	cycleImages();
	noCycleImages(); 
	
	// $('div.side-item-open').hide('fast', function callback() {
	//	resizeImg();
	// });
	
	$('div.side-item').click(function() {
		if ($(this).css("color") == 'rgb(0, 255, 138)' || $(this).css("color") == '#00ff8a') {
			$(this).text($(this).text().replace(/-/,'+'));
			$(this).css("color","#00B7EB");
		}
		else {
			$(this).text($(this).text().replace(/\+/,'-'));
			$(this).css("color","#00ff8a");
		}
		$(this).next("div.side-item-open").slideToggle('fast');
		return false;
	});

	//var img = $('#bgimg');

	//$(window).load(function() {
	//	img.removeAttr("width"); 
	//	img.removeAttr("height");
	//});

	//var imgRatio = img.width()/img.height();
	//var windowRatio = $(window).width()/$(window).height();

	//$(window).bind('resize', function(){
	//	resizeImg();
	//});

	resizeImg();

 });
