﻿/// <reference path="jquery-1.3.2-vsdoc.js"/> <!-- enables full chained intellisense -->
var pp_gemius_identifier = new String('bVngHY_pG112DFAs3CsFcLQY355KSkc0yvLBSi1XdcT.47');

// openx zones definition
var OA_zones = {
	'ogl728x90': 3,
	'ogl468x60': 1,
	'ogl300x250': 11,
	'ogl300x250Fix': 58,
	'ogl300x600': 7,
	'ogl120x120Pos1': 6,
	'ogl120x120Pos2': 8,
	'ogl120x120Pos3': 9,
	'ogl120x120Pos4': 14,
	'ogl120x120Pos5': 18,
	'ogl120x120Pos6': 23,
	'ogl120x120Pos7': 29,
	'oglTextAdTop': 49,
	'oglLeft120x300': 4,

	'oglCalendar300x600': 57,
	'oglCalendar300x100Pos01': 73,
	'oglCalendar300x100Pos02': 74,
	'oglCalendar300x100Pos03': 75,
	'oglCalendar300x100Pos04': 76,
	'oglCalendar300x100Pos05': 77,
	'oglCalendar300x100Pos06': 78,
	'oglCalendar300x100Pos07': 79,
	'oglCalendar300x100Pos08': 80,
	'oglCalendar300x100Pos09': 81,
	'oglCalendar300x100Pos10': 82,

	'oglFloater': 2,
	'ogl3rdPartyFloater': 12,
	'oglLeftEar': 55,
	'oglRightEar': 53,
	'oglPagePeel': 26
}

function createAddress($recipient, $domain, $element) {
	var $address = $recipient + "@" + $domain;
	var $href = "mailto:" + $address;
	$element.attr("href", $href).html($address).removeClass("hidden");
}

// behaves like an init function from body onload, but in a jQuery style
$(document).ready(function() {
	GAnalytics();
	// cleanup text-ad position if no ad
	if (!$("#oglText").html()) {
		$("#oglText").remove();
	}

	$.preLoadImages("images/layout/bg-featarticle.png", "images/layout/bg-featarticle-hover.png", "images/layout/bg-fp-article-hover.png");

	fixIe7();
	fixOpera();
	fixLayout();

	if ($("#photoCarousel > ul").children().size() > 1) {
		$("#boxPhoto>.contTopRtHead").prepend('<span class="nav"><a href="" id="photoPrev" class="button prev"></a><a href="" id="photoNext" class="button next"></a></span>');
		setupCarousel("#photoCarousel", "#photoPrev", "#photoNext", null);
	}
	if ($("#columnCarousel > ul").children().size() > 1) {
		$("#boxKolumna>.contTopRtHead").prepend('<span class="nav"><a href="" id="columnPrev" class="button prev"></a><a href="" id="columnNext" class="button next"></a></span>');
		setupCarousel("#columnCarousel", "#columnPrev", "#columnNext", null);
	}
	//	$("input:text:first").focus();
	//	hideValidationFields();
	//	signOnOffToggle();
	//	giveawayDataToggle();

	externalLinks();
	popupEmailForm();

	ie6BuzzOff();
});

function GAnalytics() {
	try {
		var pageTracker = _gat._getTracker("UA-267862-1");
		pageTracker._setDomainName(".muzika.hr");
		pageTracker._trackPageview();
	} catch (err) { }
}


function externalLinks() {
	$('a[rel*="external"]').click(function() {
		window.open($(this).attr('href'));
		return false;
	});
}

function popupEmailForm() {
	$("a.emailContact").click(function(e) {
		var newwindow = windowOpener($(this).attr('href'), 600, 680, null);
		if (e.preventDefault) { e.preventDefault(); } else { e.returnValue = false; }
	});
}

