/*********************************************************************************/
/* BLUEARC PATH TO PURCHASE JS     							 					 */
/*********************************************************************************/

jQuery(document).ready(function () {

	var tempIMG = jQuery('<img />').attr('src', '/resources/img/myfun/loader.gif');

	/* Hide Pay now button after clicked */
	jQuery('.next.paynow').click(function () { jQuery(this).css('visibility', 'hidden'); });

	// Validation Error Popups 
	jQuery('span.validation-error-pop').hover(function () {
		jQuery(this).append('<span>' + jQuery(this).find('img').attr('alt') + '</span>');
	}, function () {
		jQuery(this).find('span').remove();
	});


	// Total Calculation for Step 2 
	if (jQuery('span.price').length > 0) {
		var totalPrice = 0;
		jQuery('span.price').each(function () {
			totalPrice += parseFloat(jQuery(this).text().substring(1));
			jQuery('#total span').text("$" + totalPrice.toFixed(2));
		});
	}

	// Step 2 Form Expander
	jQuery('.expander').click(function () {
		if (jQuery(this).is(':checked')) {
			jQuery(this).parents('fieldset').find('.content-box.dark').slideUp();
		} else {
			jQuery(this).parents('fieldset').find('.content-box.dark').slideDown();
		};
	});
	jQuery('.expander:checked').each(function () {
		jQuery(this).parents('fieldset').find('.content-box.dark').slideUp(1);
	});
	jQuery('.expander-all').click(function (e) {
		e.preventDefault();
		jQuery('.expander').parents('fieldset').find('.content-box.dark').slideUp();
		jQuery('.expander').attr('checked', 'checked');
	});

	// Payment Details Spander
	jQuery('.payment-spander').click(function () {
		if (jQuery(this).is(':checked')) {

			// Check for the existance of the domestic shipping only checkbox
			if (typeof (domesticShippingOnly) != "undefined") {

				// If it's true, and the billing address is not australian, then show a message and don't slide
				if (domesticShippingOnly && jQuery(".ddl-billing-country").val().toLowerCase() != "australia" && jQuery(".ddl-billing-country").val() != "") {
					jQuery(this).removeAttr('checked');
					alert('Sorry, but we cannot use the same details for the shipping address as we currently only ship to Australian addresses.');
					return;
				}

			}

			jQuery(this).parent('.content-box').animate({ 'padding-bottom': '30px' }).next('.content-box').slideUp();
		} else {
			jQuery(this).parent('.content-box').animate({ 'padding-bottom': '0' }).next('.content-box').slideDown();
		};
	});
	jQuery('.payment-spander:checked').each(function () {
		jQuery(this).parent('.content-box').css('padding-bottom', '30px').next('.content-box').slideUp(1);
	});

	// Popup password label
	jQuery('#loginPopup .blocks span.pass-lbl').click(function () { jQuery(this).hide().next('input.text').focus(); });
	jQuery('#loginPopup .blocks span.pass-lbl').next('#loginPopup .blocks input.text').focus(function () { jQuery(this).prev('span.pass-lbl').hide(); }).blur(function () { jQuery(this).val() == "" ? jQuery(this).prev('span.pass-lbl').show() : jQuery(this).prev('span.pass-lbl'); });

	/* Counters Number only */
	jQuery('.ticketInput .textbox').attr('maxlength', '2');
	jQuery('.ticketInput .textbox').keypress(function (event) {

		// Backspace, tab, enter, end, home, left, right
		// We don't support the del key in Opera because del == . == 46.
		var controlKeys = [8, 9, 13, 35, 36, 37, 39];
		// IE doesn't support indexOf
		var isControlKey = controlKeys.join(",").match(new RegExp(event.which));
		// Some browsers just don't raise events for control keys. Easy.
		// e.g. Safari backspace.
		if (!event.which || // Control keys in most browsers. e.g. Firefox tab is 0
		  (49 <= event.which && event.which <= 57) || // Always 1 through 9
		  (48 == event.which && jQuery(this).attr("value")) || // No 0 first digit
		  isControlKey) { // Opera assigns values for control keys.
			return;
		} else {
			event.preventDefault();
		}
	});

	/* Counters Price Calculation For Step 1 Up Button Function */
	jQuery('.ticketInput .ticketInput-up').click(function (e) {
		e.preventDefault();
		var currentVal = jQuery(this).parent().find('.textbox').val();
		if (currentVal == "") { currentVal = 0; };
		currentVal = parseInt(currentVal);
		var newVal = currentVal + 1;
		if (newVal > 99) {
			newVal = 99;
			jQuery(this).parent().find('.textbox').val(newVal);
		} else {
			jQuery(this).parent().find('.textbox').val(newVal);
		};
		// If in the selectTicket Table
		if (jQuery(this).parents('table.generic.selectTicket').length > 0) {
			var newPrice = newVal * jQuery(this).parent().find('input[type="hidden"]').val();
			jQuery(this).parents('td').next('td').html("$" + newPrice.toFixed(2));
			// Totalling 
			var totalPrice = 0;
			jQuery(this).parents('table.generic.selectTicket').find('tr td:last-child').each(function () {
				if (!jQuery(this).hasClass('bluebg')) {
					totalPrice += parseFloat(jQuery(this).html().substring(1));
					jQuery(this).parents('table.generic.selectTicket').find(' td.bluebg:last-child').html("$" + totalPrice.toFixed(2));
				}
			});
			var totalItems = 0;
			jQuery(this).parents('table.generic.selectTicket').find('.textbox').each(function () {
				totalItems += parseInt(jQuery(this).val());
				jQuery(this).parents('table.generic.selectTicket').find(' td.bluebg.center').html(totalItems);
			});
		};
		// If in the Sidebar Cart
		if (jQuery(this).parents('#sidebar-cart-items').length > 0) {
			var newPrice = newVal * jQuery(this).parent().find('input[type="hidden"]').val();
			jQuery(this).parents('.item.clearfix').find('.sidebar-cart-price-subtotal p').html("$" + newPrice.toFixed(2));
			// number of tix
			var numTix = 0;
			jQuery('#sidebar-cart-items .ticketInput input.textbox').each(function () { numTix += parseInt(jQuery(this).val()); });
			jQuery('.sidebar-mybasket > p:first-child').html("There are currently " + numTix + " tickets in your basket");
			jQuery('.sidebar-ticket-amount').html("(" + numTix + " tickets)");
			jQuery('#myFunSidebarOpen > a > span').html(numTix);
			// Totalling 
			var totalPrice = 0;
			jQuery(this).parents('#sidebar-cart-items').find('.sidebar-cart-price-subtotal p').each(function () {
				totalPrice += parseFloat(jQuery(this).html().substring(1));
				jQuery(this).parents('.sidebar-mybasket').find('#sidebar-total-amount').html("$" + totalPrice.toFixed(2));
			});
		};
		// If in Checkout Summary
		if (jQuery(this).parents('table.generic.step-one').length > 0) {
			var newPrice = newVal * jQuery(this).parent().find('input[type="hidden"]').val();
			jQuery(this).parents('tr').find('td.right').html("$" + newPrice.toFixed(2));
			// Totalling
			var totalIndex;
			var webBookingIndex;
			var postageIndex;
			var discountIndex;

			jQuery('table.generic.step-one td.lbluebg.bold.right.bluefont').each(function () {
				if (jQuery(this).hasClass("sub-total")) { totalIndex = jQuery(this) };
				if (jQuery(this).html() == "Web booking fee") { webBookingIndex = jQuery(this) };
				if (jQuery(this).html() == "Postage fee") { postageIndex = jQuery(this) };
				if (jQuery(this).html() == "Member discount") { discountIndex = jQuery(this) };
			});

			var totalPrice = 0;
			var webBookingPrice = 0;
			if (webBookingIndex != undefined) { webBookingPrice = parseFloat(jQuery(webBookingIndex).next('td.right').html().substring(1)); };
			var postagePrice = 0;
			if (postageIndex != undefined) { postagePrice = parseFloat(jQuery(postageIndex).next('td.right').html().substring(1)); };
			var discountPrice = 0;
			if (discountIndex != undefined) { discountPrice = parseFloat(jQuery(discountIndex).next('td.right').html().substring(1)); };

			var grandTotal = 0;

			jQuery(this).parents('table.generic.step-one').find('td.right').each(function () {
				if (!jQuery(this).siblings().hasClass('noborder')) {
					totalPrice += parseFloat(jQuery(this).html().substring(1));
					grandTotal = totalPrice + webBookingPrice + postagePrice - discountPrice;
					jQuery(totalIndex).next('td.right').html("$" + totalPrice.toFixed(2));
					jQuery('table.generic.step-one').find('td.right').last().html("$" + grandTotal.toFixed(2));
				}
			});
		};
	});

	/* Counters Price Calculation For Step 1 Down Button Function */
	jQuery('.ticketInput .ticketInput-down').click(function (e) {
		e.preventDefault();
		var currentVal = jQuery(this).parent().find('.textbox').val();
		if (currentVal == "") { currentVal = 0; };
		currentVal = parseInt(currentVal);
		var newVal = currentVal - 1;
		if (newVal < 0) {
			newVal = 0;
			var currentVal = jQuery(this).parent().find('.textbox').val(newVal);
		} else {
			var currentVal = jQuery(this).parent().find('.textbox').val(newVal);
		}
		// If in the selectTicket Table
		if (jQuery(this).parents('table.generic.selectTicket').length > 0) {
			var newPrice = newVal * jQuery(this).parent().find('input[type="hidden"]').val();
			jQuery(this).parents('td').next('td').html("$" + newPrice.toFixed(2));
			// Totalling 
			var totalPrice = 0;
			jQuery(this).parents('table.generic.selectTicket').find('tr td:last-child').each(function () {
				if (!jQuery(this).hasClass('bluebg')) {
					totalPrice += parseFloat(jQuery(this).html().substring(1));
					jQuery(this).parents('table.generic.selectTicket').find(' td.bluebg:last-child').html("$" + totalPrice.toFixed(2));
				}
			});
			var totalItems = 0;
			jQuery(this).parents('table.generic.selectTicket').find('.textbox').each(function () {
				totalItems += parseInt(jQuery(this).val());
				jQuery(this).parents('table.generic.selectTicket').find(' td.bluebg.center').html(totalItems);
			});
		};
		// If in the Sidebar Cart
		if (jQuery(this).parents('#sidebar-cart-items').length > 0) {
			var newPrice = newVal * jQuery(this).parent().find('input[type="hidden"]').val();
			jQuery(this).parents('.item.clearfix').find('.sidebar-cart-price-subtotal p').html("$" + newPrice.toFixed(2));
			// number of tix
			var numTix = 0;
			jQuery('#sidebar-cart-items .ticketInput input.textbox').each(function () { numTix += parseInt(jQuery(this).val()); });
			jQuery('.sidebar-mybasket > p:first-child').html("There are currently " + numTix + " tickets in your basket");
			jQuery('.sidebar-ticket-amount').html("(" + numTix + " tickets)");
			jQuery('#myFunSidebarOpen > a > span').html(numTix);
			// Totalling 
			var totalPrice = 0;
			jQuery(this).parents('#sidebar-cart-items').find('.sidebar-cart-price-subtotal p').each(function () {
				totalPrice += parseFloat(jQuery(this).html().substring(1));
				jQuery(this).parents('.sidebar-mybasket').find('#sidebar-total-amount').html("$" + totalPrice.toFixed(2));
			});
		};
		// If in Checkout Summary
		if (jQuery(this).parents('table.generic.step-one').length > 0) {
			var newPrice = newVal * jQuery(this).parent().find('input[type="hidden"]').val();
			jQuery(this).parents('tr').find('td.right').html("$" + newPrice.toFixed(2));
			// Totalling
			var totalIndex;
			var webBookingIndex;
			var postageIndex;
			var discountIndex;

			jQuery('table.generic.step-one td.lbluebg.bold.right.bluefont').each(function () {
				if (jQuery(this).hasClass("sub-total")) { totalIndex = jQuery(this) };
				if (jQuery(this).html() == "Web booking fee") { webBookingIndex = jQuery(this) };
				if (jQuery(this).html() == "Postage fee") { postageIndex = jQuery(this) };
				if (jQuery(this).html() == "Member discount") { discountIndex = jQuery(this) };
			});

			var totalPrice = 0;
			var webBookingPrice = 0;
			if (webBookingIndex != undefined) { webBookingPrice = parseFloat(jQuery(webBookingIndex).next('td.right').html().substring(1)); };
			var postagePrice = 0;
			if (postageIndex != undefined) { postagePrice = parseFloat(jQuery(postageIndex).next('td.right').html().substring(1)); };
			var discountPrice = 0;
			if (discountIndex != undefined) { discountPrice = parseFloat(jQuery(discountIndex).next('td.right').html().substring(1)); };

			var grandTotal = 0;

			jQuery(this).parents('table.generic.step-one').find('td.right').each(function () {
				if (!jQuery(this).siblings().hasClass('noborder')) {
					totalPrice += parseFloat(jQuery(this).html().substring(1));
					grandTotal = totalPrice + webBookingPrice + postagePrice - discountPrice;
					jQuery(totalIndex).next('td.right').html("$" + totalPrice.toFixed(2));
					jQuery('table.generic.step-one').find('td.right').last().html("$" + grandTotal.toFixed(2));
				}
			});
		};
	});

	/* Counters Price Calculation For Step 1 Change Text Field Function */
	jQuery('.ticketInput .textbox').focusout(function () {
		if (jQuery(this).val() == "") { jQuery(this).val('0'); };
		var newVal = jQuery(this).parent().find('.textbox').val();
		var newPrice = newVal * jQuery(this).parent().find('input[type="hidden"]').val();
		jQuery(this).parent().siblings('span').text("$" + newPrice.toFixed(2));
		// If in the selectTicket Table
		if (jQuery(this).parents('table.generic.selectTicket').length > 0) {
			var newPrice = newVal * jQuery(this).parent().find('input[type="hidden"]').val();
			jQuery(this).parents('td').next('td').html("$" + newPrice.toFixed(2));
			// Totalling 
			var totalPrice = 0;
			jQuery(this).parents('table.generic.selectTicket').find('tr td:last-child').each(function () {
				if (!jQuery(this).hasClass('bluebg')) {
					totalPrice += parseFloat(jQuery(this).html().substring(1));
					jQuery(this).parents('table.generic.selectTicket').find(' td.bluebg:last-child').html("$" + totalPrice.toFixed(2));
				}
			});
			var totalItems = 0;
			jQuery(this).parents('table.generic.selectTicket').find('.textbox').each(function () {
				totalItems += parseInt(jQuery(this).val());
				jQuery(this).parents('table.generic.selectTicket').find(' td.bluebg.center').html(totalItems);
			});
		};
		// If in the Sidebar Cart
		if (jQuery(this).parents('#sidebar-cart-items').length > 0) {
			var newPrice = newVal * jQuery(this).parent().find('input[type="hidden"]').val();
			jQuery(this).parents('.item.clearfix').find('.sidebar-cart-price-subtotal p').html("$" + newPrice.toFixed(2));
			// number of tix
			var numTix = 0;
			jQuery('#sidebar-cart-items .ticketInput input.textbox').each(function () { numTix += parseInt(jQuery(this).val()); });
			jQuery('.sidebar-mybasket > p:first-child').html("There are currently " + numTix + " tickets in your basket");
			jQuery('.sidebar-ticket-amount').html("(" + numTix + " tickets)");
			jQuery('#myFunSidebarOpen > a > span').html(numTix);
			// Totalling 
			var totalPrice = 0;
			jQuery(this).parents('#sidebar-cart-items').find('.sidebar-cart-price-subtotal p').each(function () {
				totalPrice += parseFloat(jQuery(this).html().substring(1));
				jQuery(this).parents('.sidebar-mybasket').find('#sidebar-total-amount').html("$" + totalPrice.toFixed(2));
			});
		};
		// If in Checkout Summary
		if (jQuery(this).parents('table.generic.step-one').length > 0) {
			var newPrice = newVal * jQuery(this).parent().find('input[type="hidden"]').val();
			jQuery(this).parents('tr').find('td.right').html("$" + newPrice.toFixed(2));
			// Totalling
			var totalIndex;
			var webBookingIndex;
			var postageIndex;
			var discountIndex;

			jQuery('table.generic.step-one td.lbluebg.bold.right.bluefont').each(function () {
				if (jQuery(this).hasClass("sub-total")) { totalIndex = jQuery(this) };
				if (jQuery(this).html() == "Web booking fee") { webBookingIndex = jQuery(this) };
				if (jQuery(this).html() == "Postage fee") { postageIndex = jQuery(this) };
				if (jQuery(this).html() == "Member discount") { discountIndex = jQuery(this) };
			});

			var totalPrice = 0;
			var webBookingPrice = 0;
			if (webBookingIndex != undefined) { webBookingPrice = parseFloat(jQuery(webBookingIndex).next('td.right').html().substring(1)); };
			var postagePrice = 0;
			if (postageIndex != undefined) { postagePrice = parseFloat(jQuery(postageIndex).next('td.right').html().substring(1)); };
			var discountPrice = 0;
			if (discountIndex != undefined) { discountPrice = parseFloat(jQuery(discountIndex).next('td.right').html().substring(1)); };

			var grandTotal = 0;

			jQuery(this).parents('table.generic.step-one').find('td.right').each(function () {
				if (!jQuery(this).siblings().hasClass('noborder')) {
					totalPrice += parseFloat(jQuery(this).html().substring(1));
					grandTotal = totalPrice + webBookingPrice + postagePrice - discountPrice;
					jQuery(totalIndex).next('td.right').html("$" + totalPrice.toFixed(2));
					jQuery('table.generic.step-one').find('td.right').last().html("$" + grandTotal.toFixed(2));
				}
			});
		};
	});
	jQuery('.ticketInput .textbox').focusout();

	// Widen .selectTicket Tables and other content
	if (jQuery('.contentColRight').children().length < 1 && jQuery('table.selectTicket').length > 0) {
		jQuery('.contentColRight').remove();
		jQuery('.contentColLeft').removeClass('contentColLeft');
		jQuery('table.selectTicket').width('100%');
		jQuery('.selectTicket-wrapper img.popup').css('left', '460px');
	}
	if (jQuery.browser.msie && parseInt(jQuery.browser.version) == 7) { jQuery('.selectTicket-wrapper img.popup').css('left', '461px') }
	if (jQuery('.contentColRight').children().length < 1 && jQuery('.contentSidebar').children().length < 1) {
		jQuery('.col > .desc').width(555);
	}

	// IE7 Select List Widths
	// Select Internet Explorer 7 and below
	if (jQuery.browser.msie && jQuery.browser.version <= 7) {
		jQuery('.form-row select').each(function () {
			if (jQuery(this).width() > 211) {
				jQuery(this).width(211);
			}
		});
	}

	// webkit cartsummary header price width
	// Select Safari / Chrome
	if (jQuery.browser.safari) {
		jQuery('#hdr-bar.stepfour strong.second').width(24);
	}

	// checkout table header align
	if (jQuery('#hdr-bar').hasClass('stepfour')) {
		jQuery('#hdr-bar').html('').css('border', 'none').css('width', '0');
		jQuery('.cart-summary thead').removeClass('hide');
		jQuery('.cart-summary thead th').css('text-align', 'left');
		jQuery('.cart-summary thead th:first-child, .cart-summary thead th:last-child').css('background-color', '#fff').css('color', '#fff');
		jQuery('.cart-summary thead th:first-child').css('border-width', '0 2px 2px 0');
		jQuery('.cart-summary thead th:last-child').css('border-width', '0 0 2px 2px');
	}
	/*
	var marginThing = jQuery('#hdr-bar.stepfour').next('table.cart-summary').find('tbody tr:first-child th:first-child').outerWidth();
	jQuery('#hdr-bar.stepfour').css('marginLeft', marginThing);
	if (jQuery.browser.msie && jQuery.browser.version <= 7) {
	//marginThing -= 1;
	jQuery('#hdr-bar.stepfour').css('marginLeft', marginThing - 1);
	}
	if ( jQuery.browser == "webkit" ) {
	jQuery('#hdr-bar.stepfour').css('marginLeft', marginThing + 1);
	}
	if ( jQuery('#hdr-bar').hasClass('stepfour') ) {
	// Needed to calculate
	jQuery('.cart-summary thead').removeClass('hide');
	console.log(parseInt(jQuery('.cart-summary thead th:nth-child(2)').width()));
	jQuery('#hdr-bar.stepfour .second').width(jQuery('.cart-summary thead th:nth-child(2)').width() - 3);
	// IE
	if (j.browser.msie) {jQuery('#hdr-bar.stepfour .second').width(jQuery('.cart-summary thead th:nth-child(2)').width() - 1)}
	if (j.browser.msie && parseInt(j.browser.version) == 7) {
	jQuery('#hdr-bar.stepfour .second').width(jQuery('.cart-summary thead th:nth-child(2)').width() - 2);
	jQuery('#hdr-bar.stepfour .fourth').width(jQuery('.cart-summary thead th:nth-child(3)').width() + 5);
	jQuery('#hdr-bar.stepfour .fifth').width(jQuery('.cart-summary thead th:nth-child(4)').width() + 8);
	jQuery('#hdr-bar.stepfour').width(jQuery('.cart-summary thead th:nth-child(2)').width() + jQuery('.cart-summary thead th:nth-child(3)').width()+ jQuery('.cart-summary thead th:nth-child(4)').width() + 40);
	}
	// Webkit
	if (j.browser.webkit) {
	jQuery('#hdr-bar.stepfour .second').width(jQuery('.cart-summary thead th:nth-child(2)').width() - 1);
	jQuery('#hdr-bar.stepfour .fourth').width(jQuery('.cart-summary thead th:nth-child(3)').width() - 1);
	jQuery('#hdr-bar.stepfour .fifth').width(jQuery('.cart-summary thead th:nth-child(4)').width() + 1);
	jQuery('#hdr-bar.stepfour').width(jQuery('.cart-summary thead th:nth-child(2)').width() + jQuery('.cart-summary thead th:nth-child(3)').width()+ jQuery('.cart-summary thead th:nth-child(4)').width() + 48);
	}
	//Hide the thead again
	jQuery('.cart-summary thead').addClass('hide')
	}
	*/

	// SelectDate hidden field filling
	jQuery('.selectDate .time li input').live('click', function () {
		jQuery('.selectDate > input[type="hidden"]').val(jQuery(this).val());
	});
});


