$(document).ready(function() {

    /* BEGIN: rounded corner */
    /*$("#nav").corner('bottom');
    $("#nav ul").corner('bottom');*/
    /* END: rounded corner */

    /* BEGIN: navigation */
    $("#nav li").hover(function() {
        var $this = $(this);

        if ($this.hasClass('selected') == false) {
            $this.addClass('active');
        }

        if ($this.children("ul").length > 0) {
            $this.children("ul").stop(true, true).height($this.children("ul").height()).slideDown("fast");
        }
    }, function() {
        var $this = $(this);

        if ($this.children("ul").length > 0) {
            $this.children("ul").stop(true, true).slideUp("fast", function() {
                if ($this.hasClass('selected') == false) {
                    $this.removeClass('active');
                }
            });
        }
        else {
            if ($this.hasClass('selected') == false) {
                $this.removeClass('active');
            }
        }

    });
    /* END: navigation */

    /* BEGIN: accordion */
    $(".accordion li").click(function() {
        var $this = $(this);
        $this.parent().children('.accordion_details').not($this.next()).slideUp('fast');

        if ($this.hasClass('accordion_details') == false) {
            $this.next().slideToggle('fast');
            $this.toggleClass('accordion_rightArrow accordion_downArrow');
        }
        else {
            $this.prev().toggleClass('accordion_rightArrow accordion_downArrow');
        }

        $this.parent().children().not($this).each(function() {
            if ($(this).hasClass('accordion_downArrow') == true) {
                $(this).toggleClass('accordion_rightArrow accordion_downArrow');
            }
        });
    });
    /* END: accordion */

    /* BEGIN: random image */
    var img_id;
    var new_img;
    var active_img = [1, 2, 3, 4, 5];
    var prev_img_id = 0;
    var prev_new_img = 0;

    function randomNum(minVal, maxVal, floatVal) {
        var randVal = minVal + (Math.random() * (maxVal - minVal));
        return typeof floatVal == 'undefined' ? Math.round(randVal) : randVal.toFixed(floatVal);
    }

    function randImg() {
        do {
            img_id = randomNum(1, 5, 0);
        } while (img_id == prev_img_id)

        do {
            new_img = randomNum(1, 8, 0);

            var inActive_img = false;
            for (x in active_img) {
                if (active_img[x] == new_img) {
                    inActive_img = true;
                }
            }
        } while (new_img == prev_new_img || inActive_img == true);

        $("#img_" + img_id).fadeOut('slow', function() {
            $(this).attr('src', 'images/main/img_' + new_img + '.jpg').fadeIn('slow');
        });

        active_img.splice(parseInt(img_id - 1), 1, parseInt(new_img));

        prev_img_id = img_id;
        prev_new_img = new_img;
    }

    setInterval(randImg, 2500);
    /* END: random image */

    /* BEGIN: bucket */
    var news_height = $("#news_events").height() + 30;
    var courses_height = $("#courses").height() + 30;
    var announcements_height = $("#announcements").height() + 30;
    var study_height = $("#study_tours").height() + 30;
    $("#bucket ul li").not(".bucket_details li").height('40px');

    $("#bucket li").not(".bucket_details li").mouseover(function() {
        var $this = $(this);
        var this_id = $this.attr('id');
        var marginTop;
        var height;

        switch (this_id) {
            case 'news_events':
                height = news_height;
                break;
            case 'courses':
                height = courses_height;
                break;
            case 'announcements':
                height = announcements_height;
                break;
            case 'study_tours':
                height = study_height;
                break;
        }

        $this.children('.bucket_title').css('color', '#000');
        marginTop = parseInt(height) - 40;
        $this.stop(true).animate({
            'marginTop': '-' + marginTop + 'px',
            'height': height + 'px'
        }, 150, function() {
            $this.addClass('round_top');
        });
    }).mouseout(function() {
        var $this = $(this);

        $this.animate({
            'height': '40px',
            'marginTop': '0px'
        }, 150, function() {
            $this.removeClass('round_top');
            $this.children('.bucket_title').css('color', '#fff');
        });
    });
    /*var bucket_sliding = false;
    $("#bucket li div").mouseover(function() {
    var $this = $(this);
    var this_id = $this.parent().attr('id');
    var marginTop;
    var height;
		
	switch (this_id) {
    case 'news_events':
    height = news_height;
    break;
    case 'courses':
    height = courses_height;
    break;
    case 'announcements':
    height = announcements_height;
    break;
    case 'study_tours':
    height = study_height;
    break;
    }

	marginTop = parseInt(height)-40;
    $this.parent().stop(true).animate({
    'marginTop': '-'+marginTop+'px',
    'height': height+'px'
    }, 'fast', function() {
    $this.parent().addClass('round_top');
    });
    }).mouseout(function() {
    var $this = $(this);

	$this.parent().stop(true).animate({
    'height': '40px',
    'marginTop': '0px'
    }, 'fast', function() {
    $this.parent().removeClass('round_top');
    });
    });*/
    /* END: bucket */



});

