$(function () {
	
	/*	Practical Info - content shown on click
	*/	
	/*	Function
	*/
	var onClick = function () {
		if ($(this).parent().parent().hasClass ("open")) {
			$(this).parent().parent().removeClass ("open");
		}
		else {
			$(this).parent().parent().addClass ("open");
		}
	}
	
	/*	Click event
	*/
	$("ul.pi1 li h5 a").bind ("click", onClick);
	
	/*	Friends list - hover
	*/	
	/*	Function
	*/
	var onFriend = function () {
		$(this).addClass("open");
	}
	
	var offFriend = function () {
		$(this).removeClass("open");
	}
	
	/*	Hover event
	*/
	$("ul.fr1 li").hover (onFriend, offFriend);
	
	
	if(window.parent) {
	// adresiranje
		if (window.location.href != window.top.location.href.replace("#","")) {
			lok=window.location.href.replace("http://www.thegardenfestival.eu/","/");
			if(/Safari/.test(navigator.userAgent)){}
			else{window.top.location.hash=lok;}
		}
	}
	
	// audio-video
	if(window.top.radio) {
		// stop player
		if (window.location.href=="http://www.thegardenfestival.eu/en/festival-vibe/photos-video-music/") {
			var flashMovie=getFlashMovieObject("mplayer");
			flashMovie.SetVariable("/:izvana", "1");
		}
		else {
			var flashMovie=getFlashMovieObject("mplayer");
			flashMovie.SetVariable("/:izvana", "2");
		}
	}
	
	/*	Tickets - more info pop-up
	*/
	/*	Function
	*/
	
	var onClickTicket = function () {		
		//position
		var position = $(this).parent().position();
		var left = position.left + 130;
		//var top = position.top + 203;
		if ($(".col2-3:first").outerHeight(true) >= $(".col3-1-3:first").outerHeight(true)) { var offset = $(".col2-3:first").outerHeight(true); }
		else var offset = $(".col3-1-3:first").outerHeight(true);
		var top = position.top + offset + 92;
		var $pop_current = $t_current = $(this).parent();
		
		//check if shown
		if (!$("div.mipop").hasClass("shown")) {
			var t_heading = $t_current.children("h5.mi").html();
			var t_content = $t_current.children("div.mi").html();
			$("div.mipop h5").html (t_heading);
			$("div.mipop div").html (t_content);
			//vertical center
			$("div.mipop").addClass("shown");
			var height = $("div.mipop").outerHeight();
			if (height < 70) { 
				$("div.mipop div").css ({height: "60px"}); 
				var height = $("div.mipop").outerHeight();
			}
			var center = height / 2;
			$("div.mipop img.arrow").css ({top: center + "px"});
			$("div.mipop").css ({left: left + "px", top: top + "px", marginTop: -center + "px", marginBottom: -height + "px"});
			$(this)
				.addClass("clicked")
				.text("Close box");
				//.attr("title", $(".col2-3:first").height());
		}
		else {
			if ($(this).hasClass("clicked")) {
				$("div.mipop")
					.removeClass("shown")
					.css ({top: "-9999px"});
				$("a.clicked")
					.removeClass("clicked")
					.text("More info");
				$("div.mipop h5").html ("");
				$("div.mipop div").html ("");
			}
			else {
				$("a.clicked")
					.removeClass("clicked")
					.text("More info");
				$(this)
					.addClass ("clicked")
					.text("Close box");
				var t_heading = $t_current.children("h5.mi").html();
				var t_content = $t_current.children("div.mi").html();
				$("div.mipop h5").html (t_heading);
				$("div.mipop div").html (t_content);
				//vertical center
				var height = $("div.mipop").outerHeight();
				if (height < 70) { 
					$("div.mipop div").css ({height: "60px"}); 
					var height = $("div.mipop").outerHeight();
				}
				var center = height / 2;
				$("div.mipop img.arrow").css ({top: center + "px"});
				$("div.mipop").css ({left: left + "px", top: top + "px", marginTop: "-" + center + "px", marginBottom: -height + "px"});
			}
		}
	}
	
	$("ol#tickets2 li a.mi").bind ("click", onClickTicket);
	
});
// flash music player
function getFlashMovieObject(movieName) {
if(window.top.radio) {
  if (window.top.radio.document[movieName]) {
      return window.top.radio.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1) {
    if (window.top.radio.document.embeds && window.top.radio.document.embeds[movieName])
      return window.top.radio.document.embeds[movieName]; 
  }
  else {
    return window.top.radio.document.getElementById(movieName);
  }
}
}