var minRightWidth = 500; 
var minHeight = 500;
var oldDocWidth = 0;
var scriptex = false;


var log = function(msg, value) {
	if (typeof(value)!="undefined") {
		msg = msg + '<span class="log_value">' + value + '</span>';
	}
	$("#logs").append(msg + "<br />");
}

var resizeWnd = function() {
	
	/*
	if(scriptex) return;
	scriptex = true;
	*/
	
	$("#logs").html("");
	var docWidth = $(window).width();		
	
	
	$("#mainContainer").width(docWidth);
	var rH = $(window).height();
	
	if(rH < minHeight) rH = minHeight;

	$("#leftImg").height(rH);
	
	var imgWidth = $("#leftImg").width();
	var leftContainerWidth = imgWidth;

	var rightWidth = docWidth - imgWidth;
	if(rightWidth < minRightWidth) {
		leftContainerWidth = leftContainerWidth - (minRightWidth - rightWidth);
		if(leftContainerWidth < 0 ) leftContainerWidth = 0;
		rightWidth = minRightWidth;
		log("leftContainerWidth = ", leftContainerWidth);
	}
	$("#leftContainer").width(leftContainerWidth);	
	$("#rightContainer").width(rightWidth ).css("padding-left", leftContainerWidth);
	//$(".scrollable").width(rightWidth - 165);
	$("#mainContainer").width(rightWidth + leftContainerWidth );
	
	
	if(imgWidth > leftContainerWidth) {
		$("#imgLeftContainer").css('left', leftContainerWidth - imgWidth);
	}
	else {
		$("#imgLeftContainer").css('left', "0px");
	}	
	

	var newDocWidth = $(window).width();
	if(newDocWidth != docWidth) {
		$("#mainContainer").width(newDocWidth);
		//$("#leftContainer").width(rightWidth + newDocWidth - docWidth);
	}

	/*
	log("right width: ", rightWidth);
	log("left cont: ", leftContainerWidth);
	log("doc width: ", docWidth);
	log("total: ", rightWidth + imgWidth);
	*/
	
	initScrollArticles();
	
	scriptex = false;
}

var resizeTimer = null;

$(window).bind('resize', function() {
	if (resizeTimer) clearTimeout(resizeTimer);
	resizeTimer = setTimeout(resizeWnd, 100);
	
});


function resizeWndTimer() {
	
	
	if (resizeTimer) clearTimeout(resizeTimer);	
	
	var docWidth = $(window).width();
	if(docWidth != oldDocWidth) resizeWnd();
	oldDocWidth = docWidth;	
	
	resizeTimer = setTimeout(resizeWndTimer, 100);
}

function initScrollArticles() {	
	
}

$.fn.clickScrollItem = function () {	
	return this.each(
		function(){
			var link = $(this).find("a").attr("href");
			$(this).click(
				function() {  
					document.location.href = link;
				}
			);				
		}
	);
}





$(document).ready(function() {

	var api = $("#art_scroll div.scrollable").scrollable({
				vertical:true, 
				size: 5,
				clickable: false, 
				keyboard: false, 
				api: true,
				prevPage: '#prev_art',
				nextPage: '#next_art',
			});
	$("#art_scroll .scrollable .items div").clickScrollItem();
	
	
	var api = $("#tags_scroll div.scrollable").scrollable({
				vertical:true, 
				size: 1,
				clickable: false, 
				keyboard: false, 
				api: true,
				prev: '#prev_tag',
				next: '#next_tag',
			});
	api.seekTo = api.seekToTags;
	api.movePage(0);
	
	var image = new Image();	
	image.onload = function() {		
		//alert("a");
		resizeWnd();
	};	
	//alert(blogPath + '/../images/blog.jpg');
	image.src = blogPath + '/../images/blog.jpg';
	//resizeWnd();
	resizeWnd();
	
	$(".postComments a").click( function () { 
			$(".commentsContainer").show();
			return false;
	});
	
	$("#tagsScrollLink").click(
		function() {
			$("#art_scroll").hide();
			$("#tags_scroll").show();
		}
	);
	
	$("#arttoogle a").click (function() {
		$("#art_scroll").toggle();		
		$("#tags_scroll").hide();
		return false;
	});
		
		/*
		$("#getd").click(function () { 
      		alert( $(window).width() + " - " + $(document).width()); 
    	});
    	*/
    	 
    	 	

});