function windowOpener(windowUri, windowWidth, windowHeight, windowName) {
	var centerWidth = (window.screen.width - windowWidth) / 2;
	var centerHeight = (window.screen.height - windowHeight) / 2;
	newWindow = window.open(windowUri, windowName
		,'width=' + windowWidth +
        ',height=' + windowHeight +
        ',left=' + centerWidth +
        ',top=' + centerHeight);
	newWindow.focus();
	return newWindow;
}

function fixOpera() {
	if ($.browser.name == "opera") {
		$("#menu").css({ "float": "left" });
	}
}

function fixIe7() {
	if ($.browser.name == "msie" && $.browser.versionNumber < 8) {
		$("#leader>div").css({ "zoom": "1", "display": "inline" });
		$("#header>div").css({ "zoom": "1", "display": "inline" });
		$("#header>#menu>ul").css({ "zoom": "1", "display": "inline" });
		$("#header>#menu>ul>li").css({ "zoom": "1", "display": "inline", "cursor": "default" });
		$("#header>#menu>ul>li>a").css({ "zoom": "1", "display": "inline" });
		$("#contentTop>div").css({ "zoom": "1", "display": "inline", "cursor": "default" });
		$("ul#headingArticles>li").css({ "zoom": "1", "display": "inline", "float": "none" });
		$("ul#headingArticles>li>div").css({ "zoom": "1", "display": "inline"});
		$("ul#headingArticles>li>div:last-child").css({ "width": "190px" });
		$("ul#headingArticles.gallery>li>div:last-child").css({ "width": "156px" });
		$("#intermission1>div").css({ "zoom": "1", "display": "inline" });
		$("#intermission1>div#intermission1Right>a").css({ "zoom": "1", "display": "inline" });
		$("#contentMid>div").css({ "zoom": "1", "display": "inline", "cursor": "default" });
		$("#contentMid a > span").css({ "cursor": "pointer" });
		$("#contentMid>div>ul").css({ "min-height": "372px", "margin-bottom": "10px" /*pulled-up footerbar fix*/  });
		$("#contentMid>div#contentMidLeftMid>ul>li#contentMidLeftMidHeader").css({ "zoom": "1", "display": "inline" });
		$("#contentMid>div#contentMidLeftMid>ul>li#contentMidLeftMidHeader>div").css({ "zoom": "1", "display": "inline" });
		$("#contentMid>div#contentMidLeftMid>ul>li.contentMidLeftMidHeader>div.tlTopInfo").css({ "margin-left": "0px" });
		$("#contentMid>#contentMidLeftMid>ul>li").css({ "zoom": "1", "display": "inline", "margin-bottom": "0px" });
		$("#contentMid>#contentMidLeftMid>ul>li>div").css({ "zoom": "1", "display": "inline" });
		$("#intermission2>div").css({ "zoom": "1", "display": "inline" });
		$("#footer>div>div").css({ "zoom": "1", "display": "inline" });
		$("#adInvokes").remove();
		
		$("#calendarFilters > div#filter hr").css({ "zoom": "1", "display": "inline", "margin": "-3px auto" });
		$("#calendarFilters > div#filter ul:not(:first-child)").css({ "margin-top": "-2px" });
		$("#calendarFilters > div#filter form").css({ "margin": "3px auto" });

		//$("#contentTop>div.contentTopLeftWide>#headingHeader>h1").css({ "display": "inline" });
		$("#contentTop>div.contentTopLeftWide>#headingHeader>h1").css({ "zoom": "1", "display": "inline" });
		$("#contentTop>div.contentTopLeftWide>#headingHeader>div.submenuFilter").css({ "zoom": "1", "display": "inline", "position": "relative", "width": "420px", "margin-top": "-48px" });
		//$("#contentTop>div.contentTopLeftWide>#headingHeader>div.submenuFilter>ul").css({ "zoom": "1", "display": "inline", "width": "400px" });
		$("#contentTop>div.contentTopLeftWide>#headingHeader>div.submenuFilter>ul>li").css({ "zoom": "1", "display": "inline" });
		//#contentTop div.contentTopLeftWide div.submenuFilter

		$("#contentTop>div.contentTopLeftWide>div#articleDisplay>div.infoBox>div ").css({ "zoom": "1", "display": "inline" }); 				// set display block
		$("#albumInfoBox>div").height($("#albumInfoBox").height()); 	// article album info box divs same height

		// test if needed 
		$(".contentTopLeftWide>#headingHeader>h1").css({"display" : "inline"});
		var leftMargin = ($(".contentTopLeftWide>#headingHeader>h1").width() + 20) + "px";
		$(".contentTopLeftWide>#headingHeader>div.submenuFilter").css({ "margin-left" : leftMargin });
	}
}