function startWait() {
    jQuery('body').append('<div id="TB_overlay" class="TB_overlayBG" style="display: none;"></div>').append('<div id="wait" style="display: none;"><div class="seccionne"></div><img src="/resources/img/myfun/loader.gif" width="32" height="32" alt="please wait"></div>');
    if (jQuery('#wait-msg').length > 0) {
        jQuery('#wait .seccionne').html(jQuery('#wait-msg').val());
    } else {
        jQuery('#wait .seccionne').html('<p><span>Processing your request. </span>Please do not refresh or close your browser.</p>');
    };
    var halfDocWidth = jQuery(window).width() / 2;
    var halfThisWidth = jQuery('#wait').width() / 2;
    jQuery('#wait').css('left', (halfDocWidth - halfThisWidth) + "px");
    var halfDocHeight = jQuery(window).height() / 2;
    var halfThisHeight = jQuery('#wait').height() / 2;
    jQuery('#wait').css('top', (halfDocHeight - halfThisHeight) + jQuery('html').scrollTop() + "px");
    jQuery('#TB_overlay, #wait').fadeIn(500);
    jQuery(window).resize(function () {
        var halfDocWidth = jQuery(window).width() / 2;
        var halfThisWidth = jQuery('#wait').width() / 2;
        jQuery('#wait').css('left', (halfDocWidth - halfThisWidth) + "px");
        var halfDocHeight = jQuery(window).height() / 2;
        var halfThisHeight = jQuery('#wait').height() / 2;
        jQuery('#wait').css('top', (halfDocHeight - halfThisHeight) + jQuery('html').scrollTop() + "px");
    });
    jQuery('html').scroll(function () {
        alert('oi');
        var halfDocWidth = jQuery(window).width() / 2;
        var halfThisWidth = jQuery('#wait').width() / 2;
        jQuery('#wait').css('left', (halfDocWidth - halfThisWidth) + "px");
        var halfDocHeight = jQuery(window).height() / 2;
        var halfThisHeight = jQuery('#wait').height() / 2;
        jQuery('#wait').css('top', (halfDocHeight - halfThisHeight) + jQuery('html').scrollTop() + "px");
    });
}


