﻿var carouselActiveRelease = 0;
var cf = null;
var dtr_start = 0;
var dtr_end = 0;
var isIE6 = /msie|MSIE 6/.test(navigator.userAgent);
var isIE7 = /msie|MSIE 7/.test(navigator.userAgent);
var addToCartInProgress = false;
var objPPFlowPlayer = null;
var boolLoadFlowPlayerNow = false;

global_docready = function () {
	$(".EktronEditorsMenuMarker").remove();
	if (isIE6) {
		$("#leftNav li").mouseover(function () {
			$(this).addClass("over");
		}).mouseout(function () {
			$(this).removeClass("over");
		});
	}
	$(".external").bind("click", function () {
		window.open($(this).attr("href"));
		return false;
	});
	if ($("#cartCntnr")[0]) {
		$("#cartCntnr").dialog({
			modal: true,
			dialogClass: "cartDialogJQ",
			draggable: false,
			resizable: false,
			autoOpen: false,
			width: 600
		});
		$("#cartContinueShoppingBtn").click(function () { $("#cartCntnr").dialog("close"); });
		$("#cartViewCartBtn").click(function () { location.href = "/Cart/"; });
	}
}

login_docready = function () {
	$("#needHelpDialog").dialog({
		autoOpen: false,
		modal: true,
		draggable: false,
		resizable: false,
		dialogClass: "needHelpDialogJQ"
	});
	$(".AspNet-Login-HelpPanel a").bind("click", function () {
		$("#needHelpDialog").dialog("open");
	});
}

login_supersleight = function () {
	$("#loginBGCntnr, #prevButton, #nextButton").supersleight();
}

pwdchange_validate = function (source, arguments) {
	var overallValid = true;
	overallValid = customrequiredfieldvalidator_validate(".txtUserName:first") && overallValid;
	overallValid = customrequiredfieldvalidator_validate(".txtCurPassword:first") && overallValid;
	overallValid = customrequiredfieldvalidator_validate(".txtPassword:first") && overallValid;
	overallValid = customrequiredfieldvalidator_validate(".txtConfirmPassword:first") && overallValid;
	arguments.IsValid = overallValid;
}

pwdreset_username_validate = function (source, arguments) {
	arguments.IsValid = customrequiredfieldvalidator_validate(".txtUserName:first");
}

register_validate = function (source, arguments) {
	var errors = new Array();
	var overallValid = true;
	overallValid = customrequiredfieldvalidator_validate(".txtFirstName:first") && overallValid;
	overallValid = customrequiredfieldvalidator_validate(".txtLastName:first") && overallValid;
	overallValid = customrequiredfieldvalidator_validate(".txtEmailAddress:first") && overallValid;
	overallValid = customrequiredfieldvalidator_validate(".txtTES:first") && overallValid;
	overallValid = customrequiredfieldvalidator_validate(".txtCircuitName:first") && overallValid;
	overallValid = customrequiredfieldvalidator_validate(".txtTheatreAddress:first") && overallValid;
	overallValid = customrequiredfieldvalidator_validate(".txtCity:first") && overallValid;
	overallValid = customrequiredfieldvalidator_validateddl(".ddlStateProvince:first") && overallValid;
	overallValid = customrequiredfieldvalidator_validate(".txtPostalCode:first") && overallValid;
	overallValid = customrequiredfieldvalidator_validateddl(".ddlCountry:first") && overallValid;
	overallValid = customrequiredfieldvalidator_validate(".txtTheatrePhone:first") && overallValid;
	overallValid = customrequiredfieldvalidator_validate(".txtTheatreFax:first") && overallValid;

	var valid = true;
	if (!$(".chkAcceptTerms:first input:first").is(":checked")) {
		valid = false;
		$("#acceptTermsCntnr").addClass("error");
	}
	else {
		valid = true;
		$("#acceptTermsCntnr").removeClass("error");
	}
	overallValid = valid && overallValid;

	// Validate email address
	var emailre = /^\w[-._\w]*\w@\w[-._\w]*\w\.\w{2,3}$/;
	var email = $.trim($(".txtEmailAddress:first").val());
	if (!email.match(emailre)) {
		errors.push("Invalid email address.");
		valid = false;
		$(".txtEmailAddress:first").addClass("error");
	}
	else {
		valid = true;
		$(".txtEmailAddress:first").removeClass("error");
	}
	overallValid = valid && overallValid;

	arguments.IsValid = overallValid;
	$("#registerMessage").html(errors.join("<br />"));
}

