hennessysStart();

function hennessysStart(){
	//if (window.console && console.log) console.log("loaded hennessys script");
	
	
}

function hen_selectNewLanguage(){
	hen_setLanguage($(this).val());
}

function hen_switchLanguage(){
	if (document.hen_currentlang == "en") {
	    hen_setLanguage("pt");
	}
	else{
		hen_setLanguage("en");
	}
}

function hen_setLanguage(languageString){
	$.cookie("hen_language", languageString, {path: "/", expires: 10});	
	$(".lang_" + document.hen_currentlang).hide(0, function(){
		$(".lang_" + languageString).show();
	});
	document.hen_currentlang = languageString;
}

$(document).ready(
	function(){
	
		var currentURL = window.location.href;
		$(".menuItem a").each(function(){
			if (this.href == currentURL){
				var parentNode = $(this).parent().removeClass("menuItem").addClass("menuItemSelected");
				$(this).contents().unwrap();
			}
		});
		
		
		// show only desired language
		document.hen_currentlang = $.cookie("hen_language") || "en";
		switch (document.hen_currentlang) {
		
			case "pt":
		    	$(".lang_en").hide();
		    	break;
		
			default:
		    	$(".lang_pt").hide();
		    	break;
		
		}

	
		
/* 
		//add highlights to menuItems:
		$(".menuItem").hover(
			function(){
				$(this).addClass('menuItemHL');
			},
			function(){
				$(this).removeClass('menuItemHL');
			}
		);
*/
		
	}
);

function hen_createContentFromCalendarEvents(resp, param2, targetSelector) {
	// if (window.console && console.log) console.log("resp is:");
	// if (window.console && console.log) console.log(resp);
	if (resp && resp["items"]){
		 
		$("#calendarEventLoader").hide();
		
		if (!targetSelector){targetSelector = "#story > div:first";}
		 
		var item, fname, iconLink, icon;
		var eventDate, comments;
		for (var i = 0; i < resp.items.length; i++) {
			// if (window.console && console.log) console.log(resp.items[i]);
		
			item = resp.items[i];
			eventDate = new Date(item.start.dateTime);
			comments = item.description || "";
			icon = "";
			
			if(item["gadget"]){
				iconLink = item["gadget"]["iconLink"];
				if(iconLink){
					fname = iconLink.substring(iconLink.lastIndexOf('/') + 1, iconLink.length);
					for (var ii = 0; ii < document.supportedIcons.length; ii++) {
						if (document.supportedIcons[ii] == fname){
							icon = fname;
							break;
						}
						ii++;
					}
				}
			}
			
			if (!icon.length){
				iconLink = comments.match(/^\w+/);
				if(iconLink){iconLink = iconLink.toString().toLowerCase();}
				
				for (var ii = 0; ii < document.supportedIcons.length; ii++) {
					if (document.supportedIcons[ii+1] == iconLink){
						icon = document.supportedIcons[ii];
						break;
					}
					ii++;
				}
				
				if (!icon.length){icon = document.supportedIcons[0];}
			}
			
			comments = comments.replace(/\n/g,"<br />");
			$newDiv = $("<div/>", {class:"eventBox"});
			$newDiv.append($("<div class=\"sportsIcon\"><img alt=\"\" src=\"imgs/kalenderIcons/" + icon + "\"></div>"));
			$newDiv.append($("<div class=\"caption\">" + item.summary + "</div>"));
			$newDiv.append($("<div class=\"text\">" + eventDate.toLocaleString() + "<br />" + comments + "</div>"));
			$(targetSelector).append($newDiv);
		}
		
		var hasImages = false;
		$(".eventBox div.text img").each(function(){
			$(this).wrap("<a href=\"" + $(this).attr("src") + "\" rel=\"prettyPhoto[gallery1]\" title=\"" + $(this).parent().prev().text() + "\" />");
			hasImages = true;
		});
		
		if (hasImages) {$("a[rel^='prettyPhoto']").prettyPhoto();}
	}
	else{
		$("#calendarEventLoader img").hide();
		$("#calendarEventLoader span").text("Currently there is nothing scheduled");
	}
}


