$(document).ready(function() {	
	$("#menu ul").superfish({
		autoArrows: false,
		delay: 400, // one second delay on mouseout
		animation: {opacity:'show',height:'show'}, // fade-in and slide-down animation
		speed: 'fast', // faster animation speed
		autoArrows: false, // disable generation of arrow mark-up
		dropShadows: false // disable drop shadows
	});
	
	$.fn.superbgimage.options = {
		id: 'superbgimage', // id for the containter
		z_index: 0, // z-index for the container
		inlineMode: 0, // 0-resize to browser size, 1-do not resize to browser-size
		showimage: 1, // number of first image to display
		vertical_center: 1, // 0-align top, 1-center vertical
		transition: 1, // 0-none, 1-fade, 2-slide down, 3-slide left, 4-slide top, 5-slide right, 6-blind horizontal, 7-blind vertical, 90-slide right/left, 91-slide top/down
		transitionout: 0, // 0-no transition for previous image, 1-transition for previous image
		randomtransition: 0, // 0-none, 1-use random transition (0-7)
		showtitle: 0, // 0-none, 1-show title
		slideshow: 0, // 0-none, 1-autostart slideshow
		slide_interval: gal_interval, // interval for the slideshow
		randomimage: 0, // 0-none, 1-random image
		speed: 'slow', // animation speed
		preload: 1, // 0-none, 1-preload images
		onShow: swap_i_btn // function-callback show image
		/*onClick: superbgimage_click, // function-callback click image
		onHide: superbgimage_hide, // function-callback hide image
		onMouseenter: superbgimage_mouseenter, // function-callback mouseenter
		onMouseleave: superbgimage_mouseleave, // function-callback mouseleave
		onMousemove: superbgimage_mousemove // function-callback mousemove*/
	};
	
	
	$('#thumbs').superbgimage();
	
	$('#next_btn a').click(function() {
		return $('#thumbs').nextSlide();
	});
	
	$('#previous_btn a').click(function() {
		return $('#thumbs').prevSlide();
	});
	
	/*jQuery(window).jbgcss(siteurl + "css/jbgallery.css");
	jQuery(".jbgallery").jbgallery({
            load : function(){
				swap_i_btn();
            },
			style : gal_style,
			interval: gal_interval
    });*/
	$('#startss').toggle(
		function () {
			$('#thumbs').startSlideShow(); 
			$("#startss span").html("Stop");
	  	},
	  	function () {
			$('#thumbs').stopSlideShow(); 
			$("#startss span").html("Start slideshow");
	  	}
	);
	
	var i_count = $(".info a").size();
	if (i_count != 1) {
		$(".info a").hide();
		$('#startss').removeClass("hide_ss").fadeOut(0).fadeIn(500);
	} else {
		$('#previous_btn').hide(0);
		$('#next_btn').hide(0);
	}
	function swap_i_btn (current_pic) {
		//var current_pic = $(".jbgallery").jbgallery("current");
		//var current_pic = 1;
		//$(".info a").hide();
		//$(".info a#i_"+current_pic).show();
		var i_count = $(".info a").size();
		if (i_count != 1) {
			$(".info a").hide();
			$(".info a#i_"+current_pic).show();
		} else {
			$(".hide").removeClass("hide");
		}
	}
	
	$.fn.qtip.styles.mystyle = { // Last part is the name of the style
	   background: '#000',
	   color: '#fff',
	   textAlign: 'center',
	   paddingLeft: 12,
	   paddingRight: 12,
	   paddingTop: 3,
	   paddingBottom: 3,
	   border: {
		  width: 1,
		  radius: 0,
		  color: '#ccc'
	   },
	   tip: { 
	   		corner: 'bottomMiddle',
			color: false,
			size: {
				x: 8,
				y : 10
			}
		},
	   name: 'dark'
	}
	
	$('a.tooltip[title]').qtip({
							   	style: {
								   name: 'mystyle'
								},
								show: { 
									effect: { type: 'fade', length: 800 },
									solo: true
								},
								hide: { 
									effect: { type: 'fade', length: 200 }
								},
							   	position: {
								  corner: {
									 target: 'topMiddle',
									 tooltip: 'bottomMiddle'
								  }
							   	}
	});

	
	$('#rss').qtip({
			  content: "My RSS feed",
				style: {
				   name: 'mystyle',
				   tip: { 
					  corner: 'bottomRight'
				   }
				},
				show: { 
					effect: { type: 'fade', length: 800 },
					solo: true
				},
				hide: { 
					effect: { type: 'fade', length: 200 }
				},
				position: {
				  corner: {
					 target: 'topMiddle',
					 tooltip: 'bottomRight'
				  }
				}
	});
	
	$('#twitter').qtip({
			  content: "My latest tweets",
				style: {
				   name: 'mystyle',
				   tip: { 
					  corner: 'bottomRight'
				   }
				},
				show: { 
					effect: { type: 'fade', length: 800 },
					solo: true
				},
				hide: {
					effect: { type: 'fade', length: 200 }
				},
				position: {
				  corner: {
					 target: 'topMiddle',
					 tooltip: 'bottomRight'
				  }
				}
	});

	$('.info').qtip({
			  content: "Read post or comment",
				style: {
				   name: 'mystyle',
				   tip: { 
					  corner: 'bottomLeft'
				   }
				},
				show: { 
					effect: { type: 'fade', length: 800 },
					solo: true
				},
				hide: { 
					effect: { type: 'fade', length: 200 }
				},
				position: {
				  corner: {
					 target: 'topMiddle',
					 tooltip: 'bottomLeft'
				  }
				}
	});
	$(".info").hover(
    	function () {
        	//$("#makeMeScrollable").slideUp(400);
      	}, 
      	function () {
			//$("#makeMeScrollable").slideToggle(400);
      	}
    );
	
	
	$('#previous_btn').qtip({
			  content: "Previous photo",
				style: {
				   name: 'mystyle',
				   tip: { 
					  corner: 'leftMiddle'
				   }
				},
				show: { 
					effect: { type: 'fade', length: 800 },
					solo: true
				},
				hide: { 
					effect: { type: 'fade', length: 200 }
				},
				position: {
				  corner: {
					 target: 'rightMiddle',
					 tooltip: 'leftMiddle'
				  }
				}
	});
	
	$('#next_btn').qtip({
			  content: "Next photo",
				style: {
				   name: 'mystyle',
				   tip: { 
					  corner: 'rightMiddle'
				   }
				},
				show: { 
					effect: { type: 'fade', length: 800 },
					solo: true
				},
				hide: { 
					effect: { type: 'fade', length: 200 }
				},
				position: {
				  corner: {
					 target: 'leftMiddle',
					 tooltip: 'rightMiddle'
				  }
				}
	});
	
	
		
	$('a.tooltip img').hover(
    	function () {
			$("a.tooltip img").not(this).stop().fadeTo("fast", 0.2);
      	}, 
      	function () {
			$("a.tooltip img").not(this).stop().fadeTo("fast", 1);
      	}
    );
	
	$(".page_item a, .info a").colorbox({width:"80%", height:"90%"});
    $(".info").click(function () {
		$("#makeMeScrollable").slideUp(400);
		return false;
	});





	/*$("div.scrollableArea a").click(function () {
		var new_pic = $(this).attr('id');
		jQuery(".jbgallery").jbgallery("go" , new_pic);
		return false;
	});
	
	$("#next_btn").click(function () {
		jQuery(".jbgallery").jbgallery("right");
		return false;
	});
	$("#previous_btn").click(function () {
		jQuery(".jbgallery").jbgallery("left");
		return false;
	});*/
	
	var timer;
	if ($('#thumbnails').hasClass('thumbnails_hint')) {
		$("#makeMeScrollable").slideToggle(400);
		timer = setTimeout(hideGridShowToolTip, 1500);
	}
	function hideGridShowToolTip() {
		//$("#makeMeScrollable").toggle("slow");
		$("#makeMeScrollable").slideToggle(400);
		$('.thumbnails_hint').qtip({
						  content: 'Roll over to open thumbnails or press "i" to view post and comment',
							style: {
							   name: 'mystyle',
							   padding: 15,
							   tip: { 
	   							  corner: 'bottomLeft'
							   }
							},
							//show: { ready: true },
							show: { 
								when: { event: 'dblclick' },
								ready: true,
								effect: { type: 'fade', length: 1500 },
								solo: true
							},
							hide: { 
								when: { event: 'mouseover' },
								effect: { type: 'fade', length: 200 }
							},
							position: {
							  corner: {
								 target: 'topMiddle',
								 tooltip: 'bottomLeft'
							  }
							}
	});
	
	/*if (jQuery.browser.msie && parseInt(jQuery.browser.version) == 6) {
		
	} else {
		$('#startss').removeClass("hide_ss");
		$('html.jbg').addClass("slideshowfix");
		$('body.jbg').addClass("slideshowfix");
		$('.jbgallery').addClass("slideshowfix");
		$('.jbgallery table').addClass("slideshowfix");
		$('.jbgallery td').addClass("slideshowfix");
	}*/
	//$('#rss').removeClass("hide_ss").fadeOut(0).fadeIn(500);
	//$('#twitter').removeClass("hide_ss").fadeOut(0).fadeIn(500);
		
	}
	$("#thumbnails").click(function () {
		$("#makeMeScrollable").slideToggle(400);
		return false;
	});
	$("#thumbnails").hover(
    	function () {
			$("#makeMeScrollable").slideToggle(400);
      	}, 
      	function () {
       		//
      	}
    );
	$("#makeMeScrollable").hover(
    	function () {
        	clearTimeout(timer);
      	}, 
      	function () {
			$("#makeMeScrollable").slideToggle(400);
      	}
    );
	
	
	$("#latesttweets a").attr("target", "_blank");
	$("#twitter").click(function () {
		$("#latesttweets").slideToggle(400);
		return false;
	});
	
	$("a#allowed_tags_switcher").live("click", function(){
		$("p#allowed_tags").toggle("fast");
		return false;
	});

});