function ie6BuzzOff() {
	if ($.browser.className == "msie6") {
		$("body").append('<div id="upgradeNotice"></div>');
		$("#upgradeNotice").load("/Pages/upgradeie6.html");
		$("#upgradeNotice").modal({
			minWidth: 640,
			minHeight: 480,
			opacity: 95,
			onOpen: function(dialog) {
				dialog.overlay.fadeIn('fast', function() {
					dialog.container.slideDown('fast', function() {
						$('#upgradeNotice').removeClass("hidden");
						dialog.data.show();
					});
				});
			},
			onShow: function(dialog) {
				//$("#simplemodal-container a.modalCloseImg").css({ "display": "none", "visibility": "hidden" });
				$("#simplemodal-container").css({ "width": "640px", "height": "480px" });
				$("*").css({"overflow-x": "hidden"});
			},
			onClose: function(dialog) {
				$("#upgradeNotice").addClass("hidden");
				dialog.data.fadeOut('fast', function() {
					dialog.container.slideUp('fast', function() {
						dialog.overlay.fadeOut('fast', function() {
							$.modal.close(); // must call this!
						});
					});
				});
			}
		});
	}
}


function fixTopLayout() {
	$(".contentTopLeft").height("auto");
	//$(".contentTopMid").height("auto");	// if enabled, front page breathes up-down! don't want that
	var topHeight = Math.max($(".contentTopLeft").height(), $(".contentTopMid").height());
	$(".contentTopLeft").height(topHeight);
	$(".contentTopMid").height(topHeight);
}

function fixMidLayout() {
	var maxBoxHeight = Math.max(Math.max(Math.max($("#contentMidLeft").height(), $("#contentMidLeftMid").height()), $("#contentMidRightMid").height()), $("#contentMidRight").height());
	$("#contentMid>div").height(maxBoxHeight);
	$("#contentMid>div>ul").height(maxBoxHeight - 66); /* - title (30) - footer (26) - ul/li top margin (10) */
}

function fixLayout() {
	// --- menu
	if ($.os.name == "win") {
		$("#menu ul li:not(.featured) a").css({ "padding-right": "30px" });
	}
	// --- front-page
	fixTopLayout();		// top boxes
	fixMidLayout(); // bottom boxes

	// --- article
	//$("#albumInfoBox>div").height($("#albumInfoBox").height());		// article album info box divs same height
	var $imgCaption = $("p.articleImgCaption"); 						// caption overlay
	$imgCaption.each(function() {
		$(this).width($(this).prev().children("img").width() - 20);		// ...
	});

}

function initFpFeatArticles() {
	$(".contentTopLeft > .articlesSlider:not(:first)").hide();
	$(".contentTopLeft > .articlesSlider:not(:first)").removeClass("hidden");
}

function switchFpFeatArticles(clickedObj, clickedElId, exposedHeadingId) {
	if ($(clickedObj).hasClass("selected")) {
		$("#fpa" + clickedElId).removeClass("selected");
		$("#fp" + clickedElId).hide(); 		// hide filtered shown
		$("#fp" + exposedHeadingId).show(); 	// show nonfiltered
		fixTopLayout();
	}
	else {
		$(".contentTopLeft > .submenuFilter a[class*='selected']").removeClass("selected");
		$("#fpa" + clickedElId).addClass("selected");
		$(".contentTopLeft > .articlesSlider:visible").hide(); // hide shown
		$("#fp" + clickedElId).show(); 						// show selected
		fixTopLayout();
	}
}