updateprofile_validate = function (source, arguments) {
	var errors = new Array();
	var overallValid = true;
	overallValid = customrequiredfieldvalidator_validate(".txtUserID:first") && overallValid;
	overallValid = customrequiredfieldvalidator_validate(".txtFirstName:first") && overallValid;
	overallValid = customrequiredfieldvalidator_validate(".txtLastName:first") && overallValid;
	overallValid = customrequiredfieldvalidator_validate(".txtEmailAddress:first") && overallValid;
	overallValid = customrequiredfieldvalidator_validate(".txtTheatreFax:first") && overallValid;
	
	// Make sure passwords match
	var pwdcheck = ($.trim($(".txtPassword:first").val()) == $.trim($(".txtConfirmPassword:first").val()));
	if (!pwdcheck) {
		$(".txtPassword:first").addClass("error");
		$(".txtConfirmPassword:first").addClass("error");
	}

	overallValid = pwdcheck && overallValid;

	// Validate email address
	var emailre = /^\w[-._\w]*\w@\w[-._\w]*\w\.\w{2,3}$/;
	var email = $.trim($(".txtEmailAddress:first").val());
	if (!email.match(emailre)) {
		errors.push("Invalid email address.");
		valid = false;
		$(".txtEmailAddress:first").addClass("error");
	}
	else {
		valid = true;
		$(".txtEmailAddress:first").removeClass("error");
	}
	overallValid = valid && overallValid;

	arguments.IsValid = overallValid;
	$("#registerMessage").html(errors.join("<br />"));
}

customrequiredfieldvalidator_validate = function (selector) {
	var txt = $(selector);
	var valid = ($.trim(txt.val()) != "");
	if (valid)
		txt.removeClass("error");
	else
		txt.addClass("error");
	return valid;
}

customrequiredfieldvalidator_validateddl = function (selector) {
	var ddl = $(selector);
	var valid = ($.trim(ddl.val()) != "-1");
	if (valid)
		ddl.removeClass("error");
	else
		ddl.addClass("error");
	return valid;
}

pwdchange_passwordmatch_validate = function (source, arguments) {
	//alert("pwdchange_passwordmatch_validate");
	var pwd = $.trim($(".txtPassword:first").val());
	var conf = $.trim($(".txtConfirmPassword:first").val());
	var valid = (pwd == conf);
	if (valid) {
		$(".txtPassword:first").removeClass("error");
		$(".txtConfirmPassword:first").removeClass("error");
	}
	else {
		$(".txtPassword:first").addClass("error");
		$(".txtConfirmPassword:first").addClass("error");
	}
	arguments.IsValid = valid;
	//alert(arguments.IsValid);
}

default_onload = function () {
	// Make sure all four columns are the same height
	var maxHeight = 700;
	$("#leftColumn, .homeColumn").each(function () {
		maxHeight = Math.max(maxHeight, $(this).height());
	});
	$("#leftColumn, .homeColumn").each(function () {
		$(this).css("height", maxHeight + "px");
	});
}

default_supersleight = function () {
	$("#logoLink, #videoPlayerOverlayLeft, #videoPlayerOverlayTop, #videoPlayerOverlayRight, #videoPlayerOverlayBottom, #prevButton, #nextButton, .homeColumn").supersleight();
}

releases_supersleight = function () {
	$("#logoLink, .release").supersleight();
}

