$(function(){
		   
		// Hide button functionality (show/hide panel)
		$(".hide_button a").click(function(e){
			e.preventDefault();
			
			if($("#panel_tabs").hasClass("hidden")){
				$("#panel_tabs").removeClass("hidden");
				$("#panel_tabs").stop().fadeTo(600, 1);
				$("#main_panel").stop().animate({height:380}, 600, "easeInOutQuint");
				$(".hide_button a").text("HIDE");
			}else{
				$("#panel_tabs").addClass("hidden");
				$("#panel_tabs").stop().fadeTo(600, 0);
				$("#main_panel").stop().animate({height:56}, 400, "easeInOutQuint");
				$(".hide_button a").text("SHOW");
			}
			Cufon.replace('.hide_button a', {hover:true});
		});		   
})

$(function(){
	// function associated with URL changes
	$.history.init(showTab);
	
	// If no subsection/tab selected, open the first one
	if(!window.location.hash){
		showFirstTab();
	}
	
	
	$(".tab_button a").click(function(e){
		// Cancel the default behaviour to avoid base href conflicts
		if($(this).parent().hasClass("current")){
			return;
		}
		var hash=this.hash;
		if(hash.length){
			$.history.load(hash.substr(1));
		}
		else{
			return true;
		}
		return false;
	});
	
/*	var c_values = new Array();
	$("li.temp").each(function(){
		c_values.push(parseInt($(this).text()));
	});
	
	
	$('a[rel="view_pdf"]').click(function(e){
		e.preventDefault();
		var pdf_ref = this.href.substring(this.href.lastIndexOf('/')+1);
		showPDFViewer(pdf_ref);
	});
	
	
	$("a.temp_measure").click(function(e){
		e.preventDefault();
		
		var link = $(e.target);
		var c;
		var f;
		if(link.attr("id") == "C"){
			$('a.temp_measure[id="F"]').removeClass("active");
			$('a.temp_measure[id="C"]').addClass("active");
			
			$("li.temp").each(function(i){
				c = c_values[i];
				$(this).text(c+"ºc");
			});
			
		}else if(link.attr("id") == "F"){
			$('a.temp_measure[id="F"]').addClass("active");
			$('a.temp_measure[id="C"]').removeClass("active");
			
			$("li.temp").each(function(i){
				c = c_values[i];
				f = parseInt(((9/5)*c)+32);
				$(this).text(f+"ºf");
			});

			
		}
	});*/
});


function showFirstTab(){
	var tab_buttons = $(".first_container a");
	if(tab_buttons.length){
		var default_hash = tab_buttons[0].hash.substr(1);
		$.history.load(default_hash);
	}
	var tabs=$('.tab_container');
	if(tabs.length==1){
		$h=tabs.find('.tab_content_wrapper').css({height:'auto'}).height();
		//$('#panel_background').css({height:$h+80});
	} 
}

function showTab(hash){
	// If the passed hash value doesn't exist, redirect to (and open) the first tab
	if(!$("a[href=#"+hash+"]").length){
		showFirstTab();
		return;
	}
	
	// Close the last tab and open the new one
	$(".tab_content_wrapper.current .tab_content").jScrollPaneRemove();
	$(".tab_content_wrapper.current").stop().animate({height:0}, 400, "easeOutQuint");
	$(".tab_content_wrapper.current .tab_content").stop().animate({height:0}, 400, "easeOutQuint");
	
	$(".current").removeClass("current");
	
	var panel_h = $("#panel_tabs").height();
	var content_height = panel_h - ($(".tab_button").length*30);
	$("a[href=#"+hash+"]").parent().addClass("current");
	$("a[href=#"+hash+"]").parent().next().addClass("current");
	$(".tab_content_wrapper.current").stop().animate({height:0}, 350).animate({height:content_height}, 600, "easeOutQuint");
	//$(".tab_content_wrapper.current .tab_content").jScrollPane();
	$(".tab_content_wrapper.current .tab_content").stop().animate({height:0}, 350).animate({height:(content_height-10)}, 600, "easeOutQuint").animate({height:(content_height-10)}, 20, "easeOutQuint", function(){
		// show the scroll after X ms (if it's not weather)
		var noScrollPane = $(".noScrollPane", this).length;
		if(!noScrollPane){
			$(this).jScrollPane({showArrows:true,scrollbarWidth:9,dragMaxHeight:33,dragMinHeight:33});
		}
	});
}


/*var bayofkotor = 	new Array('doc_416631226792854', 'document_id=26619549&access_key=key-1phh0r2rfep4kqzg8zh4&page=1&viewMode=list');
var montenegro = 	new Array('doc_144140324028938', 'document_id=26619663&access_key=key-y5yox9j4vq4nx0wzbtv&page=1&viewMode=list');
var ozana = 		new Array('doc_112538344459337', 'document_id=27335011&access_key=key-nud1ghx6srrtwl5mixs&page=1&viewMode=list');
var tivat = 		new Array('doc_213624766475017', 'document_id=26620011&access_key=key-12o5f74765v6qevvm8a3&page=1&viewMode=list');
var vision = 		new Array('doc_734008689961536', 'document_id=27335269&access_key=key-25miz5fsgb66a2onx45q&page=1&viewMode=list');
var zeta = 			new Array('doc_650511555625693', 'document_id=27334891&access_key=key-yjostkgg9qx802jpfhm&page=1&viewMode=list');

function getPDFViewerCode(pdf_ref){
	var pdf_info = eval(pdf_ref);
	if(pdf_info == undefined){ pdf_info = bayofkotor; }
	
	var pdf_viewer_code  = '';
	pdf_viewer_code += '<div id="pdf_viewer">';
	pdf_viewer_code += '	<div class="background">&nbsp;</div>';
	pdf_viewer_code += '	<div class="content">';
	pdf_viewer_code += '		<object id="'+pdf_info[0]+'" name="'+pdf_info[0]+'" width="650" height="500" type="application/x-shockwave-flash" data="http://d1.scribdassets.com/ScribdViewer.swf" style="outline:none;" >';
	pdf_viewer_code += '			<param name="movie" value="http://d1.scribdassets.com/ScribdViewer.swf" />';
	pdf_viewer_code += '			<param name="bgcolor" value="#ffffff" />';
	pdf_viewer_code += '			<param name="allowFullScreen" value="true" />';
	pdf_viewer_code += '			<param name="allowScriptAccess" value="always" />';
	pdf_viewer_code += '			<param name="FlashVars" value="'+pdf_info[1]+'" />';
	pdf_viewer_code += '		</object>';
	pdf_viewer_code += '		<div class="box_close"><span>close</span></div>';
	pdf_viewer_code += '	</div>';
	pdf_viewer_code += '</div>';
	return(pdf_viewer_code);
}

function showPDFViewer(pdf_ref){
	if($("#pdf_viewer")){
		$("#pdf_viewer").remove();
	}
	$("#content").append(getPDFViewerCode(pdf_ref));
	
	$(".box_close").click(function(){
		$("#pdf_viewer").remove();
	});
}*/
