// JavaScript Document
Cufon.set('fontFamily', 'hiruko');

Cufon.replace('h1, h2, h3, h4, #head a, #foot p, .datebox span, .sfont', {
			  hover: true
			  });


/* VIDEO */
$(document).ready(function(){
	var vid_w = 440;
	var vid_h = 300;
	$(".youtubevideo").each(function(){
		var code = $(".code", this).html();
		$(this).html('<object width="'+vid_w+'" height="'+vid_h+'"><param name="movie" value="http://www.youtube.com/v/'+code+'"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'+code+'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="'+vid_w+'" height="'+vid_h+'"></embed></object>');
	})
	$(".vimeovideo").each(function(){
		var code = $(".code", this).html();
		$(this).html('<object width="'+vid_w+'" height="'+vid_h+'"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id='+code+'&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id='+code+'&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="'+vid_w+'" height="'+vid_h+'"></embed></object>');
	})
})

$(document).ready(function(){
	$(".js_comment").click(function(){
			 var target = $(this).attr("id");
			 $("#fb_"+target+" .wallkit_form").slideDown();
			 return false;
	});
})



/* GALLERY */
function myGallery(div, w, h){
	var curImg = 0;
	var galleryTo = 0;
	var DIV = "#"+div;
	var NAV = "#"+div+" .gal_navigation";
	var totGal = $(DIV+" ul li").length;
	
$(document).ready(function() {  
		$(DIV).append('<div class="gal_navigation"><span class="numeric" style="display: none"></span> <div class="prev"><span></span></div> <div class="next"><span></span></div> <span class="playpause" style="display: none"> </span></div>');
		$(DIV+" .playpause").html("Pause");
		$(DIV).css({
				   position: 'relative',
				   overflow: 'hidden',
				   display: 'block',
				   width: w+"px",
				   height: h+"px"
				   });
		$(NAV).css({
				   display: 'block',
				   width: w+"px"
				   });
		$(DIV+" li").each(function(){
					var index = $(DIV+" li").index(this);
					$(this).css({
						 position: 'absolute',
						 overflow: 'hidden',
						 height: h+"px",
						 top: 0,
						 left: 0,
						 margin: 0
					})
		})
		$(NAV+" .prev").css({
						   position: 'absolute',
						   top: 0,
						   left: 0,
						   height: h+'px',
						   width: '60px', //width: Math.floor(w/2)+'px',
						   opacity: '0.3'
						 })
		$(NAV+" .next").css({
						   position: 'absolute',
						   top: 0,
						   right: 0,
						   height: h+'px',
						   width: '60px', //width: Math.floor(w/2)+'px',
						   opacity: '0.3'
						 })
		$(NAV+" .prev span").css({
						   position: 'absolute',
						   left: 10+"px",
						   top: Math.floor(h/2)-17+"px",
						   display: 'block',
						   height: 34+'px',
						   width: 34+'px',
						   backgroundImage: 'url(http://www.picniccomics.com/site/picnic/css/images/gallery/bw_back.png)',
						   backgroundRepeat: 'no-repeat'
						 })
		$(NAV+" .next span").css({
						   position: 'absolute',
						   right: 10+"px",
						   top: Math.floor(h/2)-17+"px",
						   display: 'block',
						   height: 34+'px',
						   width: 34+'px',
						   backgroundImage: 'url(http://www.picniccomics.com/site/picnic/css/images/gallery/bw_next.png)',
						   backgroundRepeat: 'no-repeat'
						 })
		$(NAV+" .prev, "+NAV+" .next").mouseover(function() { $(this).stop().fadeTo('fast', 1) }).mouseout(function() { $(this).stop().fadeTo('fast', 0.3) });
		$(DIV).mouseenter(function() { $(NAV).stop().fadeTo('slow', 1) }).mouseleave(function() { $(NAV).stop().fadeTo('slow', 0) }); 
	
		$(NAV+" .playpause").click(function(){
			var c = $(NAV+" .playpause").html();
			switch(c){
				case "Pause":
				$(NAV+" .playpause").html("Play");
				clearInterval(galleryTo);
				break;
				
				case "Play":
				$(NAV+" .playpause").html("Pause");
				galleryTo = setTimeout(nextImg, 500);
				break;
			}
		})
		$(NAV+" .playpause, "+NAV+" .prev, "+NAV+" .next").css({ cursor: 'pointer'});
		$(NAV+" .prev").click(function(){
			var next = parseInt(curImg)-1;
			if(next < 0) next = parseInt(totGal)-1;
			changeImg(next);
		})
		$(NAV+" .next").click(function(){
			var next = parseInt(curImg)+1;
			if(next == totGal) next = 0;
			changeImg(next);
		})
		$(DIV+" li").each(function(){
			var li = this;
			var ii = $(DIV+" li").index(li);
			$(NAV+" .numeric").append(' <a href="#" num="'+ii+'" class="num">'+(ii+1)+'</a> ');
		});
		$(NAV+" .numeric .num").click(function(){
			var ii = $(this).attr('num');
			curImg = ii;
			changeImg(ii);
			return false;
		})
		//galleryInterval = setInterval(nextImg, 6000);
	
		function changeImg(ix){
			//$(DIV+" li").stop().css({opacity: 1});
			$(DIV+" li").stop().fadeOut();
			$(DIV+" li:eq("+ix+")").stop().css({opacity: 1});
			$(DIV+" li:eq("+ix+")").hide();
			$(DIV+" li:eq("+ix+")").fadeIn();
			$(NAV+" .numeric a").removeAttr('style');
			$(NAV+" .numeric a:eq("+ix+")").css({color: '#000000'});
			var c = $(DIV+" .playpause").html();
			if(c == "Pause"){
				clearInterval(galleryTo);
				galleryTo = setTimeout(nextImg, 7000);
			}
			curImg = ix;
			return false;
		}
		
		
		function nextImg(){
			var ix = parseInt(curImg) + 1;
			if(ix == totGal) ix = 0;
			else if(ix < 0) ix = totGal;
			changeImg(ix);
		}
		
		changeImg(0);
	});
}