datestoremember_docready = function() {
    var lastAgendaItemDateString = null;
    $("#calendar").fullCalendar({
        contentHeight: 600,
        header: {
            left: "prev",
            center: "title",
            right: "today,next"
        },
        buttonText: {
            prev: "Prev",
            next: "Next",
            today: "Today"
        },
        columnFormat: {
            month: "dddd"
        },
        events: function(start, end, callback) {
            // clear agenda
            $(".agendaItem").each(function() { $(this).remove(); });
            $.ajax({
                url: "/handlers/DatesToRemember.ashx",
                dataType: "json",
                data: {
                    start: Math.round(start.getTime() / 1000),
                    end: Math.round(end.getTime() / 1000),
                    "_": (new Date()).getTime()
                },
                success: function(ret) {
                    // Update all of the event date/times to reflect midnight in the current time zone
                    dtr_start = Math.round(start.getTime() / 1000);
                    dtr_end = Math.round(end.getTime() / 1000);
                    var arr = new Array();
                    for (var i = 0; i < ret.length; i++) {
                        var event = ret[i];
                        var dt = Math.round(Date.parse(event.start) / 1000);

                        var offset = (new Date(event.start)).getTimezoneOffset() * 60;
                        dt = dt + offset;
                        event.start = dt;
                        arr.push(event);
                    }
                    callback(arr);
                }
            });
        },
        eventAfterRender: function(event, element, view) {
            // move it over and up
            var pos = $(element).position();
            var elLeft = pos.left;
            var elTop = pos.top;
            var elWidth = $(element).width();
            $(element).css({ left: elLeft + 25, top: elTop - 32, width: elWidth - 25 }).hide().fadeIn();

            // tooltip configuration
            $(element).qtip({
                content: {
                    text: event.descriptionhtml
                },
                show: "mouseover",
                hide: {
                    delay: 100,
                    fixed: true,
                    when: {
                        event: "mouseout"
                    }
                },
                position: {
                    corner: {
                        target: "bottomLeft",
                        tooltip: "topRight"
                    },
                    adjust: {
                        x: 40,
                        y: -20
                    }
                },
                style: {
                    border: {
                        width: 2,
                        color: "#000000"
                    },
                    "font-size": "0.8em"
                }
            });

            // agenda render
            var ai = $("<div class='agendaItem'>");
            if (lastAgendaItemDateString != event.agendaDateString) {
                var h5 = $("<h5>").attr("class", event.className).text(event.agendaDateString);
                h5.appendTo(ai);
                lastAgendaItemDateString = event.agendaDateString;
            }
            var cntnr = $("<div class='clearfix'>");
            var legend = $("<div class='legendColor " + event.className + "LegendColor'>");
            legend.appendTo(cntnr);
            var s = $("<span>");
            s.text(event.title);
            s.appendTo(cntnr);
            cntnr.appendTo(ai);
            ai.appendTo($("#agenda"));
            if (isIE6) ai.supersleight();
        }
    });

    // Set up month/year jump controls
    var td = $(".fc-button-today:first").parent();
    var monthJump = $("<select>").attr("id", "monthJump");
    for (var i = 0; i < 12; i++) {
        monthJump.append($("<option>").attr("value", i).text($.fullCalendar.formatDate($.fullCalendar.parseDate((i + 1).toString() + "/1/2010"), "MMMM")));
    }
    monthJump.appendTo(td);
    var yearJump = $("<select>").attr("id", "yearJump");
    var now = new Date();
    for (var y = 2009; y <= now.getFullYear(); y++) {
        var option = $("<option>").text(y.toString());
        if (y == now.getFullYear())
            option.attr("selected", "selected");
        option.appendTo(yearJump);
    }
    yearJump.appendTo(td);

    // Jump controls onselect
    $("#monthJump, #yearJump").unbind("change").bind("change", dateJump);

    // Create semi-transparent blue divs for even-numbered (zero-index) rows and position them
    // behind the day numbers
    var rowIdx = 0;
    var gridOffsetLeft = $(".fc-grid:first").offset().left + 7;
    var gridOffsetTop = $(".fc-grid:first").offset().top + 7;
    $(".fc-grid table tbody tr").each(function() {
        if (rowIdx % 2 == 0) {
            $("td", this).each(function() {
                var offset = $(this).offset();
                var offsetLeft = offset.left - gridOffsetLeft;
                var offsetTop = offset.top - gridOffsetTop;
                var cellWidth = $(this).width();
                var cellHeight = $(this).height();

                $("<div>").css({
                    backgroundColor: "#3eb8e5",
                    opacity: 0.3,
                    position: "absolute",
                    left: offsetLeft,
                    top: offsetTop,
                    height: cellHeight,
                    width: cellWidth,
                    zIndex: 1
                }).appendTo($(this));
            });
        }
        rowIdx++;
    });

    // Wire up PDF download button
    $("#btnDownloadPDF").bind("click", function() {
        location.href = "/handlers/DatesToRememberPDF.ashx?start=" + dtr_start.toString() + "&end=" + dtr_end.toString();
        return false;
    });
}

