﻿$(document).ready(function() {
    addCarousel();
    addTableStyle();
    addGalleryTabs();
    addColumnHeights();
    addGallery();
});

function addCarousel() {
    if ($(".carousel").length > 0) {
        if ($(".carouselPane li").length < 4) {
            $(".carousel").carousel({
                vertical: false,
                scrollNext: ".next",
                scrollPrev: ".prev",
                scrollNum: 0,
                scrollVisible: 4,
                circular: false,
                itemHeight: 100,
                itemWidth: 100,
                scrollSpeed: 500
            });
            $(".carousel .next").css("display", "none");
            $(".carousel .prev").css("display", "none");
            $(".carouselPane ul").css("background", "#ffffff");
            $(".carouselPane").css("margin", "0px");
        }
        else {
            $(".carousel").carousel({
                vertical: false,
                scrollNext: ".next",
                scrollPrev: ".prev",
                scrollNum: 4,
                scrollVisible: 4,
                circular: true,
                itemHeight: 100,
                itemWidth: 102,
                scrollSpeed: 500
            });
        };
        if ($.browser.msie) {
            if ($.browser.version == "6.0") {
                alignImages();
            }
        }
    };
}

function alignImages() {
    // dirty hack for ie 6 - stupid browser !!!
    $(".carouselPane li").append("<span style='height:100px;display:inline-block;width:1px;color:#fff'>.</span>");
    $(".carouselPane li").prepend("<span style='height:100px;display:inline-block;width:1px;color:#fff'>.</span>");
}

function addTableStyle() {
    $(".zebra tr:odd").each(function() {
        $(this).children("td").css("background", "#fafafa");
    });

    $(".eventPrices tr").each(function() {
        $(this).children("th:gt(0)").css("padding-left", "1px");
        $(this).children("td:gt(0)").css("border-left", "1px dotted #999999");
    });
}

function addGalleryTabs() {
    $(".galleryThumbs .tabs li").hover(function() {
        $(this).addClass("hover");
    },
	function() {
	    $(this).removeClass("hover");
	});

//    $(".galleryThumbs .tabs li a").click(function() {
//        parentItem = $(this).parent("li");
//        tabIndex = parentItem.parent("ul").children("li").index(parentItem);
//        $(".galleryThumbs .galleryAlbum").removeClass("galleryActive"); ;
//        $(".galleryThumbs .galleryAlbum:eq(" + tabIndex + ")").addClass("galleryActive");
//        parentItem.siblings().removeClass("active");
//        parentItem.addClass("active");
//        return false;
//    });

}

function addColumnHeights() {
    var leftHeight = $(".leftCol").height();
    var middleHeight = $(".midCol").height();
    var rightHeight = $(".rightCol").height();

    if (leftHeight > middleHeight && leftHeight > rightHeight) {
        $(".midCol").height(leftHeight);
        $(".rightCol").height(leftHeight);
    }
    else if (middleHeight > leftHeight && middleHeight > rightHeight) {
        $(".leftCol").height(middleHeight);
        $(".rightCol").height(middleHeight);
    }
    else if (rightHeight > leftHeight && rightHeight > middleHeight) {
        $(".leftCol").height(rightHeight);
        $(".middleCol").height(rightHeight);
    }
}

function addGallery() {
    $(".gallery .carouselPane li a").click(function() {
        targetImg = $(this).attr("href");
        $(".galleryPane img").attr("src", targetImg);
        return false;
    });
} //custom submit function to prevent double submit on standard .net submit input. This method modify click function and peform manual validation and postback
function preventDoubleSubmit() {
    $('input[type=submit].preventDoubleSubmit').click(function() { //we need to be specific because we still want cancel button to work
        Page_ClientValidate();
        if (Page_IsValid) {
            $(this).css("background", "#E5E5E5");
            $(this).css("color", "#333");
            $(this).css("border", "1px solid #333");
            $(this).attr('disabled', 'disabled');
            __doPostBack($(this).attr('name'), ''); //if postback is not manually called then it wont fall into the button click event because submit input is disabled
        }
    });
    $('a.preventDoubleSubmit').click(function() {
        Page_ClientValidate();
        if (Page_IsValid) {
            $(this).css("background", "#E5E5E5");
            $(this).css("color", "#333");
            $(this).css("border", "1px solid #333");
            $(this).unbind("click").click(function(e) {
                e.preventDefault();
            });
        }
    });
}