$(window).load(function() {
	$("#body").height($("#body").height());
});

$(function () {
    /* sign-up form*/
    /* asscociate */
    $('#ContentPlaceHolderDefault_cp_content_ctl01_associate_signup_form_3_txtDOB').datepicker({
        yearRange: "-80:+0",
        dateFormat: 'dd-mm-yy',
        changeMonth: true,
        changeYear: true
    });    
    $('#ContentPlaceHolderDefault_cp_content_ctl01_associate_signup_form_3_txtIC').mask("999999-99-9999", {placeholder:" "});
    $("#ContentPlaceHolderDefault_cp_content_ctl01_associate_signup_form_3_txtMobileTel").numeric();
    $("#ContentPlaceHolderDefault_cp_content_ctl01_associate_signup_form_3_txtOfficeTel").numeric();
    $("#ContentPlaceHolderDefault_cp_content_ctl01_associate_signup_form_3_txtFax").numeric();

    $("#ContentPlaceHolderDefault_cp_content_ctl01_associate_signup_form_3_txtYearsPresentEmployer").numeric();

    /* corporate */
    $('#ContentPlaceHolderDefault_cp_content_ctl01_corporate_signup_form_3_txtDateIncorporation').datepicker({
        yearRange: "-80:+0",
        dateFormat: 'dd-mm-yy',
        changeMonth: true,
        changeYear: true
    });
    $("#ContentPlaceHolderDefault_cp_content_ctl01_corporate_signup_form_3_txtCompanyTelephone").numeric();
    $("#ContentPlaceHolderDefault_cp_content_ctl01_corporate_signup_form_3_txtCompanyFax").numeric();
    
    $('#ContentPlaceHolderDefault_cp_content_ctl01_corporate_signup_form_3_txtAppointedIC').mask("999999-99-9999", {placeholder:" "});
    $('#ContentPlaceHolderDefault_cp_content_ctl01_corporate_signup_form_3_txtAppointedDOB').datepicker({
        yearRange: "-80:+0",
        dateFormat: 'dd-mm-yy',
        changeMonth: true,
        changeYear: true
    });     
    $("#ContentPlaceHolderDefault_cp_content_ctl01_corporate_signup_form_3_txtAppointedMobileTel").numeric();
    $("#ContentPlaceHolderDefault_cp_content_ctl01_corporate_signup_form_3_txtAppointedNoYearsWithCompany").numeric();
    $("#ContentPlaceHolderDefault_cp_content_ctl01_corporate_signup_form_3_txtAppointedOfficeTel").numeric();
    $("#ContentPlaceHolderDefault_cp_content_ctl01_corporate_signup_form_3_txtAppointedFax").numeric();
    
    $('#ContentPlaceHolderDefault_cp_content_ctl01_corporate_signup_form_3_txtAlternateIC').mask("999999-99-9999", {placeholder:" "});
    $('#ContentPlaceHolderDefault_cp_content_ctl01_corporate_signup_form_3_txtAlternateDOB').datepicker({
        yearRange: "-80:+0",
        dateFormat: 'dd-mm-yy',
        changeMonth: true,
        changeYear: true
    });     
    $("#ContentPlaceHolderDefault_cp_content_ctl01_corporate_signup_form_3_txtAlternateMobileTel").numeric();
    $("#ContentPlaceHolderDefault_cp_content_ctl01_corporate_signup_form_3_txtAlternateNoYearsWithCompany").numeric();
    $("#ContentPlaceHolderDefault_cp_content_ctl01_corporate_signup_form_3_txtAlternateOfficeTel").numeric();
    $("#ContentPlaceHolderDefault_cp_content_ctl01_corporate_signup_form_3_txtAlternateFax").numeric();   
    
    /* END: sign-up form*/
});

$(function () {
    $('#gallery a').lightBox();
});

$(document).ready(function() {
            $('#cycle').cycle({
                fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
            });
        });