datestoremember_supersleight = function () {
	$("#logoLink").supersleight();
}

dateJump = function () {
	$("#calendar").fullCalendar("gotoDate", $("#yearJump").val(), $("#monthJump").val());
}

legal_docready = function () {
	$("#backButton").unbind("click").bind("click", function () {
		history.back();
	});
}

movieinfo_docready = function () {
//	$("#fplayer").bind("click", function () {
//		$("#controlBar, #controlBarBGCntnr").show();
//	});
}

movieinfo_onload = function() {
    if ($("#videoPlayer").length > 0 && $("#fplayer").length > 0) {
        objPPFlowPlayer = $f("fplayer", {
            src: "/flash/flowplayer.commercial-3.2.7.swf",
            wmode: "transparent"
        }, {
            key: "#@47a6880264d69ebb110",
            clip: {
                url: this.href,
                autoPlay: true,
                autoBuffering: true,
                width: 720,
                height: 300
                //                onStart: function(clip, info) {
                //                    $("#controlBar a.play, #controlBar a.pause, #controlBar a.mute, #controlBar a.unmute").supersleight();
                //                }
            },
            plugins: {
                controls: // null
                {
                url: '/flash/flowplayer.controls-3.2.5.swf',
                all: false,
                play: true,
                mute: true,
                volume: true,
                fullscreen: true,
                scrubber: true,
                time: true,
                timeColor: '#CCCCCC',
                timeSeparator: '/',
                tooltips: {
                    buttons: true,
                    fullscreen: 'Enter fullscreen mode'
                }
            }
            ////                    autoHide: 'always',
            ////                    backgroundColor: 'transparent',
            ////                    tooltips: {
            ////                        buttons: true,
            ////                        fullscreen: 'Enter fullscreen mode'
            ////                    },
            ////                    play: true,
            ////		            scrubber: true,
            ////		            bufferColor: '#555555'

        },
        play: {
            url: "/images/btn_play_small.png",
            width: 90,
            height: 82
        },
        onLoad: function() {
            $("#videoPlayer").css("background-image", "none");
            //                $("#controlBarBGCntnr").show();
            //                $("#controlBar").css("top", "-52px");
        },
        onMute: function() {
            //                $("#controlBar a.unmute").supersleight();
        },
        onUnmute: function() {
            //                $("#controlBar a.mute").supersleight();
        }
    })//.controls("controlBar");

}
if (boolLoadFlowPlayerNow == true && objPPFlowPlayer != null)
    LoadFlowPlayer();
}

function LoadFlowPlayer() {

    objPPFlowPlayer.play();
    boolLoadFlowPlayerNow = false; //only auto-load the player one time
}

ordermaterials_docready = function () {
	imageDialogInit();

	addToCartInProgress = false;
	$(".orderMaterialButton").bind("click", orderbutton_click);
}

