$(document).ready(function() {


    // google-analytics
    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-22653738-1']);
    _gaq.push(['_trackPageview']);

    (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
    })();


    $('button.resizer').click(function() {

        //$.cookie("font", 's6');

        var currentSize = 4;
        var cookieSize = $.cookie("font");
        if (cookieSize != null && cookieSize != "") {
            currentSize = parseInt(cookieSize);
        }

        var newSize = $(this).attr('size');

        if (newSize == 'Smaller') {
            if (currentSize > 1) {
                currentSize--
            }
        }
        else {
            if (currentSize < 7) {
                currentSize++;

            }
        }

        $('.menu-nav-font-adjuster-increase .resizer').show();
        $('.menu-nav-font-adjuster-decrease .resizer').show();
        if (currentSize == 1) {
            $('.menu-nav-font-adjuster-decrease .resizer').hide();
        } else if (currentSize == 7) {
            $('.menu-nav-font-adjuster-increase .resizer').hide();
        }

        $.cookie("font", currentSize);
        adjustFonts();

    });

    if ($('.rate-this-comment-box').html() == '') {

        $('.rate-this-comment-box').autoResize({
            // On resize:
            onResize: function() {
                $(this).css({ opacity: 0.8 });
            },
            // After resize:
            animateCallback: function() {
                $(this).css({ opacity: 1 });
            },
            // Quite slow animation:
            animateDuration: 300,
            // More extra space:
            extraSpace: 10
        });

    }

    adjustFonts();
    initSlide();


});


function initSlide() {
    $('.slide-body').hide();
    $('.img-faq-arrow-right').show();
    $('.img-faq-arrow-down').hide();


    $("h3.slide-head").click(function(e) {

        $(this).next(".slide-body").slideToggle(200);

        $(this).children(".img-faq-arrow-right").toggle();
        $(this).children(".img-faq-arrow-down").toggle();
    });
  
}




function adjustFonts() {

    var currentSize = $.cookie("font");
    if (currentSize == null) {
        currentSize = 4;
    }

    var bodyFontSize = 's' + currentSize;
    $('body').removeClass('s1 s2 s3 s4 s5 s6 s7');

    if (bodyFontSize != null && bodyFontSize != "") {
        $('body').addClass(bodyFontSize);
    } else {
        $('body').addClass('s4');
    }

}

function performExpandAll() {
    $('.slide-body').show();
    $('.img-faq-arrow-right').hide();
    $('.img-faq-arrow-down').show();
}

function performContractAll() {
    $('.slide-body').hide();
    $('.img-faq-arrow-right').show();
    $('.img-faq-arrow-down').hide();
}

function performSearch() {
    var searchKeyWord = $("#SearchKeyWord").attr('value');

//    var websiteUrl = "http://app1.mcys.gov.sg";
    var websiteUrl = "www.publicguardian.gov.sg";



	
	var fullSearchUrl = "http://sgms.internet.gov.sg/Search.aspx?q=" + searchKeyWord + "&site=default&filter_s=Within+All+Government+Websites%23default|Within+Business%23within_biz|Within+Citizens+And+Residents%23within_cit_res|Within+Non-Residents%23within_non_res|&feedback_url=http%3A%2F%2Fsgms-web.internet.gov.sg%2FUIs%2FFeedback.aspx&contact_url=http%3A%2F%2Fsgms-web.internet.gov.sg%2FUIs%2FContactInfo.aspx&client=default&proxystylesheet=default&output=xml_no_dtd&filter_ss=Results+Within+This+Website%23" + websiteUrl + "|";
    var siteSearchUrl = "http://sgms.internet.gov.sg/Search.aspx?q=" + searchKeyWord + "&site=default&filter_s=Within+All+Government+Websites%23default|Within+Business%23within_biz|Within+Citizens+And+Residents%23within_cit_res|Within+Non-Residents%23within_non_res|&feedback_url=http%3A%2F%2Fsgms-web.internet.gov.sg%2FUIs%2FFeedback.aspx&contact_url=http%3A%2F%2Fsgms-web.internet.gov.sg%2FUIs%2FContactInfo.aspx&client=default&proxystylesheet=default&output=xml_no_dtd&filter_ss=Results+Within+This+Website%23" + websiteUrl + "|&sitesearch=" + websiteUrl;

	
	
    window.open(siteSearchUrl);
    return false;
}