function initReviewsBoxes() {
	// add nav
	$("#contentMidLeft > .contMidHead > span.nav").html('<a class="button prev"></a><a class="button next"></a>');
	// calculate the most high ul
	$("#contentMidLeft > ul").height("auto");
	$maxUlHeight = 0;
	for (i = 0; i < $("#contentMidLeft > ul").length; i++) {
		$maxUlHeight = Math.max($maxUlHeight, $("#contentMidLeft > ul:eq(" + (i) + ")").height());
	}
	$("#contentMidLeft").height($maxUlHeight + 56); /* 56 = title (30) + footer (26) */
	$("#contentMidLeft > ul:not(:first)").hide();
	$("#contentMidLeft > ul:not(:first)").removeClass("hidden");
	fixMidLayout();

	var upSlideTime = 290;
	var downSlideTime = 470;
	var $midLeftBoxPages = new Array("#reviewBoxAlbums", "#reviewBoxBooks", "#reviewBoxMovies");
	var $lastShownMidLeftBoxIdx = $.cookie('midLeftBox'); 				// read cookie and set last selected menu filter
	if ($lastShownMidLeftBoxIdx == null) var $lastShownMidLeftBoxIdx = 0; // initial value
	$("#contentMidLeft > ul:first").hide();
	$("#contentMidLeft > " + $midLeftBoxPages[$lastShownMidLeftBoxIdx]).show();
	$("#contentMidLeft > .contMidHead > h2").html($($midLeftBoxPages[$lastShownMidLeftBoxIdx]).children("li:first").children("input").val());
	$("#contentMid #contentMidLeft ul").css({ "min-height": "0px" }); // enables sliding up to the zero-height
	$("#contentMidLeft > .contMidHead > span.nav > a.prev").click(function(e) {
		e.preventDefault();
		$midLeftBoxIdxToShow = ($lastShownMidLeftBoxIdx + $midLeftBoxPages.length - 1) % $midLeftBoxPages.length;
		$.cookie('midLeftBox', $midLeftBoxIdxToShow, { path: '/' }); // set cookie
		$("#contentMidLeft > " + $midLeftBoxPages[$lastShownMidLeftBoxIdx]).slideUp(upSlideTime, function() {
			$("#contentMidLeft > .contMidHead > h2").html($($midLeftBoxPages[$midLeftBoxIdxToShow]).children("li:first").children("input").val());
			$("#contentMidLeft > " + $midLeftBoxPages[$midLeftBoxIdxToShow]).slideDown(downSlideTime);
		});
		$lastShownMidLeftBoxIdx = $midLeftBoxIdxToShow;
	});
	$("#contentMidLeft > .contMidHead > span.nav > a.next").click(function(e) {
		e.preventDefault();
		$midLeftBoxIdxToShow = ($lastShownMidLeftBoxIdx + 1) % $midLeftBoxPages.length;
		$.cookie('midLeftBox', $midLeftBoxIdxToShow, { path: '/' }); // set cookie
		$("#contentMidLeft > " + $midLeftBoxPages[$lastShownMidLeftBoxIdx]).slideUp(upSlideTime, function() {
			$("#contentMidLeft > .contMidHead > h2").html($($midLeftBoxPages[$midLeftBoxIdxToShow]).children("li:first").children("input").val());
			$("#contentMidLeft > " + $midLeftBoxPages[$midLeftBoxIdxToShow]).slideDown(downSlideTime);
		});
		$lastShownMidLeftBoxIdx = $midLeftBoxIdxToShow;
	});
}