orderbutton_click = function (e) {
	if (!addToCartInProgress) {
		addToCartInProgress = true;
		e.preventDefault();

		// Show AJAX indicator
		var indicator = $($(this).parents(".omProductOrderBox").siblings(".addToCartProgress:first"));
		indicator.show();

		var item = $(this).parents(".omProduct")[0];
		var validator = $(".omInvalidQuantity:first", $(item));
		var itemID = $(".omItemID:first", $(item)).val();

		// Validate quantity
		var qty = $.trim($(".omProductOrderQty:first", $(item)).val());
		if (isNaN(parseInt(qty))) {
			// Show message
			validator.show();
			indicator.hide();
			addToCartInProgress = false;
		}
		else {
			if (parseInt(qty) < 1) {
				validator.show();
				indicator.hide();
				addToCartInProgress = false;
			}
			else {
				validator.hide();
				$.ajax({
					url: "/handlers/AddToCart.ashx",
					data: {
						itemID: itemID,
						quantity: qty,
						time: (new Date()).getTime() // cachebuster
					},
					success: function (data, status, xhr) {
						$.ajax({
							url: "/handlers/Cart.ashx",
							data: {
								time: (new Date()).getTime() // cachebuster
							},
							dataType: "json",
							success: function (data, textStatus, xhr) {
								var cart = data;
								var items = cart.items;
								$("#itemsInCart").text(cart.itemCount);
								if (items.length > 0) {
									var lastItem = items[items.length - 1];
									$("#justAddedImg").attr("src", lastItem.itemImageURL).attr("alt", lastItem.itemTitle);
									$("#justAddedInfoCntnr h4:first").text(lastItem.filmTitle);
									$("#justAddedInfoCntnr h5:first").text(lastItem.itemTitle);
									$("#justAddedQuantity").text("Quantity: " + lastItem.quantity);
								}
								indicator.hide();
								addToCartInProgress = false;
								$("#cartCntnr").dialog("open");
							}
						});
					}
				});
			}
		}
	}
	return false;
}

promosupport_docready = function () {
	singleImageDialogInit();
	downloadTrackingInit();
}

hiresartwork_docready = function () {
	singleImageDialogInit();
	downloadTrackingInit();
}

digitalAssets_docready = function () {
	singleImageDialogInit();
	downloadTrackingInit();
}

history_docready = function () {
	$("#historyCycleCntnr").cycle({
		fx: "fade",
		easing: "swing",
		speed: 400,
		timeout: 0,
		pager: "#historyCycleNav",
		pagerAnchorBuilder: function (idx, slide) {
			return "#historyCycleNav li:eq(" + idx + ") a";
		},
		cleartype: true,
		cleartypeNoBg: true
	});
	$("#historyCyclePrev").click(function () { $("#historyCycleCntnr").cycle("prev"); });
	$("#historyCycleNext").click(function () { $("#historyCycleCntnr").cycle("next"); });
	$("#historyFirstYear").text($("#historyCycleNav li:first a").attr("title"));
	$("#historyLastYear").text($("#historyCycleNav li:last a").attr("title"));

	// Space timeline buttons
	var totalWidth = 750;
	var gaps = $("#historyCycleNav li").length - 1;
	if (gaps > 1) {
		var spaceBetween = totalWidth / gaps;
		if (isIE6) {
			$("#historyCycleNav li").each(function (idx, el) {
				$(this).css({ left: (idx * Math.floor(spaceBetween)) - 12 });
			});
		}
		else {
			$("#historyCycleNav li").css({ marginRight: spaceBetween - 12 });
			$("#historyCycleNav li:eq(" + (gaps - 1).toString() + ")").css({ marginRight: 0 });
			$("#historyCycleNav li:last").css({ marginRight: -12, "float": "right" });
		}
		$("#historyCycleNav li a").qtip({
			show: "mouseover",
			hide: "mouseout",
			position: {
				corner: {
					target: "topLeft",
					tooltip: "bottomLeft"
				},
				adjust: {
					x: -3,
					y: 5
				}
			},
			show: {
				delay: 0
			},
			hide: {
				delay: 100
			},
			style: {
				"background-color": "transparent",
				"border": "0",
				"color": "#ffffff",
				"font-size": "0.8em",
				"font-weight": "bold"
			}
		});
	}
}

