﻿/// <reference path="../includes/jquery/jquery-1.7.1.min.js" />
/// <reference path="../includes/jquery/fancybox/jquery.fancybox-1.3.1.js" />

$(document).ready(function () {
	//reframe("<%=mySett.my_site_root %>");
	$("a[rel^='prettyPhoto']").prettyPhoto();
	$("a").each(function () { if (this.href.indexOf("youtube.com") != -1) { $(this).prettyPhoto(); }; });
	$("a[rel^='gallery']").fancybox();
	$('#mainImage').cycle({
		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		timeout: 10000,
		before: onBefore,
		after: onAfter
	});
	$("input[id*='currentCat']").each(function () {
		if ($(this).val() != "" && $(this).val() != "0") {
			var parent = $("#pointer_" + $(this).val()).parent().parent().get();
			if ($(parent).attr("ID").toString() != "genMainBox") { // siamo a livello 0
				var ok = false;
				while (!ok) {
					if ($(parent).parent().parent().attr("ID").toString().indexOf("pointer_") != -1) {
						parent = $(parent).parent().parent().get();
					}
					else {
						ok = true;
					}
				}
				$heading = $(parent);            // create a reference to visible sibling elements so we don't have to keep creating a jQuery object           
				$expandedSiblings = $heading.siblings().find('ul:visible');
				if ($expandedSiblings.size() > 0) { $expandedSiblings.slideUp(500, function () { $heading.find('ul').slideDown(500); }); } else { $heading.find('ul').slideDown(1000); }
			}
		}
	});
	$("#genMainBox").css("display", "inline");
});


function startGallery(imgObj) {
	if ($(imgObj).attr("ID") == "img_0" || $(imgObj).attr("ID") == "img_1") {
		window.setTimeout(function () {
			$("a[rel^='gallery']").fancybox().trigger('click');
		}, 500);
	}
}

function onBefore() {
	//$("#callout").css("z-index", "0");
}

function onAfter() {
	if (this.alt != "") {
		$("#callout").css("position", "absolute");
		$("#callout").css("diplay", "inline");
		$("#calloutTitle").html(this.title);
		$("#calloutText").html(this.alt);
		$("#callout").css("z-index", "10000");
	}
	else {
		$("#callout").css("z-index", "0");
	}
}

$(function () {
	$('#nav>li>ul').hide(); $('#nav>li').click(function () {
		if ($('#nav ul:animated').size() == 0) {            // create a reference to the active element (this) so we don't have to keep creating a jQuery object           
			$heading = $(this);            // create a reference to visible sibling elements so we don't have to keep creating a jQuery object           
			$expandedSiblings = $heading.siblings().find('ul:visible');
			if ($expandedSiblings.size() > 0) { $expandedSiblings.slideUp(500, function () { $heading.find('ul').slideDown(500); }); } else { $heading.find('ul').slideDown(1000); }
		}
	});
});