function initChartsBoxes() {
	if ($("#contentMidLeftMid > ul").length <= 1) {
		if ($("#contentMidLeftMid > ul").length == 1) {
			$("#contentMidLeftMid > .contMidHead > h2").html($("#contentMidLeftMid > ul > li:first-child > div > li:first > input").val());
		}
		return; // don't put sliders when nothing to slide
	}
	// add nav
	$("#contentMidLeftMid > .contMidHead > span.nav").html('<a class="button prev"></a><a class="button next"></a>');
	// calculate the most high ul
	$("#contentMidLeftMid > ul").height("auto"); // clear css height
	var $maxUlHeight = 0;
	for (i = 0; i < $("#contentMidLeftMid > ul").length; i++) {
		$maxUlHeight = Math.max($maxUlHeight, $("#contentMidLeftMid > ul:eq(" + (i) + ")").height());
	}
	$("#contentMidLeftMid").height($maxUlHeight + 56); /* 56 = title (30) + footer (26) */
	$("#contentMidLeftMid > ul:not(:first)").hide();
	$("#contentMidLeftMid > ul:not(:first)").removeClass("hidden");
	fixMidLayout();

	var upSlideTime = 290;
	var downSlideTime = 470;
	var $boxPages = $("#contentMidLeftMid > ul");
	var $lastShownBoxIdx = 0; 				// read cookie and set last selected menu filter
	$("#contentMidLeftMid > .contMidHead > h2").html($($boxPages[$lastShownBoxIdx]).children("li:first").children("input").val());
	$("#contentMid #contentMidLeftMid ul").css({ "min-height": "0px" });	// enables sliding up to the zero-height
	$("#contentMidLeftMid > .contMidHead > span.nav > a.prev").click(function(e) {
		e.preventDefault();
		$boxIdxToShow = ($lastShownBoxIdx + $boxPages.length - 1) % $boxPages.length;
		$($boxPages[$lastShownBoxIdx]).slideUp(upSlideTime, function() {
			$("#contentMidLeftMid > .contMidHead > h2").html($($boxPages[$boxIdxToShow]).children("li:first").children("input").val());
			$($boxPages[$boxIdxToShow]).slideDown(downSlideTime);
		});
		$lastShownBoxIdx = $boxIdxToShow;
	});
	$("#contentMidLeftMid > .contMidHead > span.nav > a.next").click(function(e) {
		e.preventDefault();
		$boxIdxToShow = ($lastShownBoxIdx + 1) % $boxPages.length;
		$($boxPages[$lastShownBoxIdx]).slideUp(upSlideTime, function() {
			$("#contentMidLeftMid > .contMidHead > h2").html($($boxPages[$boxIdxToShow]).children("li:first").children("input").val());
			$($boxPages[$boxIdxToShow]).slideDown(downSlideTime);
		});
		$lastShownBoxIdx = $boxIdxToShow;
	});
}

function initCalendarFilter() {
	$(document).ready(function() {
		var upSlideTime = 110;
		var downSlideTime = 178;
		var $filterPages = new Array("#filterMenuDefault", "#filterMenuRegions", "#filterMenuCities");

		$("#filterMenuDefault").hide();
		$("#filterMenuRegions").hide();
		$("#filterMenuCities").hide();

		var $lastShownFilterIdx = 0; // initial value
		if ($("#filterMenuRegions a.selected").length) {
			$lastShownFilterIdx = 1;
		}
		else if ($("#filterMenuCities a.selected").length) {
			$lastShownFilterIdx = 2;
		}
		$($filterPages[$lastShownFilterIdx]).show();

		$("#calendarFilters > #filter a.showRegions").click(function(e) {
			e.preventDefault();
			$filterIdxToShow = 1;
			$("#calendarFilters > #filter > " + $filterPages[$lastShownFilterIdx]).slideUp(upSlideTime, function() {
				$("#calendarFilters > #filter > " + $filterPages[$filterIdxToShow]).slideDown(downSlideTime);
			});
			$lastShownFilterIdx = $filterIdxToShow;
		});
		$("#calendarFilters > #filter a.showCities").click(function(e) {
			e.preventDefault();
			$filterIdxToShow = 2;
			$("#calendarFilters > #filter > " + $filterPages[$lastShownFilterIdx]).slideUp(upSlideTime, function() {
				$("#calendarFilters > #filter > " + $filterPages[$filterIdxToShow]).slideDown(downSlideTime);
			});
			$lastShownFilterIdx = $filterIdxToShow;
		});
		$("#calendarFilters > #filter a.showMain").click(function(e) {
			e.preventDefault();
			$filterIdxToShow = 0;
			$("#calendarFilters > #filter > " + $filterPages[$lastShownFilterIdx]).slideUp(upSlideTime, function() {
				$("#calendarFilters > #filter > " + $filterPages[$filterIdxToShow]).slideDown(downSlideTime);
			});
			$lastShownFilterIdx = $filterIdxToShow;
		});
	});
}