history_supersleight = function () {
	$("#logoLink, #historyCyclePrev, #historyCycleNext, p.byline").supersleight();
}

changeRegion = function (id) {
	if (id == "all") {
		$(".region").show();
	}
	else {
		$(".region").hide();
		if (id != "none") {
			$("#" + id + "_region").show();
		}
	}
}

sendmessage_supersleight = function () {
	$("#logoLink, #btnSubmit").supersleight();
}

sendmessage_docready = function () {
	$("#TechnicolorNumber").val($("#pTechnicolorNumber").html());
	$("#CircuitName").val($("#pCircuitName").html());
	$("#TheatreLocation").val($("#pTheatreName").html());
	$("#Address").val($("#pAddress").html().replace(/<br\s?\/?>/gi, ", "));
}

sendmessage_validate = function () {
	$(".sendMessageForm .error").unbind("blur", field_error_blur).removeClass("error");
	var re = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/; //Email regular expression for validation
	$(".sendMessageForm input:text, .sendMessageForm textarea").each(function () {
		if ($.trim($(this).val()) == "") {
			$(this).addClass("error");
		}
		else if ($(this).attr("id") == "Email") {
			var email = $.trim($(this).val());
			if (!re.test(email)) {
				$(this).addClass("error");
			}
		}
	});
	$(".sendMessageForm .error").bind("blur", field_error_blur);

	if ($(".sendMessageForm .error")[0]) {
		$(".sendMessageForm .error")[0].focus();
		return false;
	}
	return true;
}

marketingmaterials_docready = function () {
	imageDialogInit();
}

marketingmaterials_supersleight = function () {
	$("#logoLink").supersleight();
}

news_supersleight = function () {
	$("#logoLink, p.byline").supersleight();
}

cart_docready = function () {
	$("#confirmRemoveDialog").dialog({
		modal: true,
		dialogClass: "cartDialogJQ confirmRemoveDialogJQ",
		draggable: false,
		resizable: false,
		autoOpen: false,
		width: 500
	});
	$(".removeItemLink").click(function (e) {
		e.preventDefault();
		var targetUrl = $(this).attr("href");
		var item = $(this).parents(".itemListItem")[0];
		$("#confirmRemoveDialog").dialog({
			buttons: {
				"Cancel": function () {
					$(this).dialog("close");
				},
				"Confirm": function () {
					location.href = targetUrl;
				}
			},
			open: function () {
				$("#confirmRemoveImg").attr("src", ($("img:first", $(item)).attr("src")));
				$("#confirmRemoveInfoCntnr h4").text($("h4:first", $(item)).text());
				$("#confirmRemoveInfoCntnr h5").text($("h5:first", $(item)).text());
				$("#confirmRemoveQuantity").text("Quantity: " + $(".itemListInfoQuantity input:first", $(item)).val());
			}
		});
		$("#confirmRemoveDialog").dialog("open");
	});
}

/******** FORM VALIDATION FUNCTIONS ********/

field_error_blur = function () {
	if (($(this).attr("type") == "text" || $(this).is("textarea")) && $.trim($(this).val()) != "") {
		if ($(this).attr("id") == "Email") {
			var email = $.trim($(this).val());
			var re = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/; //Email regular expression for validation
			if (re.test(email)) {
				$(this).removeClass("error");
			}
		}
		else {
			$(this).removeClass("error");
		}
	}
}

/******** CAROUSEL/CONTENTFLOW FUNCTIONS **********/

