// (c) Artopod 2008, Author: Elin Tjerngren
$(document).ready(function(){	
// 	$("p").bind("mouseover",function(){
// 		$(this).animate({ color: "#3300ff" },600); 
// 	});
	$("#gallery").hide();
	 //{showArrows:true, scrollbarWidth: 15, arrowSize: 16}
	$("li.casethumb").bind("click",function(){
		if (!$("#gallery:hidden")[0] && $(this).hasClass("current")) {
			// hide gallery
			closeSlides();
		} else {
			// load gallery
			var url=$(this).children("a")[0].href;
			$("li.casethumb").removeClass("current");
			$(this).addClass("current");
			$("#inner").empty().load(url,function(){
				// pic's notes if exists:
				if ($("#gallery:hidden")[0]) {
					$("#gallery").slideDown("slow",function(){  

					});
											//$("#gallery").show();
				}
				var tot=400;
				$("#inner .pic img").each(function(){
					tot+=parseInt($(this).css("width"))+4;
				});
				$(".scrollpane, .jScrollPaneContainer").css("width",tot+"px");
				$("#theslide").css("height","390px");
				// styled scroll
				CSBfleXcroll("theslide");
				$("#theslide")[0].contentScroll(0,0,false);
// 				$("#theslide img").each(function(){
// 					$(this).addClass("png");	
// 				});
				// curl thingie
// 				if(curlOnload) curlOnload(); if(isIE){addIECurl(); }else {addCurl(); }
				if (typeof(cvi_curl)!="undefined") {
					$(".curl").each(function(){
						$(this).parent("a").hover(function(){
							cvi_curl.modify($(this).children(".curl")[0], { size: 7 });
						},function(){
							cvi_curl.modify($(this).children(".curl")[0], { size: 3 });
						}).click(function(){
							// se text:
							toggleNote($(this).parent(".pic").children(".txtnote:visible")[0],$(this).parent(".pic").children(".txtnote,.txtnote_bg"));
/*							if ($(this).parent(".pic").children(".txtnote:visible")[0]) {
								$(this).parent(".pic").children(".txtnote,.txtnote_bg").hide();
							} else {
								$(this).parent(".pic").children(".txtnote,.txtnote_bg").show();
							}*/
/*							$(this).parent(".pic").click(function() {
								$(this).parent(".pic").children(".txtnote,.txtnote_bg").hide(); 
								return false; 
							});*/
							return false;
						});
						$(this).parent("a").parent(".pic").children(".txtnote_bg,.txtnote").click(function() { 
							toggleNote($(this).parent(".pic").children(".txtnote:visible")[0],$(this).parent(".pic").children(".txtnote,.txtnote_bg"));
						});
						cvi_curl.add(this, { shadow: 90, color: 0, size: 3 });  
					});
				}
			});
			pageTracker._trackPageview(url); // google analytics
		}
		return false;
	});
	// fix width of the slider....check if it's wider than the viewport. 
	var slidetot=0; // this will hold the total width of inner slide
	var viewportw=parseInt($("#caseslide").css("width")); // width of viewport
	$("#caseslide li").each(function(){
		slidetot+=$(this)[0].offsetWidth; 
	});
	// pilar hö/vä, default-värden
	var curpos=0;
	$("#slideright").addClass("disabled"); // left arrow
	
	if (slidetot>viewportw) {
		$("#caseslide ul").css("width",slidetot+"px");
		var lastpos=-(slidetot-viewportw);
		var slideinterval=parseInt(0.7*viewportw);// 70% from width
		$("#caseslide ul").css("position","relative");
		// pil till höger
		$("#slideleft").click(function(){
			if (this.className.indexOf("disabled")!=-1) return false;
			var newpos=curpos-slideinterval;
			$("#slideleft").removeClass("disabled");
			$("#slideright").removeClass("disabled");
			if (newpos<lastpos) {
				newpos=lastpos;
				$("#slideleft").addClass("disabled");
			}
			$("#caseslide ul").animate({
				"left":newpos+"px"
			},1000, function() {
				curpos=newpos;	
			});
			pageTracker._trackPageview("/arrow/right"); // google analytics
			return false;
		})
		// pil till vänster
		$("#slideright").click(function(){
			if (this.className.indexOf("disabled")!=-1) return false;
			var newpos=curpos+slideinterval;
			$("#slideleft").removeClass("disabled");
			$("#slideright").removeClass("disabled");
			if (newpos>0) {
				newpos=0;
				$("#slideright").addClass("disabled");
			} 
			$("#caseslide ul").animate({
				"left":newpos+"px"
			},1000, function() {
				curpos=newpos;	
			});
			pageTracker._trackPageview("/arrow/left"); // google analytics
			return false;
		})
	} else {
		viewportw=slidetot;
		$("#slideleft").addClass("disabled"); // right arrow
	}

/* @annotation: sitter löst :-) */
	$(".right").bind("click",function(){
			alert("right?")
		$("#theslide").empty().load(this.href,function(){
			if ($("#gallery:hidden")[0]) {
				$("#gallery").slideDown("slow");
			}
			
/*			if(document.getElementById(conf_imageflow))
			{
				hide(conf_loading);
				refresh(true);
				show(conf_images);
				show(conf_scrollbar);
				initMouseWheel();
				//initMouseDrag();
					
			}  */
		});
		return false;
	});
	$("#closewin").click(closeSlides);
	
	// blog - sidebar:
	$(".js_switch a").click(sidebarSwitch);
	$(".js_switch a.current").each(sidebarSwitchStart);
/*	$(".js_list").hide();
	$(".js_list:first").show();*/
});
function sidebarSwitch() {
	$(".js_switch a").removeClass("current");
	$(this).addClass("current");
	var n=$(this).parent(".js_switch")[0].className.replace(/.*(list_[^ ]+).*/,"$1");
	$(".js_list").hide("slow");
	$("#"+n).show("slow");
	pageTracker._trackPageview("/sidebarswitch/"+n); // google analytics
	return false;
}
function sidebarSwitchStart() {
	var n=$(this).parent(".js_switch")[0].className.replace(/.*(list_[^ ]+).*/,"$1");
	$(".js_list").hide();
	$("#"+n).show();
	pageTracker._trackPageview("/sidebarswitch/"+n); // google analytics
	return false;
}
function toggleNote(isVis,jQobj) {
	if (isVis) {
		jQobj.hide();			
	} else {
		jQobj.show();
	}			
}
function closeSlides() {
	if ($("#gallery:visible")[0]) {
		$("#gallery").slideUp("slow",function(){
			$("li.casethumb").removeClass("current");
		});
	}
	return false;
}
			
function chP(imgurl,ID) {
	$("#"+ID)[0].src=imgurl;
}

// addition to imageflow.js
// function handleBigPict(url) {
// 	$("#photo").empty().append('<img src="'+url+'" />').fadeIn();
// }