// Thickbox 3 - One Box To Rule Them All
var tb_pathToImage = "/resources/img/myfun/loader2.gif";
jQuery(document).ready(function () { tb_init('a.thickbox, area.thickbox, input.thickbox'); imgLoader = new Image(); imgLoader.src = tb_pathToImage; }); function tb_init(domChunk) { jQuery(domChunk).click(function () { var t = this.title || this.name || null; var a = this.href || this.alt; var g = this.rel || false; tb_show(t, a, g); this.blur(); return false; }); } function tb_show(caption, url, imageGroup) { try { if (typeof document.body.style.maxHeight === "undefined") { jQuery("body", "html").css({ height: "100%", width: "100%" }); jQuery("html").css("overflow", "hidden"); if (document.getElementById("TB_HideSelect") === null) { jQuery("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div><div id='TB_window' role='dialog' aria-live='assertive' aria-relevant='additions'></div>"); } } else { if (document.getElementById("TB_overlay") === null) { jQuery("body").append("<div id='TB_overlay'></div><div id='TB_window' role='dialog' aria-live='assertive' aria-relevant='additions'></div>"); jQuery("#TB_overlay").click(tb_remove); } } if (tb_detectMacXFF()) { jQuery("#TB_overlay").addClass("TB_overlayMacFFBGHack"); } else { jQuery("#TB_overlay").addClass("TB_overlayBG"); } if (caption === null) { caption = ""; } jQuery("body").append("<div id='TB_load'><img src='" + imgLoader.src + "' alt='Loading...' /></div>"); jQuery('#TB_load').show(); var baseURL; if (url.indexOf("?") !== -1) { baseURL = url.substr(0, url.indexOf("?")); } else { baseURL = url; } var urlString = /\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$/; var urlType = baseURL.toLowerCase().match(urlString); if (urlType == '.jpg' || urlType == '.jpeg' || urlType == '.png' || urlType == '.gif' || urlType == '.bmp') { TB_PrevCaption = ""; TB_PrevURL = ""; TB_PrevHTML = ""; TB_NextCaption = ""; TB_NextURL = ""; TB_NextHTML = ""; TB_imageCount = ""; TB_FoundURL = false; if (imageGroup) { TB_TempArray = jQuery("a[rel=" + imageGroup + "]").get(); for (TB_Counter = 0; ((TB_Counter < TB_TempArray.length) && (TB_NextHTML === "")); TB_Counter++) { var urlTypeTemp = TB_TempArray[TB_Counter].href.toLowerCase().match(urlString); if (!(TB_TempArray[TB_Counter].href == url)) { if (TB_FoundURL) { TB_NextCaption = TB_TempArray[TB_Counter].title; TB_NextURL = TB_TempArray[TB_Counter].href; TB_NextHTML = "<a href='#' id='TB_next'><img src='/resources/img/myfun/tbox-nxt.gif' width='32' height='32' alt='Next' /></a>"; } else { TB_PrevCaption = TB_TempArray[TB_Counter].title; TB_PrevURL = TB_TempArray[TB_Counter].href; TB_PrevHTML = "<a href='#' id='TB_prev'><img src='/resources/img/myfun/tbox-prev.gif' width='32' height='32' alt='Previous' /></a>"; } } else { TB_FoundURL = true; TB_imageCount = "Image " + (TB_Counter + 1) + " of " + (TB_TempArray.length); } } } imgPreloader = new Image(); imgPreloader.onload = function () { imgPreloader.onload = null; var pagesize = tb_getPageSize(); var x = pagesize[0] - 150; var y = pagesize[1] - 150; var imageWidth = imgPreloader.width; var imageHeight = imgPreloader.height; if (imageWidth > x) { imageHeight = imageHeight * (x / imageWidth); imageWidth = x; if (imageHeight > y) { imageWidth = imageWidth * (y / imageHeight); imageHeight = y; } } else if (imageHeight > y) { imageWidth = imageWidth * (y / imageHeight); imageHeight = y; if (imageWidth > x) { imageHeight = imageHeight * (x / imageWidth); imageWidth = x; } } TB_WIDTH = imageWidth + 30; TB_HEIGHT = imageHeight + 60; jQuery("#TB_window").append("<a href='#' id='TB_ImageOff' title='Close'><img id='TB_Image' src='" + url + "' width='" + imageWidth + "' height='" + imageHeight + "' alt='" + caption + "' /></a>" + "<p id='TB_footer'>" + TB_PrevHTML + TB_NextHTML + "<span>" + TB_imageCount + " | <em>" + caption + "</em></span></p><a href='#' id='TB_closeWindowButton'><img src='/resources/img/myfun/tbox-close.gif' width='32' height='32' alt='Close' /></a>"); jQuery("#TB_closeWindowButton").click(tb_remove); if (!(TB_PrevHTML === "")) { function goPrev() { if (jQuery(document).unbind("click", goPrev)) { jQuery(document).unbind("click", goPrev); } jQuery("#TB_window").remove(); jQuery("body").append("<div id='TB_window'></div>"); tb_show(TB_PrevCaption, TB_PrevURL, imageGroup); return false; } jQuery("#TB_prev").click(goPrev); } if (!(TB_NextHTML === "")) { function goNext() { jQuery("#TB_window").remove(); jQuery("body").append("<div id='TB_window'></div>"); tb_show(TB_NextCaption, TB_NextURL, imageGroup); return false; } jQuery("#TB_next").click(goNext); } document.onkeydown = function (e) { if (e == null) { keycode = event.keyCode; } else { keycode = e.which; } if (keycode == 27) { tb_remove(); } else if (keycode == 190) { if (!(TB_NextHTML == "")) { document.onkeydown = ""; goNext(); } } else if (keycode == 188) { if (!(TB_PrevHTML == "")) { document.onkeydown = ""; goPrev(); } } }; tb_position(); jQuery("#TB_load").remove(); jQuery("#TB_ImageOff").click(tb_remove); jQuery("#TB_window").css({ position: "fixed", top: "50%", left: "50%", height: "auto", overflow: "auto" }); if (typeof document.body.style.maxHeight === "undefined") { jQuery("#TB_window").css({ position: "absolute" }); }; }; imgPreloader.src = url; } else { var queryString = url.replace(/^[^\?]+\??/, ''); var params = tb_parseQuery(queryString); TB_WIDTH = (params['width'] * 1) + 30 || 630; TB_HEIGHT = (params['height'] * 1) + 40 || 440; ajaxContentW = TB_WIDTH - 30; ajaxContentH = TB_HEIGHT - 45; if (url.indexOf('TB_iframe') != -1) { urlNoQuery = url.split('TB_'); jQuery("#TB_iframeContent").remove(); if (params['modal'] != "true") { jQuery("#TB_window").css({ padding: "15px 15px 48px" }).append("<a href='#' id='TB_closeWindowButton'><img src='/resources/img/myfun/tbox-close.gif' width='32' height='32' alt='Close' /></a><iframe allowtransparency='true' frameborder='0' hspace='0' src='" + urlNoQuery[0] + "' id='TB_iframeContent' name='TB_iframeContent" + Math.round(Math.random() * 1000) + "' onload='tb_showIframe()' style='width:" + (ajaxContentW + 29) + "px;height:" + (ajaxContentH + 17) + "px;' > </iframe>"); } else { jQuery("#TB_overlay").unbind(); jQuery("#TB_window").css({ padding: "15px" }).append("<iframe allowtransparency='true' frameborder='0' hspace='0' src='" + urlNoQuery[0] + "' id='TB_iframeContent' name='TB_iframeContent" + Math.round(Math.random() * 1000) + "' onload='tb_showIframe()' style='width:" + (ajaxContentW + 29) + "px;height:" + (ajaxContentH + 17) + "px;'> </iframe>"); } } else { if (jQuery("#TB_window").css("overflow") != "visible") { if (params['modal'] != "true") { jQuery("#TB_window").css({ padding: "15px 15px 48px" }).append("<a href='#' id='TB_closeWindowButton'><img src='/resources/img/myfun/tbox-close.gif' width='32' height='32' alt='Close' /></a><div id='TB_ajaxContent' style='width:" + ajaxContentW + "px;height:" + ajaxContentH + "px'></div>"); } else { jQuery("#TB_overlay").unbind(); jQuery("#TB_window").css({ padding: "15px" }).append("<div id='TB_ajaxContent' class='TB_modal' style='width:" + ajaxContentW + "px;height:" + ajaxContentH + "px;'></div>"); } } else { jQuery("#TB_ajaxContent")[0].style.width = ajaxContentW + "px"; jQuery("#TB_ajaxContent")[0].style.height = ajaxContentH + "px"; jQuery("#TB_ajaxContent")[0].scrollTop = 0; jQuery("#TB_ajaxWindowTitle").html(caption); } } jQuery("#TB_closeWindowButton").click(tb_remove); if (url.indexOf('TB_inline') != -1) { jQuery("#TB_ajaxContent").append(jQuery('#' + params['inlineId']).children()); jQuery("#TB_window").unload(function () { jQuery('#' + params['inlineId']).append(jQuery("#TB_ajaxContent").children()); }); tb_position(); jQuery("#TB_load").remove(); jQuery("#TB_window").css({ position: "fixed", top: "50%", left: "50%", height: "auto", width: "auto", overflow: "visible" }); if (typeof document.body.style.maxHeight === "undefined") { jQuery("#TB_window").css({ position: "absolute" }); }; } else if (url.indexOf('TB_iframe') != -1) { tb_position(); if (j.browser.safari) { jQuery("#TB_load").remove(); jQuery("#TB_window").css({ display: "block" }); } } else { jQuery("#TB_ajaxContent").load(url += "&random=" + (new Date().getTime()), function () { tb_position(); jQuery("#TB_load").remove(); tb_init("#TB_ajaxContent a.thickbox"); jQuery("#TB_window").css({ position: "fixed", top: "50%", left: "50%", height: "auto", width: "auto", overflow: "visible" }); if (typeof document.body.style.maxHeight === "undefined") { jQuery("#TB_window").css({ position: "absolute" }); }; }); } } if (!params['modal']) { document.onkeyup = function (e) { if (e == null) { keycode = event.keyCode; } else { keycode = e.which; } if (keycode == 27) { tb_remove(); } }; } } catch (e) { } } function tb_showIframe() { jQuery("#TB_load").remove(); jQuery("#TB_window").css({ position: "fixed", top: "50%", left: "50%", height: "auto", overflow: "visible" }); if (typeof document.body.style.maxHeight === "undefined") { jQuery("#TB_window").css({ position: "absolute" }); }; } function tb_remove() { jQuery("#TB_imageOff").unbind("click"); jQuery("#TB_closeWindowButton").unbind("click"); jQuery("#TB_window,#TB_overlay").fadeOut("fast", function () { jQuery('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove(); }); jQuery("#TB_load").remove(); if (typeof document.body.style.maxHeight == "undefined") { jQuery("body", "html").css({ height: "auto", width: "auto" }); jQuery("html").css("overflow", ""); } document.onkeydown = ""; document.onkeyup = ""; return false; } function tb_position() { jQuery("#TB_window").css({ marginLeft: '-' + parseInt((TB_WIDTH / 2), 10) + 'px', width: TB_WIDTH + 'px' }); if (!(jQuery.browser.msie && jQuery.browser.version < 7)) { jQuery("#TB_window").css({ marginTop: '-' + parseInt((TB_HEIGHT / 2), 10) + 'px' }); } } function tb_parseQuery(query) { var Params = {}; if (!query) { return Params; } var Pairs = query.split(/[;&]/); for (var i = 0; i < Pairs.length; i++) { var KeyVal = Pairs[i].split('='); if (!KeyVal || KeyVal.length != 2) { continue; } var key = unescape(KeyVal[0]); var val = unescape(KeyVal[1]); val = val.replace(/\+/g, ' '); Params[key] = val; } return Params; } function tb_getPageSize() { var de = document.documentElement; var w = window.innerWidth || self.innerWidth || (de && de.clientWidth) || document.body.clientWidth; var h = window.innerHeight || self.innerHeight || (de && de.clientHeight) || document.body.clientHeight; arrayPageSize = [w, h]; return arrayPageSize; } function tb_detectMacXFF() { var userAgent = navigator.userAgent.toLowerCase(); if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox') != -1) { return true; } }