contentflow_init = function () {
	$("#releaseCarouselCF").show();
	var cf = new ContentFlow("releaseCarouselCF", {
		reflectionHeight: 0,
		visibleItems: 3,
		scrollWheelSpeed: 0,
		keys: {},
		endOpacity: 0.58,
		maxItemHeight: 150,
		flowDragFriction: 0,
		calcCoordinates: function (item) {
			var rP = item.relativePosition;
			var rPn = item.relativePositionNormed;
			var x = rPn * (1 - (0.05 * Math.abs(rP))) + (rP * 0.01);
			var y = 1;

			return { x: x, y: y };
		},
		calcSize: function (item) {
			var rP = item.relativePosition;
			var h = 1 - (0.1 * Math.abs(rP));
			var w = h;
			return { width: w, height: h };
		},
		onDoneMoving: function (item) {
			// We customized contentflow and added this new event
			// It's still a little touchy, so we'll keep track of the currently displayed
			// release's ID and only do something if that changes.
			// Each carousel item's image ID attribute is "item_nn" where nn is the ID of the
			// release's content block.
			var id = parseInt($("img:first", item.element).attr("id").substr(5));
			if (!isNaN(id) && carouselActiveRelease != id) {
				carouselActiveRelease = id;
				$("#homeCarouselTarget").fadeOut();
				$("#homeCarouselLoadingCntnr").fadeIn(function () {
					$.ajax({
						url: "/ajaxcontent/ReleaseCarouselContent.aspx",
						data: { id: id },
						success: function (data, status, xhr) {
							$("#homeCarouselTarget").html($("#ajaxCntnr", data).html()).fadeIn();
							$("#fplayer img").supersleight();
							movieinfo_onload();
						},
						complete: function (xhr, status) {
							$("#homeCarouselLoadingCntnr").fadeOut();
						}
					});
				});
			}
		},
		onclickActiveItem: function (item) {
			return false;
		}
	});

	$("#prevButton").live("click", function () {
		cf.moveTo("previous");
		return false;
	});
	$("#nextButton").live("click", function () {
		cf.moveTo("next");
		return false;
	});
}

/******** IMAGE DIALOG FUNCTIONS **********/

singleImageDialogInit = function () {
	var hPad = 100;
	var vPad = 150;

	$(".imageDialog").dialog({
		autoOpen: false,
		draggable: false,
		resizable: false,
		dialogClass: "imageDialogJQ",
		modal: true,
		show: "fade",
		hide: "fade",
		width: 50,
		height: "auto",
		open: function () {
			var dlg = $(this).parent();
			var img = $("img:first", this);
			$(dlg).css({
				left: "50%",
				top: "50%",
				marginLeft: (-.5 * (img.width() + hPad)) + $(window).scrollLeft(),
				marginTop: (-.5 * (img.height() + vPad)) + $(window).scrollTop(),
				width: img.width() + hPad,
				height: img.height() + vPad
			});
		}
	});
}

imageDialogInit = function () {
	var hPad = 100;
	var vPad = 130;

	$(".imageDialog").dialog({
		autoOpen: false,
		draggable: false,
		resizable: false,
		dialogClass: "imageDialogJQ",
		modal: true,
		show: "fade",
		hide: "fade",
		width: 800 + hPad,
		height: 600 + vPad,
		open: function () {
			var dlg = $(this).parent();
			$(".imageDialogCycle", this).cycle({
				timeout: 0,
				next: $(".imageDialogPaginationNext", this),
				prev: $(".imageDialogPaginationPrev", this),
				cleartype: 1
			});
			$(dlg).css({
				left: "50%",
				top: "50%",
				marginLeft: -400 - (.5 * hPad),
				marginTop: -300 - (.5 * vPad),
				width: 800 + hPad,
				height: 600 + vPad
			});
			$(this).height(600 + vPad);
		},
		beforeclose: function () {
			$(".imageDialogCycle", this).cycle("destroy");
		}
	});
}

viewLarger = function (pos) {
	$("#imageDialog_" + pos).dialog("open");
}

/************** DOWNLOAD TRACKING ******************/

downloadTrackingInit = function () {
	$(".downloadButton").each(function () {
		$(this).bind("click", function () {
			// Track the download
			$.ajax({
				url: "/handlers/DownloadTracker.ashx",
				data: {
					release: $.trim($("h1:first").text()),
					title: $(this).attr("title")
				}
			});
		});
	});
}