function initCalendarFeatured() {
	var upSlideTime = 220;
	var downSlideTime = 356;
	$(document).ready(function() {
		$("#calendarFilters > #featEvent > ul > li").hide();
		$("#calendarFilters > #featEvent > ul > li:first").show();
		$("#calendarFilters > #featEvent > span.nav > a.prev").click(function(e) {
			e.preventDefault();
			$elToShow = $("#calendarFilters > #featEvent > ul > li:first").is(":visible") ? $("#calendarFilters > #featEvent > ul > li:last") : $("#calendarFilters > #featEvent > ul > li:visible").prev();
			$("#calendarFilters > #featEvent > ul > li:visible").slideUp(upSlideTime, function() {
				$elToShow.slideDown(downSlideTime);
			});
		});
		$("#calendarFilters > #featEvent > span.nav > a.next").click(function(e) {
			e.preventDefault();
			$elToShow = $("#calendarFilters > #featEvent > ul > li:last").is(":visible") ? $("#calendarFilters > #featEvent > ul > li:first") : $("#calendarFilters > #featEvent > ul > li:visible").next();
			$("#calendarFilters > #featEvent > ul > li:visible").slideUp(upSlideTime, function() {
				$elToShow.slideDown(downSlideTime);
			});
		});
	});
}

function initArticleAlbumInfoBox() {
	$(document).ready(function() {
		$("#albumInfoBox > div#trackList > .tabNav > img.btnPrev").click(function() {
			if ($("#albumInfoBox > div#trackList > .tabbedContent > li:visible").attr("id") != $("#albumInfoBox > div#trackList > .tabbedContent > li:first").attr("id")) {
				var $oldHeight = $("#albumInfoBox > div#trackList > .tabbedContent > li:visible").height();
				var $divToShow = $("#albumInfoBox > div#trackList > .tabbedContent > li:visible").prev();
				$("#albumInfoBox > div#trackList > .tabbedContent > li").hide();
				$($divToShow).fadeIn("fast");
				var $newHeight = $("#albumInfoBox > div#trackList > .tabbedContent > li:visible").height();
				var $maxBoxHeight = Math.max($oldHeight, $newHeight);
				$("#albumInfoBox > div#trackList > .tabbedContent > li:visible").height($maxBoxHeight);
			}
			return false;
		});
		$("#albumInfoBox > div#trackList > .tabNav > img.btnNext").click(function() {
			if ($("#albumInfoBox > div#trackList > .tabbedContent > li:visible").attr("id") != $("#albumInfoBox > div#trackList > .tabbedContent > li:last").attr("id")) {
				var $oldHeight = $("#albumInfoBox > div#trackList > .tabbedContent > li:visible").height();
				var $divToShow = $("#albumInfoBox > div#trackList > .tabbedContent > li:visible").next();
				$("#albumInfoBox > div#trackList > .tabbedContent > li").hide();
				$($divToShow).fadeIn("fast");
				var $maxBoxHeight = Math.max($("#albumInfo").height(), $("#trackList").height());
				$("#albumInfo").height($maxBoxHeight);
				$("#trackList").height($maxBoxHeight);
				var $newHeight = $("#albumInfoBox > div#trackList > .tabbedContent > li:visible").height();
				var $maxBoxHeight = Math.max($oldHeight, $newHeight);
				$("#albumInfoBox > div#trackList > .tabbedContent > li:visible").height($maxBoxHeight);
			}
			return false;
		});

		$("#trackList > .tabNav").removeClass("hidden");

		$("div#trackList > .tabbedContent > li").hide();
		$("div#trackList > .tabbedContent > li:first").show();
	});
}

