//build menu with DIV ID="myslidemenu" on page:
droplinemenu.buildmenu("droplinetabs1");

jQuery.fn.fadeToggle = function (speed, easing, callback) {
    return this.animate({
        opacity: 'toggle'
    }, speed, easing, callback);
};

$("input[type=checkbox][checked]").size();

$(document).ready(function () {
    $(".show_text").click(function () {
        $(".show_text").hide();
        $("#show_text").show();
    });

    $(".hide_text").click(function () {
        $(".show_text").show();
        $("#show_text").hide();
    });

    $(".show_text2").click(function () {
        $(".show_text2").hide();
        $("#show_text2").show();
    });

    $(".hide_text2").click(function () {
        $(".show_text2").show();
        $("#show_text2").hide();
    });

    $(".show_text3").click(function () {
        $(".show_text3").hide();
        $("#show_text3").show();
    });

    $(".hide_text3").click(function () {
        $(".show_text3").show();
        $("#show_text3").hide();
    });

    $("#list_container li").click(function () {
        $("#list_container li").removeClass("active");
        $(this).children().removeClass("hover");
        $(this).addClass("active");
        var number = $(this).attr("id").replace("list-", "");
        $(".content_div").removeClass("active");
        $("#content-" + number).addClass("active");
    });

    $("#list_container li div").hover(

    function () {
        if (!$(this).parent().hasClass("active")) {
            $(this).addClass("hover");
        }
    }, function () {
        $(this).removeClass("hover");
    });

/*$("#products_tab").hover(
	function()
	{
		var src=$("#products_tab img").attr('src');
		src=src.replace(".jpg","-R.jpg");
		$("#products_tab img").attr('src',src);
	},
	function()
	{
		var src=$("#products_tab img").attr('src');
		src=src.replace("-R.jpg",".jpg");
		$("#products_tab img").attr('src',src);
	});
	
	$("#services_tab").hover(
	function()
	{
		var src=$("#services_tab img").attr('src');
		src=src.replace(".jpg","-R.jpg");
		$("#services_tab img").attr('src',src);
	},
	function()
	{
		var src=$("#services_tab img").attr('src');
		src=src.replace("-R.jpg",".jpg");
		$("#services_tab img").attr('src',src);
	});*/

    $("#products_tab").click(function () {
/*$("#products_categories").show();
		$("#services_categories").hide();*/
        window.location = '/products';
    });

    $("#services_tab").click(function () {
/*$("#services_categories").show();
		$("#products_categories").hide();*/
        window.location = '/services';
    });

    //image rotator
    //$('.rotate_images').cycle({fx:'fade',speed:1000});
    //news and events tabs
    $("#news_events_tabs").tabs();
    $("#understanding_agedacare_tabs").tabs();
    $("#facility_listing_tabs").tabs();

    var $understanding_agedacare_tabs = $("#understanding_agedacare_tabs").tabs();
    var $facility_listing_tabs = $('#facility_listing_tabs').tabs(); // first tab selected
    // Advanced Search
    //$("div.cornered_bottom_background").corner("bottom");
    //$("div.cornered_top_background").corner("bottom");
/*$("#sitesponsors_outer").corner();
	$("#sitesponsors_inner").corner();
	$("#main_search_map").corner();*/

    //advertiser login
    //$("#advertiser_bottom").corner();
    //$("#advertiser_left").corner();
    $("#advanced-checkbox :input").click(function () {
        advancedSearchHide($(this).val());
    });

    $("#ContactState").change(function () {
        $("#autoComplete").attr('value', '');
    });

    $("#wa").mouseover(

    function () {
        $("#search_map_logo").attr('src', '/img/search_map/western_australia.gif');
    });
    $("#wa").mouseout(

    function () {
        $("#search_map_logo").attr('src', '/img/search_map/main_image.gif');
    });

    $("#nt").mouseover(

    function () {
        $("#search_map_logo").attr('src', '/img/search_map/northern_territory.gif');
    });
    $("#nt").mouseout(

    function () {
        $("#search_map_logo").attr('src', '/img/search_map/main_image.gif');
    });

    $("#qld").mouseover(

    function () {
        $("#search_map_logo").attr('src', '/img/search_map/queensland.gif');
    });
    $("#qld").mouseout(

    function () {
        $("#search_map_logo").attr('src', '/img/search_map/main_image.gif');
    });

    $("#nsw").mouseover(

    function () {
        $("#search_map_logo").attr('src', '/img/search_map/nsw_act.gif');
    });
    $("#nsw").mouseout(

    function () {
        $("#search_map_logo").attr('src', '/img/search_map/main_image.gif');
    });

    $("#vic").mouseover(

    function () {
        $("#search_map_logo").attr('src', '/img/search_map/victoria.gif');
    });
    $("#vic").mouseout(

    function () {
        $("#search_map_logo").attr('src', '/img/search_map/main_image.gif');
    });

    $("#tas").mouseover(

    function () {
        $("#search_map_logo").attr('src', '/img/search_map/tasmania.gif');
    });
    $("#tas").mouseout(

    function () {
        $("#search_map_logo").attr('src', '/img/search_map/main_image.gif');
    });

    $("#sa").mouseover(

    function () {
        $("#search_map_logo").attr('src', '/img/search_map/south_australia.gif');
    });
    $("#sa").mouseout(

    function () {
        $("#search_map_logo").attr('src', '/img/search_map/main_image.gif');
    });

    function advancedSearchHide(show) {
        switch (show) {
        case 'p':
            $("#CategoryList").hide();
            $("#ServiceList").hide();
            $("#ProductList").show();
            break;
        case 's':
            $("#CategoryList").hide();
            $("#ServiceList").show();
            $("#ProductList").hide();
            break;
        default:
            $("#CategoryList").show();
            $("#ServiceList").hide();
            $("#ProductList").hide();
        }
    }
    advancedSearchHide($("#advanced-checkbox :input").val());
    $("#advanced-checkbox :input:checked").click();
    $("div#priority input:checkbox").attr('checked', false);
    $("div#catlistings input:checkbox").attr('checked', false);

    function totalcost() {
        $("span.total").empty().append($("input:checkbox:checked[class=cat]").size());

        var catamount = $("input:checkbox:checked[class=cat]").size() * 500;
        $("span.totalnogast").empty().append(catamount);
        var featureamount = $("#featureamount").val() * 99;
        if ($("#ProductFeatureNo:checked").size() == 1) {
            featureamount = 0;
            featurelength = 0;
            $("#feature-hide").hide();
        }
        else {
            featurelength = $("#featureamount").val();
            $("#feature-hide").show();
        }
        $("span.featuretotal").empty().append(featureamount);
        $("#feature").empty().append(featureamount);
        var listinglength = $("#listinglength").val();
        if ($("#ProductListingNo:checked").size() == 1) {
            listinglength = 0;
            $("#listing-hide").hide();
            $("#priority").hide();
            $("div#priority input:checkbox").attr('checked', false);
        }
        else {
            $("#listing-hide").show();
            $("#priority").show();
        }
        var priority = $("div#priority input:checkbox:checked").size() * 180 * $("#listinglength").val();
        $("span#months").empty().append(featurelength);
        $("span#prioritysize").empty().append($("div#priority input:checkbox:checked").size());
        $("span.prioritycost").empty().append(priority);
        $("#prioritymonth").empty().append(listinglength);
        $("#grandtotal").empty().append((parseInt(catamount) + parseInt(priority) + parseInt(featureamount)));
        $("#gst").empty().append(Math.round((parseInt(catamount) + parseInt(priority) + parseInt(featureamount)) * .1 * 100) / 100);
        var supergrandtotal = Math.round((parseInt(catamount) + parseInt(priority) + parseInt(featureamount)) * 1.1 * 100) / 100;
        $("#supergrandtotal").empty().append(supergrandtotal);
        if (supergrandtotal == 0) $("input:submit").hide();
        else $("input:submit").show();

    }
    totalcost();
    $("#ProductFeatureYes").click(function () {
        totalcost();

    });

    $("div.checkbox input").click(function () {
        totalcost();
    });

    $("#featureamount").change(function () {
        totalcost();
        $("#featuregrandtotal").empty().append(this.value * 99);
        $("#featuregst").empty().append(Math.round(((this.value * 99) * .1) * 100) / 100);
        $("#featuresupergrandtotal").empty().append(Math.round(((this.value * 99) * 1.1) * 100) / 100);
        $("#featuregrandtotal").empty().append(this.value * 99);

    });
    $("#listinglength").change(function () {
        totalcost();
    });

    $("span#total").append($("input:checkbox:checked").size());
    $("#amounttop").change(function () {
        $("span#totall").empty();
        $("span#totall").append(Math.round($(this).val() * 500 * 1.1));
        $("input[name='totalamount']").attr('value', Math.round($(this).val() * 500 * 1.1));
        $("#grandtotal").empty();
        $("#grandtotal").append($("input:radio:checked[class=featured]").val());
        $("input[name='a3']").attr('value', Math.round($(this).val() * 500 * 1.1) + $("input:radio:checked[class=featured]").val());
        $("input[name='buyamount']").attr('value', $(this).val());
        $("input[name='item_name']").attr('value', $(this).val() + " Credit(s) for Paid Listings - NaturalHealthGuide.com.au")

    });


    $("input:checkbox[id=nocat]").click(function () {
        var checkValues = [];
        $('input:checkbox[class=cat]:checked').each(function () {
            $("#Product" + $(this).val()).hide();
            $("#Product" + $(this).val() + " input:checkbox").removeAttr("checked");
            $("#Service" + $(this).val()).hide();
            $("#Service" + $(this).val() + " input:checkbox").removeAttr("checked");
            $("#Category" + $(this).val()).hide();
            $("#Category" + $(this).val() + " input:checkbox").removeAttr("checked");
            checkValues.push($(this).val());
        });
        var checkSegmentStatus = checkValues.join(",");

        fireunit.ok(false, checkSegmentStatus);
        $("input:checkbox[class=cat]").removeAttr("checked");
        totalcost();
    });

    $("input:checkbox[class=cat]").click(function () {
        $("span#freelistingselected").empty();
        $("input:checkbox[id=nocat]").removeAttr("checked");
        totalcost();

    }

    );

    $("div#catlistings input:checkbox").click(function () {
        if ($(this).is(':checked')) {
            $("#Product" + this.value).show();
        }
        else {
            $("#Product" + this.value).hide();
            $("#Product" + this.value + " input:checkbox").removeAttr("checked")
        }

        if ($(this).is(':checked')) {
            $("#Service" + this.value).show();
        }
        else {
            $("#Service" + this.value).hide();
            $("#Service" + this.value + " input:checkbox").removeAttr("checked")
        }

        if ($(this).is(':checked')) {
            $("#Category" + this.value).show();
        }
        else {
            $("#Category" + this.value).hide();
            $("#Category" + this.value + " input:checkbox").removeAttr("checked")
        }

        totalcost();
    }

    );

    $("div#priority input:checkbox").click(function () {
        $("input:checkbox[id=nopiority]").removeAttr("checked")
        totalcost();
    }

    );

    $("span.totalnogast").empty();
    $("span.totalnogast").append($("input:checkbox:checked[class=cat]").size() * 500);

    $("input:radio[id=nofeatured]").click(function () {
        $("#featuretext").hide();
        $("#feature").empty();
        //alert($("input:radio:checked[class=featured]").val());
        totalcost();
    })

    $("input:radio[id=featured]").click(function () {
        $("#feature").empty();
        alert($("input:radio:checked[class=featured]").val());
        totalcost();
    });

    $("input:radio[id=listing]").click(function () {
        $("#listing").empty();
        //alert(Math.round($("input:checkbox:checked[class=cat]").size() * 500 + parseInt($("input:radio:checked[class=featured]").val()) + parseInt($("input:radio:checked[class=listing]").val()));
        totalcost();
    });

    $("input:radio[id=nolisting]").click(function () {
        $("#listing").empty();
        //alert(Math.round($("input:checkbox:checked[class=cat]").size() * 500 + parseInt($("input:radio:checked[class=featured]").val()) + parseInt($("input:radio:checked[class=listing]").val()));
        $("#listingtext").show();
        $("#listing").append($("input:radio:checked[class=listing]").val());
        totalcost();
    });

    $(".free-cats").click(function () {
        $(".chosenfreecat").empty();
        $(".chosenfreecat").append($(".free-cats>input:checked").attr('title'));
    });

    $("input:radio['title=catcon']").click(function () {
        $("span.catcon").empty();
        $("span.catcon").append();
    });

    //totalcost();
    $("#step2").click(function () {
        $("#divstep2").show();
    });

    $("#step3").click(function () {
        $("#divstep3").show();
    });

    $("#summary").click(function () {
        $("#divsummary").show();
    });

    $("#ContactFirstName").change(function () {
        $("span.customerfname").empty();
        $("span.customerfname").append($("#ContactFirstName").val());
        $(".FirstName").attr('value', $("#ContactFirstName").val());
    });

    $(".FirstName").change(function () {
        $(".FirstName").attr('value', $(".FirstName").val());
        $("#hiddenfirstname").attr('value', $(".FirstName").val());
    });

    $("#followupname").change(function () {
        $("span.followupname").empty();
        $("span.followupname").append($("#followupname").val());
    });
    $("#ContactLastName").change(function () {
        $("span.customerlname").empty();
        $("span.customerlname").append($("#ContactLastName").val());
        $("#LastName").attr('value', $("#ContactLastName").val());
    });


    $("#CompanyName").change(function () {
        $("span.companyname").empty();
        $("span.companyname").append($("#CompanyName").val());
    });

    $("input:radio[id=callback1]").click(function () {
        $("div#leavemessage").show();
    });

    $("input:radio[id=unable_to_find_phone]").click(function () {
        $("div#nophone").show();
    });

    $("input:radio[id=follow]").click(function () {
        $("div#follow-up").show();
    });

    $(".FirstName").change(function () {
        $("span.customerfname").empty();
        $("span.customerfname").append($(".FirstName").val());
    });
    $("#tmpname").change(function () {
        $("span.tmpname").empty();
        $("span.tmpname").append($("#tmpname").val());
        $("#followupname").attr('value', $("#tmpname").val());
    });

    $("input").change(function () {
        $("#" + $(this).attr('title')).attr('value', $(this).val())
    });

    $("div.subscriber-cat h3").click(function () {
        $("#" + $(this).attr('title')).toggle()
    });

    $("#pain h2 a").click(function () {
        $("#" + $(this).attr('title')).show();
    });

    $("#makefname").click(function () {
        $(".FirstName").empty();
        $(".FirstName").attr('value', $("#tmpname").val());
        $("span.customerfname").empty();
        $("span.customerfname").append($(".FirstName").val());

    });

    $(".category-index .subcategories").hover(function () {
        $("#main-image").attr('src', '/img/categories/' + this.id)

    });

    $(".service-index .subcategories").hover(function () {
        $("#main-image").attr('src', '/img/categories/' + this.id)

    });

    $(".Service-index .subcategories").hover(function () {
        $("#main-image").attr('src', '/img/categories/' + this.id)

    });

    $(".Product-index .subcategories").hover(function () {
        $("#main-image").attr('src', '/img/categories/' + this.id)

    });

    $("#main_facilities img").mouseover(function () {
        //alert($(this).attr('title'));
        $("#default_blurb").hide();
        $("div.main_facility_blurb").hide();
        $("#" + $(this).attr('title')).show();
    });

    $("#main_facilities img").hover(

    function () {
        var original_src = $(this).attr('src');
        original_src = original_src.replace(".jpg", "_R.jpg");
        $(this).attr('src', original_src);

        var link_id = $(this).attr('title');
        $("#" + link_id + " a").css('color', 'red');
        $("#" + link_id + " a").css('text-decoration', 'underline');
    }, function () {
        var src = $(this).attr('src');
        src = src.replace("_R.jpg", ".jpg");
        $(this).attr('src', src);

        var link_id = $(this).attr('title');
        $("#" + link_id + " a").css('color', '#0084BD');
        $("#" + link_id + " a").css('text-decoration', 'none');
    });

/*$("#start_here_tabs img").hover
	(
		function() 
		{			
			var original_src=$(this).attr('src');			
			original_src=original_src.replace(".jpg","-R.jpg");
			$(this).attr('src',original_src);
		},
		function()
		{
			var src=$(this).attr('src');
			src=src.replace("-R.jpg",".jpg");
			$(this).attr('src',src);
		}
	);*/


    $("#glossarynav li").click(function () {
        $("div.glossary").hide();
        $("." + $(this).attr('title')).show();
    });

/*$("#start_here_tabs img").click(function()
	{
		/*alert($(this).attr('title'));
		$("div.start_here_text").hide();
		$("."+$(this).attr('title')).show();	
		$(".top").show();*/

/*
		var location=$(this).attr('title');
		window.location=location;
	});*/

    $("#start_here_navigation div").click(function () {
/*$("div.start_here_text").hide();
		$("."+$(this).attr('title')).show();*/
    });
    // Image fade
    $(".subcategories img").fadeTo("slow", 0.6); // This sets the opacity of the thumbs to fade down to 60% when the page loads
    $(".subcategories img").hover(function () {
        $(this).fadeTo("slow", 1.0); // This should set the opacity to 100% on hover
    }, function () {
        $(this).fadeTo("slow", 0.6); // This should set the opacity back to 60% on mouseout
    });

    $(".new_secondary_menu a").hover(function () {
        image = $(this).children().attr("src");
        new_image = image.replace(".jpg", "-R.jpg");
        $(this).children().attr("src", new_image);

    }, function () {
        image = $(this).children().attr("src");
        new_image = image.replace("-R.jpg", ".jpg");
        $(this).children().attr("src", new_image);
    });

    $("#ContactAddForm").validate();

    /** For changing font size **/
    var fontsize_array = new Array();
    var tags = "span,div,a,td,strong,p,u,b,i,em,blockquote,label";
    if (!($.browser.msie && ($.browser.version == '6.0' || $.browser.version == '7.0'))) {
        for (var i = 0; i < $(tags).length; i++) {
            fontsize_array[i] = parseInt($(tags).eq(i).css("font-size"));
        }

        var size = 2;
        if ($.cookie("fontsize") != null) {
            size = $.cookie("fontsize");
            //alert("here1");
            change_fontsize(size);
        }

        $("#inc").click(function () {
            if (size < 5) {
                size++;
                $.cookie("fontsize", size, {
                    domain: '.agedcare.com.au',
                    path: '/',
                    expires: 30
                });
                change_fontsize(size);
            }
            return false;
        });

        $("#dec").click(function () {
            if (size > 1) {
                size--;
                $.cookie("fontsize", size, {
                    domain: '.agedcare.com.au',
                    path: '/',
                    expires: 30
                });
                change_fontsize(size);
            }
            return false;
        });

        $("#res").click(function () {
            for (var i = 0; i < $(tags).length; i++) {
                var new_fontsize = fontsize_array[i];
                $(tags).eq(i).attr("style", "font-size:" + new_fontsize + "px !important");
                size = 2;
                $.cookie("fontsize", null, {
                    domain: '.agedcare.com.au',
                    path: '/'
                });
            }
            return false;
        });
    }

    function change_fontsize(size) {
        for (var i = 0; i < $(tags).length; i++) {
            var new_fontsize = fontsize_array[i] + (size - 2) * 2;
            $(tags).eq(i).attr("style", "font-size:" + new_fontsize + "px !important");
        }
    }
});
