$(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
	});
	
	jQuery(window).jbgcss(siteurl + "css/jbgallery.css");
	jQuery(".jbgallery").jbgallery({
            load : function(){
				swap_i_btn();
            },
			style : gal_style,
			interval: gal_interval
    });
	$('#startss').toggle(
		function () {
			$(".jbgallery").jbgallery("play");
			$("#startss span").html("Stop");
	  	},
	  	function () {
			$(".jbgallery").jbgallery("stop");
			$("#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 () {
		var current_pic = jQuery(".jbgallery").jbgallery("current");
		//$(".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',
							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;
	});

});