function initArticleEventsInfoBox() {
	$(document).ready(function() {
		var $lastShown;

		// inject pull-up a with image
		$("#eventInfoBoxMaster > p > span.nav").html('<a class="button up"></a>');
		$("#eventInfoBoxMaster > p > span.nav > a").click(function() {
			if ($lastShown) {
				$($lastShown).slideUp("fast");
				$lastShown = null;
			}
		});

		$("#articleDisplay > #infoBoxContainer > #eventInfoBoxMaster a").click(function() {
			var $divToShow = "#" + $(this).attr("rel");
			//$("#articleDisplay > .tabbedContent > div:not(" + $lastShown + ")").slideUp("fast", function() {
			if ($lastShown) {
				$($lastShown).slideUp("fast", function() {
					$($divToShow).slideDown("fast");
				});
			}
			else { $($divToShow).slideDown("fast"); }
			$lastShown = $divToShow;
			return false;
		});

		$("#articleDisplay > #infoBoxContainer > #eventInfoBoxMaster").hide();
		$("#articleDisplay > #infoBoxContainer > #eventInfoBoxMaster").removeClass("hidden");
		$("#articleDisplay > #infoBoxContainer > #eventInfoBoxMaster").show();

		$("#articleDisplay > #infoBoxContainer > .tabbedContent > div").hide();
	});
}

function initSocial(baseAppPath) {
		$(document).ready(function() {
		$("#social").load(baseAppPath + "Views/include/AddThis.html");
		$.getScript("http://s7.addthis.com/js/250/addthis_widget.js?pub=muzikahr");
		$("#social").removeClass("hidden");
		});
		}

function setupCarousel(carouselElementId, carouselBtnPrevId, carouselBtnNextId, autoTimingMillis) {
	$(function() {
		$(carouselElementId).jCarouselLite({
			btnNext: carouselBtnNextId,
			btnPrev: carouselBtnPrevId,
			visible: 1,
			circular: true,
			auto: autoTimingMillis
		});
	});
}

function CreateBookmark() {
	title = "Muzika.hr";
	url = "http://www.muzika.hr";
	if (window.sidebar) {
		window.sidebar.addPanel(title, url, ""); // Mozilla Firefox Bookmark
	}
	else if (window.external) {
		window.external.AddFavorite(url, title); // IE Favorite		
	}
	else if (window.opera && window.print) {
		return true; // Opera Hotlist
	}
}

function nitelifeContactPopupLoad() {
	$("#contactPopup").load("/include/nitelifeContact.html");
}

