$(function() {
    $(".askQuestionTxt").html($("#askQuestion_cms_text").html());
    $(".stayConnectedTxt").html($("#signIn_cms_text").html());

    $(".header_ask_button").click(function() {
        $("#askQuestion").dialog('open');
        iniMaskClose("#askQuestion");
    });
    //   $(".effortless_getstarted").click(function() {
    //     $("#askQuestion").dialog('open');
    //   });
    $(".apartment_check_availability_button").click(function() {
        $("#askQuestion").dialog('open');
        iniMaskClose("#askQuestion");
        return false;
    });
    $(".suggest_story_btn").click(function() {
        $("#mystory").dialog('open');
        iniMaskClose("#mystory");
    });
    $(".privacy_policy").click(function() {
        $("#privacy").dialog('open');
        iniMaskClose("#privacy");
    });

    $(".opt_in_privacy").click(function() {
        $("#privacy").dialog('open');
        iniMaskClose("#privacy");
    });
    $(".legal_information").click(function() {
        $("#privacy").dialog('open');
        iniMaskClose("#privacy");
    });
    $(".login_button").click(function() {
        $("#signIn").dialog('open');
        $("#sbs_name").val($("#inName").val());
        $("#sbs_email").val($("#inEmail").val());
        iniMaskClose("#signIn");
    });
    $("#keep_up").click(function() {
        $("#shareit").dialog('open');
        $(".stico_default").mouseover();
        $("#stwrapper").show();
        iniMaskClose("#shareit");
    });
	$('select.wpcf7-select').css({
		'width' : '132px',
		'margin-top' : '10px',
		'margin-left' : '0'
	});
	$('.wpcf7-response-output').click(function() {
		$(this).fadeOut();
	});
	$('.contactTest .contact_receive_updates.wpcf7-radio').prepend('<label>Would you like to receive email updates about news and events at Greenwood Village?</label>');
	
    $("#askQuestion").dialog({
        modal: true,
        autoOpen: false,
        resizable: false,
        closeOnEscape: true,
        width: 642,
        height: 450
    });
    $("#mystory").dialog({
        modal: true,
        autoOpen: false,
        resizable: false,
        closeOnEscape: true,
        width: 642,
        height: 450
    });
    $("#signIn").dialog({
        modal: true,
        autoOpen: false,
        resizable: false,
        closeOnEscape: true,
        width: 645,
        height: 390
    });
    $("#privacy").dialog({
        modal: true,
        autoOpen: false,
        resizable: false,
        closeOnEscape: true,
        width: 645,
        height: 390
    });

    if ($.browser.mozilla) {
        setTimeout(function() {
            $("#shareit").dialog({
                modal: true,
                autoOpen: false,
                resizable: false,
                closeOnEscape: true,
                width: 692,
                height: 440
            });
            $("body").click(function() { if ($("#shareit").parent().is(':visible')) { $(".stico_default").mouseover(); } });
            $("body").mousemove(function() { if ($("#shareit").parent().is(':visible')) { $(".stico_default").mouseover(); } });
        }, 10000);
    }
    else {
        $("#shareit").dialog({
            modal: true,
            autoOpen: false,
            resizable: false,
            closeOnEscape: true,
            width: 692,
            height: 490
        });
        $("body").click(function() { if ($("#shareit").parent().is(':visible')) { $(".stico_default").mouseover(); } });
        $("body").mousemove(function() { if ($("#shareit").parent().is(':visible')) { $(".stico_default").mouseover(); } });
    }

    /*$("body").click(function() { if ($("#shareit").parent().is(':visible')) { $(".stico_default").mouseover(); } });
    $("body").mousemove(function() { if ($("#shareit").parent().is(':visible')) { $(".stico_default").mouseover(); } });*/
    if ($.browser.safari) {
        $(".contentemploy2").css("width","75px");
        $(".zip").css("margin-left","0px");
        $(".ceckin").css("margin-top","6px");
        $(".ceckin2").css("margin-top","6px");
        $(".ceckin3").css("margin-top","6px");
        $(".ceckin4").css("margin-top","6px");
        $(".ceckin5").css("margin-top","2px");
        $("input").css("padding-left","3px !important");
        $(".inf_about").css("width","128px");
        $("input[id~=inName]").css("width","124px");
        $("input[id~=inEmail]").css("width","124px");
        $("select[name~=contact_phone_type]").css("width","124px");
    }
    if ($.browser.mozilla) {
        $("textarea[name=contact_text]").css("margin-bottom","5px");
    }

    if ($.browser.ie) {
        $("select[name=ask_name]").css("width","130px !important");
        $("select[name=ask_email]").css("width","130px !important");
        $("select[name=ask_phone]").css("width","130px !important");
        $("select[name=ask_zip]").css("margin-left","0px !important");
    }

    // Increase Font Size
    $(".increaseFont").click(function() {
        var currentFontSize = $('html').css('font-size');
        var currentFontSizeNum = parseFloat(currentFontSize, 10);
        var newFontSize = currentFontSizeNum + 2;
        if (newFontSize <= 22) {
            $('html').css('font-size', newFontSize);
        }
        return false;
    });
    // Decrease Font Size
    $(".decreaseFont").click(function() {
        var currentFontSize = $('html').css('font-size');
        var currentFontSizeNum = parseFloat(currentFontSize, 10);
        var newFontSize = currentFontSizeNum - 2
        if (newFontSize >= 16) {
            $('html').css('font-size', newFontSize);
        }
        return false;
    });

    if (($(".slider_div").size() > 0) || $(".slider_div_home").size() > 0) {
        current = 0;
        setTimeout(function() { show_next_slide(); }, milisekund);
    }
});

