$(function () {

    if ($('h2').text() == ('DVD Montage')) {
    }
    else if ($('h2').text() == ('Debut & Premier Wedding Videography')) {
    }
    else {

        $(".content").each(function () {
            if ($('p', this).is(':visible')) {
                $(this).wrapInner("<div class='scroll-content'></div>");
            }
            if ($('.testimonials, .video', this).is(':visible')) {
                $(".scroll-content").removeClass("scroll-content");
            }
        });
    }

    $(".flickr_set_mid").each(function () {
        $("object param:last", this).before("<param name='wmode' value='transparent'>");
    });
    $(".flickr_set_mid").each(function () {
        $("embed", this).attr("wmode", "transparent");
    });

    $(".free_consultation").each(function () {
        $("a[href*='free-consultation']").addClass("iframe").fancybox({ "frameWidth": 749, "frameHeight": 422, "hideOnContentClick": false, "overlayOpacity": 0.7 });
    });

    $("#home .services .service .desc div, #home #mast .mast .desc div, .price_package div").each(function () {
        $(this).addClass("find_out_more");
    });

    $("#navigation ul").each(function () {
        $("li:first", this).addClass("first");
        if ($(".first", this).hasClass("selected")) {
            $(".first", this).addClass("first_selected").removeClass("selected").removeClass("first");
        }

    });

    $("navigation ul:last li:last", this).addClass("last");
    if ($(".last", this).hasClass("selected")) {
        $(".last", this).addClass("last_selected").removeClass("selected").removeClass("last");
    }

    $("#navigation ul li ul").each(function () {
        $(".first", this).removeClass("first");
    });

    $("#navigation ul:last").each(function () {

        $(".last", this).removeClass("last");
        $("li:last", this).parent().parent().attr("style", "border: none; background: none;").addClass("last");

    });

    if ($(".last", this).hasClass("selected")) {
        $(".last", this).addClass("last_selected").removeClass("selected").removeClass("last");
    }

    $("#navigation ul li").hover(function () {
        $("ul", this).show().parent().addClass("selected").parent();
    }, function () {
        $("ul", this).hide().parent().removeClass("selected").parent();
    });

    var ua = $.browser;
    if (ua.safari && ua.version.slice(0, 3) == "533") {
        $("#navigation ul").addClass("safari");

    }
    else if (ua.safari && ua.version.slice(0, 3) == "534") {
        $("#navigation ul").addClass("safari");

    }


    $(".contact_us form, .pop_up_right form").wrap("<div class='mm_form'></div>");
    // Capture Form    
    $(".mm_form tr").each(function () {
        $("td:first", this).addClass("label");
        $("td:last", this).addClass("input");
    });
    $(".mm_form .label").wrapInner("<div></div>");
    $(".mm_form textarea").parent().addClass("textarea");
    $(".mm_form").each(function () {
        $("input:last", this).addClass("SubmitButton");
        $(".label:last", this).hide();
        $("tr:last", this).addClass("SubmitButtonTR");
        $("td:last", this).addClass("SubmitButtonTD");
        $(".SubmitButtonTD", this).removeClass("input");
        $("textarea", this).parent().removeClass("input");
        $("textarea", this).parent().addClass("textarea");
        $("form", this).addClass("form");
        $(".textarea", this).prev().addClass("textarea_label");
        $(".textarea_label", this).removeClass("label");
    });
    $(".mm_form tr").each(function () {
        var labelText = $(".label", this).text();
        var labelTextArea = $(".textarea_label", this).text();
        $(".input input", this).val(labelText);
        $(".textarea textarea", this).val(labelTextArea);
    });
    $(".mm_form .input input, .mm_form .textarea textarea").each(function () {
        var thisObj = $(this);
        var thisVal = thisObj.val();
        thisObj.bind("focus", function () {
            if (thisObj.val() == thisVal) { thisObj.val(""); }
        }).bind("blur", function () {
            if (thisObj.val() == "") { thisObj.val(thisVal); }
        });
    });

    if ($(".image_banner_text p").text() == "") {
        $(".image_banner_text").hide();
    }

    $(".disc_only_location:first").before("<div id='locations_header'></div>");
    var locationsHeader = $(".locations_header").html();
    $("#locations_header").html(locationsHeader);

    $(".disc_only_location").wrapAll("<div class='location_slide'></div>");


    $(".disc_only_locations").each(function () {
        $(".disc_only_location:eq(0), .disc_only_location:eq(1)", this).wrapAll("<div class='two_locations'></div>");
        $(".disc_only_location:eq(2), .disc_only_location:eq(3)", this).wrapAll("<div class='two_locations'></div>");
        $(".disc_only_location:eq(4), .disc_only_location:eq(5)", this).wrapAll("<div class='two_locations'></div>");
        $(".disc_only_location:eq(6), .disc_only_location:eq(7)", this).wrapAll("<div class='two_locations'></div>");
        $(".disc_only_location:eq(8), .disc_only_location:eq(9)", this).wrapAll("<div class='two_locations'></div>");
        $(".disc_only_location:eq(10), .disc_only_location:eq(11)", this).wrapAll("<div class='two_locations'></div>");
        $(".disc_only_location:eq(12), .disc_only_location:eq(13)", this).wrapAll("<div class='two_locations'></div>");
        $(".disc_only_location:eq(14), .disc_only_location:eq(15)", this).wrapAll("<div class='two_locations'></div>");
        $(".disc_only_location:eq(16), .disc_only_location:eq(17)", this).wrapAll("<div class='two_locations'></div>");
        $(".disc_only_location:eq(18), .disc_only_location:eq(19)", this).wrapAll("<div class='two_locations'></div>");
        $(".disc_only_location:eq(20), .disc_only_location:eq(21)", this).wrapAll("<div class='two_locations'></div>");


        var pagingItems = Math.ceil(eval($(".two_locations").length - 1) / 1);
        var countItems = 1;
        while (countItems <= pagingItems + 1) {
            $(".disc_only_locations .paging").append("<span id=\"" + countItems + "\">" + countItems + "</span>");
            countItems++;
        }
        $(".disc_only_locations .paging span:first").addClass("active");
        $(".disc_only_locations .paging span").click(function () {
            $(".paging span").removeClass("active");
            $(this).addClass("active");
            var pageNumber = $(this).attr("id") - 1;
            $(".disc_only_locations .two_locations").animate({ "left": "-" + eval(pageNumber * 501) + "px" });
        });

    });

    $(".two_locations").each(function () {
        $(".disc_only_location:odd", this).attr("style", "float: right");
    });

    $(".location_slide").wrap("<div id='location_slide'></div>");

    var photo = $(".photos .content_right_photos .latest:first").html();
    $(".photos .content_right_photos").html(photo);
    $(".photos .content_right_photos .latest").show();

    var photoInfo = $(".photos .photo_info .latest:first").html();
    $(".photos .photo_info").html(photoInfo);
    $(".photos .photo_info .latest").show();

    var quote = $("#footer_middle .testimonials .testimonial:first").show();

    $(".footer_special_offers .footer_special_offer:eq(0), .footer_special_offers .footer_special_offer:eq(1)").show();
    $(".footer_special_offers .footer_special_offer:eq(2)").attr("style", "margin: 0; border: none;").show();

    $(".content_left_wide .services").each(function () {
        var pagingItems1 = Math.ceil(eval($(".services .service").length - 3) / 3);
        var countItems = 1;
        while (countItems <= pagingItems1 + 1) {
            $(".services .paging").append("<span id=\"" + countItems + "\">" + countItems + "</span>");
            countItems++;
        }
        $(".services .paging span:first").addClass("active");
        $(".services .paging span").click(function () {
            $(".paging span").removeClass("active");
            $(this).addClass("active");
            var pageNumber = $(this).attr("id") - 1;
            $(".services .service").animate({ "top": "-" + eval(pageNumber * 515) + "px" });
        });
    });

    $(".content_left_wide .services .service:nth-child(3n+3)").attr("style", "border-bottom: #fff;");

    $(".services_left_right").each(function () {
        var pagingItems1 = Math.ceil(eval($(".services_left_right .service").length - 1) / 1);
        var countItems = 1;
        while (countItems <= pagingItems1 + 1) {
            $(".services_left_right .paging").append("<span id=\"" + countItems + "\">" + countItems + "</span>");
            countItems++;
        }
        $(".services_left_right .paging span:first").addClass("active");
        $(".services_left_right .paging span").click(function () {
            $(".paging span").removeClass("active");
            $(this).addClass("active");
            var pageNumber = $(this).attr("id") - 1;
            $(".services_left_right .service").animate({ "left": "-" + eval(pageNumber * 523) + "px" });
        });
    });

    $(".content_left_wide .testimonials").each(function () {
        var pagingItems1 = Math.ceil(eval($(".content_left_wide .testimonials .testimonial").length - 3) / 3);
        var countItems = 1;
        while (countItems <= pagingItems1 + 1) {
            $(".content_left_wide .testimonials .paging").append("<span id=\"" + countItems + "\">" + countItems + "</span>");
            countItems++;
        }
        $(".content_left_wide .testimonials .paging span:first").addClass("active");
        $(".content_left_wide .testimonials .paging span").click(function () {
            $(".paging span").removeClass("active");
            $(this).addClass("active");
            var pageNumber = $(this).attr("id") - 1;
            $(".content_left_wide .testimonials .testimonial").animate({ "top": "-" + eval(pageNumber * 486) + "px" });
        });
    });

    $(".capture_form_image_desc").prev().addClass("razor");
    $(".razor:contains('Error')").hide();

    $(".content_right_narrow .testimonials").each(function () {
        $(".testimonial:eq(0)", this).show();
        $(".testimonial:eq(1)", this).show().addClass("hide_image");
    });

    var url = window.location;

    $(".photo_info .like").each(function () {
        $(this).html("<fb:like href='" + url + "' layout='standard' show-faces='true' width='450' action='like' colorscheme='light' font='arial'></fb:like>");
    });

    $(".content_left_wide .like").each(function () {
        $(this).html("<fb:like href='" + url + "' layout='standard' show-faces='true' width='260' action='like' colorscheme='light' font='arial'></fb:like>");
    });

    /**Form Validation**/
    var fullname = $("#CustomFields_831_578").val();
    var date = $("#CustomFields_634_578").val();


    $(".validate").click(function () {
        if ($("#CustomFields_831_578").val() == fullname

     ) {
            alert("Please fill out your full name");
        } else if ($("#CustomFields_634_578").val() == date) {
            alert("Please fill out your wedding date");
        } else {
            $(".SubmitButtonTD input").trigger('click');
        }
    });

    var fullname2 = $("#CustomFields_831_574").val();
    var date2 = $("#CustomFields_634_574").val();


    $(".validate_right").click(function () {
        if ($("#CustomFields_831_574").val() == fullname2) {
            alert("Please fill out your full name");
        } else if ($("#CustomFields_634_574").val() == date2) {
            alert("Please fill out your wedding date");

        } else {
            $(".SubmitButtonTD input").trigger('click');
        }
    });


});