function eventLocationDisplayInit(programCallText, mapToggleText) {
	$(document).ready(function() {
		// ### call for program init
		$('<div id="contactPopup" class="hidden"></div>').appendTo("body");
		$('<p id="programCall">' + programCallText + '<a href="#" class="popup" id="callForProgram"></a></div>').appendTo("#scheduleContainer");
		$("#callForProgram").click(function(e) {
			e.preventDefault();
			nitelifeContactPopupLoad();
			$('#contactPopup').modal({
				closeHTML: '<a class="modalCloseImg" title="Zatvori"></a>',
				onOpen: function(dialog) {
					dialog.overlay.fadeIn('fast', function() {
						dialog.container.slideDown('fast', function() {
							$('#contactPopup').removeClass("hidden");
							dialog.data.show();
						});
					});
				},
				onClose: function(dialog) {
					$('#contactPopup').addClass("hidden");
					dialog.data.fadeOut('fast', function() {
						dialog.container.slideUp('fast', function() {
							dialog.overlay.fadeOut('fast', function() {
								$.modal.close(); // must call this!
							});
						});
					});
				}
			});
		});
		// ### Map & Schedule Navigation Init
		// init google maps
		GoogleMapsDisplayInit();
		// read data state
		var mapExists = ($("#mapExists").val().toLowerCase() === 'true');
		var scheduleExists = ($("#scheduleExists").val().toLowerCase() === 'true');
		if (mapExists && scheduleExists) {
			$("#mapContainer").hide();
			// inject js controls
			$('<p id="mapToggle">' + mapToggleText + '<a href="#" id="displayMap"></a><a href="#" id="hideMap"></a></p>').appendTo("#eventLocationDisplay #map");
			// attach event handlers
			$("#displayMap").click(function(e) {
				e.preventDefault();
				$("#mapContainer").slideDown("fast", function() {
					$("#displayMap").hide();
					$("#hideMap").show();
					if (map == null) {
						initMapDisplay();
					}
					var divMapCss = { 'width': '620px', 'margin-left': '-160px' }
					$("#eventLocationDisplay > #map").css(divMapCss);
					var mapCanvasCss = { 'margin-left': '0px' }
					$("#map_canvas").css(mapCanvasCss);
				});
			});
			$("#hideMap").click(function(e) {
				e.preventDefault();
				$("#mapContainer").slideUp("fast");
				var divMapCss = { 'width': '460px', 'margin-left': '0px' }
				$("#eventLocationDisplay > #map").css(divMapCss);
				var mapCanvasCss = { 'margin-left': '-160px' }
				$("#map_canvas").css(mapCanvasCss);
				$("#hideMap").hide();
				$("#displayMap").show();
			});
			// activate initial display
			$("#hideMap").click();
		}
		else if (mapExists) {
			initMapDisplay();
		}
	});
}



/************** GOOGLE MAPS *******************/
var map = null;
var geocoder = null;
var marker = null;

function GoogleMapsDisplayInit() {
	$(window).unload(function() {
		GUnload();
	});


	$(document).ready(function() {

		if (GBrowserIsCompatible()) {
		}

	});
}

function pinLatLng(latlng) {
	map.clearOverlays();
	marker = new GMarker(latlng);
	map.addOverlay(marker);
}

function initMapDisplay() {
	if (GBrowserIsCompatible()) {
		var lat = $("#gLat").val();
		var lng = $("#gLng").val();
		if (lat == undefined || lng == undefined || lat == '' || lng == '') {
			return;
		}

		var defaultZoomLevel = 13;

		$("#map_canvas").removeClass("hidden");
		var mapCanvasCss = { 'height': '480px', 'width': '618px', 'margin-left': '-160px', 'border': '1px solid #e5e5e5' }
		$("#map_canvas").css(mapCanvasCss);

		map = new GMap2($("#map_canvas")[0]);

		//map.addControl(new GLargeMapControl());
		map.addControl(new GLargeMapControl3D());
		//map.addControl(new GSmallMapControl());
		//map.addControl(new GSmallZoomControl3D());
		map.addControl(new GMapTypeControl());
		map.addControl(new GScaleControl());
		map.enableScrollWheelZoom();
		map.disableDoubleClickZoom();
		map.setMapType(G_HYBRID_MAP);

		if (geocoder == null) {
			geocoder = new GClientGeocoder();
		}

		if (geocoder) {
			var lat = $("#gLat").val();
			var lng = $("#gLng").val();
			if (!(lat == undefined || lng == undefined || lat == '' || lng == '')) {
				var point = new GLatLng(lat, lng);
				map.setCenter(point, defaultZoomLevel);
				pinLatLng(point);
			}
		}
	}
}

/************** END :: GOOGLE MAPS *******************/