function iniMaskClose(obj) {
	$(".ui-widget-overlay").click(function() {
		$(obj).dialog('close');
		$("#stwrapper").hide();
	});
}

function Input_Change(pInput, txt) {
    if ($(pInput).val() == txt) {
        $(pInput).val("");
    }
}

function Input_Changed(pInput, txt) {
    if ($(pInput).val() == "") {
        $(pInput).val(txt);
    }
}

function Changemailupdates(pCheckBox) {
        $(pCheckBox).parent().parent().children().find("input[name=ask_mailupdates]").attr('checked', false);
        $(pCheckBox).parent().parent().children().find("span.checkbox").css("backgroundPosition", "0 0");
        $(pCheckBox).attr('checked', true);
        $(pCheckBox).prev().css("backgroundPosition", "0 -50px");
}

function closeprivacy() {
    $("#privacy").dialog('close');
    return false;
}

function closeaskQuestion() {
    $("#askQuestion").dialog('close');
    return false;
}
function closemystory() {
    $("#mystory").dialog('close');
    return false;
}

function closesignIn() {
    $("#signIn").dialog('close');
    return false;
}

function closeshareit() {
    $("#shareit").dialog('close');
    $("#stwrapper").hide();
    return false;
}

function closeThankYou() {
    $("#ThankYou").dialog('close');
}

var milisekund=4000;
var current=0;

function show_next_slide() {

    current++;
	if(typeof(banners)!="undefined"){
		if (current > banners) {
			current = 0;
		}

		showSliderImage(current);

		setTimeout(function() { show_next_slide(); }, milisekund);
	}
}


function showSliderImage(num) {
    current = num;

    $(".navigationSliderLink").removeClass('activeSliderLink');

     if (jQuery.browser.msie) {
         $(".headerimage").not($(".headerimage" + current)).hide();
        /*$(".headerimage" + current).fadeIn(100, function() {
            if (jQuery.browser.msie) {
                $(".headerimage" + current)[0].style.filter = "";
            }
        });*/
    }
    else {
    $(".headerimage").not($(".headerimage" + current)).fadeOut(1000, function() {
        if (jQuery.browser.msie)
            ($(".headerimage").not($(".banner" + current)))[0].style.filter = "";
    });
	}

    if (jQuery.browser.msie) {
        $(".headerimage" + current).show();
        /*$(".headerimage" + current).fadeIn(100, function() {
            if (jQuery.browser.msie) {
                $(".headerimage" + current)[0].style.filter = "";
            }
        });*/
    }
    else {
        $(".headerimage" + current).fadeIn(1000, function() {
            if (jQuery.browser.msie) {
                $(".headerimage" + current)[0].style.filter = "";
            }
        });
    }

    $(".navigationSliderLink" + current).addClass('activeSliderLink');

    return false;
}

function showPrevSliderImage() {
    current--;
    if (current < 0) {
        current = banners;
    }

    showSliderImage(current);

    return false;
}


function showNextSliderImage() {
    current++;

    if (current > banners) {
        current = 0;
    }

    showSliderImage(current);
    return false;
}

function submitmystory() {
    $.post(ThemeURL + "/footer.php", $("#frm_mystory").serialize(), function(data) {
        $("#Thank_You_Text").html(data);
        $("#ThankYou").dialog({
            modal: true,
            autoOpen: false,
            resizable: false,
            closeOnEscape: true,
            width: 645,
            height: 390
        });
        $("#mystory").dialog('close');
		$("#ThankYou").dialog('open');
        iniMaskClose("#ThankYou");
    });
    return false;
}

function submitsignIn() {
    $.post(ThemeURL + "/footer.php", $("#frm_signIn").serialize(), function(data) {
        $("#Thank_You_Text").html(data);
        $("#ThankYou").dialog({
            modal: true,
            autoOpen: false,
            resizable: false,
            closeOnEscape: true,
            width: 645,
            height: 390
        });
        $("#signIn").dialog('close');
		$("#ThankYou").dialog('open');
        iniMaskClose("#ThankYou");
    });
    return false;
}

function submitaskQuestion() {
    $.post(ThemeURL + "/footer.php", $("#frm_askQuestion").serialize(), function(data) {
        $("#Thank_You_Text").html(data);
        $("#ThankYou").dialog({
            modal: true,
            autoOpen: false,
            resizable: false,
            closeOnEscape: true,
            width: 645,
            height: 390
        });
        $("#askQuestion").dialog('close');
		$("#ThankYou").dialog('open');
        iniMaskClose("#ThankYou");
    });
    return false;
}

function submitContactUs() {
    $("#frm_ContactUs").submit();
    return true;
}

function submitEmployment() {
    $("#frm_ContactUs").submit();
    return true;
}

