$(document).ready(function(){


/* SMOOTH SCROLLING*/

            $(function() {
                $('a').bind('click',function(event){
                    var $anchor = $(this);
                    
                    $('html, body').stop().animate({
                        scrollTop: $($anchor.attr('href')).offset().top
                    }, 1000,'easeOutExpo');
                    /*
                    if you don't want to use the easing effects:
                    $('html, body').stop().animate({
                        scrollTop: $($anchor.attr('href')).offset().top
                    }, 1000);
                    */
                    event.preventDefault();
                });
            });


/*END SMOOTH SCROLLING*/

	
$('#scrollbar').tinyscrollbar();

	//navigate prev/next on diary entries.
	

 	$(".next").live('mouseup',(function(){
		var idarr = $(this).attr("id").split("_");
 		var datastring = "entry="+idarr[1]+"&total="+idarr[2];
			$.ajax({
				url:"/ajax/ajax_nextentry.php?"+datastring,
				success: function(blogentry){
					$("#diary").html(blogentry);
					$('#scrollbar').tinyscrollbar();
				}
			});	

			return false;
		
	}));
	
	
	//*WORK SECTION*//
		$(".worknav").mouseup(function(){
		
		if(!($(this).hasClass("selected"))){
			//load it
			$(".worknav").removeClass("selected");
			$(this).addClass("selected");
			var idarr = $(this).attr("id").split("_");
			var datastring = "client="+idarr[0]+"&max="+idarr[1];
			$.ajax({
				url:"ajax/ajax_loadwork.php?"+datastring,
				success: function(work){
					$("#portfolioFrame").html(work);
					if(idarr[2]=="flash"){
						$("."+idarr[0]+"_flashholder_1").flash({
							src:"/2011/swf/mediaplayer.swf",
							width: 680,
							height: 420,
							autoplay: true,
						flashvars: {file:"../flv/"+idarr[0]+"_1.flv",autoplay:true}
						});	
					
					}
				}
			});			
		}
	
	});
	
	
	
	$(".prvnxt").live('mouseup',(function(){
		
		var dir = $(this).attr("id").split("_");
		var client = dir[0];
		var max = $(".counter_"+client).attr("id").split("_");
		
		var newPrev = parseInt(dir[2]) - 1;
		var newNext = parseInt(dir[2]) + 1;	
		
		if(newPrev <= 0){
			newPrev = max[2];
		}
		
		if(newNext>max[2]){
			newNext = 1;
		}
		
		
		 //hide all
		$(".workitem").hide();
		//show
		$("#workitem_"+dir[2]).show();
		if($("#workitem_"+dir[2]).hasClass("flash")){
			//clear all flash
			$(".flashholder").html("");
			//new flash
			var vidname = $("#workitem_"+dir[2]).find("div").attr("id");
			$("."+client+"_flashholder_"+dir[2]).flash({
				src:"/swf/mediaplayer.swf",
				width: 680,
				height: 420,
				autoplay: true,
				flashvars: {file:"../flv/"+vidname+".flv",autoplay:true}
			});	
			
		}
/*
			if(("#workitem_"+dir[2]).hasClass("flash")){
				alert("flash");
				var flashname = $(this+":first").attr("id");
				var s1 = new SWFObject("../swf/mediaplayer.swf","mediaplayer","590","360","8");
            	s1.addParam("allowfullscreen","true");
            	s1.addVariable("width","590");
            	s1.addVariable("height","360");
            	s1.addVariable("autoplay",true);
            	s1.addVariable("file","../flv/"+flashname+".flv");
            	s1.write("flashholder");					
			}
*/
		
		
		//update counter
		$(".counter_"+client).html(dir[2]+" of "+max[2]);
		//update nav ids
		$("."+client+"_prev").attr("id",client+"_prev_"+newPrev);	
		$("."+client+"_next").attr("id",client+"_next_"+newNext);	
		
		return false;
		}));



$(".art_next").mouseup(function(){
	
	var selectedart = $(this).attr("id").split("_");
	var max = $(".artcounter").attr("id").split("_");
	
	
	var next = 0;
	if(parseInt(selectedart[1])+1>max[1]){
		next = 1;
	}else{
		next = parseInt(selectedart[1])+1;
	}
	
	var previous = 0;
	if(parseInt(selectedart[1])-1<1){
		previous =  parseInt(max[1]);
	}else{
		previous = parseInt(selectedart[1])-1;
	}
	
	
	//first hide all img
	$(".artitem").hide();
	//show img
	$("#artitem_"+selectedart[1]).show();
	
	//hide all desc
	$(".artdesc").hide();
	//show desc
	$("#artwork_"+selectedart[1]).show();	
	//update counter
	$(".artcounter").html(selectedart[1]+" of "+max[1]);
	//update arrows
	$(".prvbtnart").attr("id","art_"+previous);
	$(".nxtbtnart").attr("id","art_"+next);
	
})
	
	
	/* ARROWS */
		
	$("#arrow_nxt").mouseover(function(){
		$(this).attr("src","images/arrow_next_hover.png");
	});
	$("#arrow_nxt").mouseout(function(){
		$(this).attr("src","images/arrow_next.png");
	});
	$("#arrow_pre").mouseover(function(){
		$(this).attr("src","images/arrow_pre_hover.png");
	});
	$("#arrow_pre").mouseout(function(){
		$(this).attr("src","images/arrow_pre.png");
	});
	
	
	
});
