jQuery(document).ready(function(){
                if (jQuery().ezMark) {
                        jQuery('.m3').find('input').ezMark();
                        jQuery('.c3subfile').find('input').ezMark();
                        jQuery('.e1subfile').find('input').ezMark();
                }
                if (jQuery().datePicker) {
                        jQuery('.fdate').datePicker().val(new Date().asString()).trigger('change');
                }

                jQuery(".fsubmit").fadeTo(0, 0.8);
                jQuery(".fsubmit").mouseover(function(){
                        jQuery(this).stop().fadeTo('fast', 1);
                });
                jQuery(".fsubmit").mouseout(function(){
                        jQuery(this).stop().fadeTo('fast', 0.8);
                });

                jQuery(".jqfoldtitle").next('.jqfoldcontent').hide();
                jQuery(".jqfoldtitle").click(function(e){
                        e.preventDefault();
                        jQuery(this).toggleClass('jqfoldtitleb');
                        jQuery(this).next('.jqfoldcontent').stop().animate({opacity:'toggle', height:'toggle'});
                });

                jQuery('.c1record').click(function(e, refresh){
                        if (e.pageX - jQuery(this).offset().left > 450) {
                                return true;
                        }
                        var ischecked = jQuery(this).find('input[type=checkbox]').hide().attr('checked');
                        if (!refresh) {
                                ischecked = !ischecked;
                        }

                        jQuery(this).find('input[type=checkbox]').attr('checked', ischecked);

                        if (ischecked) {
                                jQuery(this).addClass('c1ischecked');
                        }
                        else {
                                jQuery(this).removeClass('c1ischecked');
                        }
                });
                jQuery('.c1record').trigger('click', 'refresh');

                jQuery('.c3record .element').click(function(e, refresh){
                        var ischecked = jQuery(this).find('input[type=checkbox]').hide().attr('checked');
                        if (!refresh) {
                                ischecked = !ischecked;
                        }

                        jQuery(this).find('input[type=checkbox]').attr('checked', ischecked);

                        if (ischecked) {
                                jQuery(this).addClass('c3ischecked');
                        }
                        else {
                                jQuery(this).removeClass('c3ischecked');
                        }
                });
                jQuery('.c3record .element').trigger('click', 'refresh');

                if (jQuery().lightBox) {
                        jQuery('.lightbox').lightBox({txtImage:"Image", txtOf:'of', overlayBgColor:'#000000'});
                }
                jQuery('.g1element .value').css({position:'absolute', left:'0px', bottom:'0px', cursor:'pointer'}).animate({opacity:0.0}, 0);
                jQuery('.g1element').hover(
                        function (e) {
                                jQuery('.value', this).stop().animate({opacity:0.8});
                        },
                        function (e) {
                                jQuery('.value', this).stop().animate({opacity:0.0});
                        }
                );

                // -

                jQuery('.i1record .i1record_hover').hide();
                jQuery('.i1record').hover(
                function (e) {
                                jQuery(this).find('.btn').hide();
                                jQuery('.i1record_hover', this).show();
                        },
                function (e) {
                                jQuery(this).find('.btn').show();
                                jQuery('.i1record_hover', this).hide();
                        }
                );

                // -

                jQuery('.c2href_popup').hide();
                jQuery('.c2href_popup').find('.close').click(function(e){ jQuery(this).parent().hide(); });
                jQuery('#c2href').click(function(e){
                        jQuery.ajax({
                                href:     'index.php5'
                                ,data:    { 3:'a1', iscompact:1 }
                                ,success: function (data) {
                                        jQuery('.c2href_popup').show().find('.value').html(data);
                                }
                        });
                        return false;
                });

                // -

                jQuery('.c2advanced').hide();
                jQuery('.c2advanced').prev('.c2fold').click(function(e){
                        jQuery(this).next('.c2advanced').stop().animate({opacity:'toggle', height:'toggle'});
                        jQuery(this).toggleClass('c2unfolded');
                });

                // -

                jQuery('.agvtabs').each(function(){
                        jQuery(this).find('.agvtabs_content').not(':first').hide();
                        jQuery(this).find('.agvtabs_label').eq(0).addClass('agvtabs_ischecked');
                });
                jQuery('.agvtabs .agvtabs_label').click(function(e){
                        var id = jQuery(this).attr('href');
                        if (id) {
                                jQuery(this).parent().find('.agvtabs_label').removeClass('agvtabs_ischecked');
                                jQuery(this).parent().find('.agvtabs_content').hide();
                                jQuery(this).addClass('agvtabs_ischecked');
                                jQuery(this).parent().find(id).show();
                                e.preventDefault();
                        }
                });

                // -

                jQuery('.c2uniqk').hide();
                jQuery(".c2uniqk").prev('.c2fold').click(function(e) {
                        jQuery(this).next('.c2uniqk').stop().animate({opacity:'toggle', height:'toggle'});
                        e.preventDefault();
                });

                jQuery('.c2record .body').not(':first').not('.new').hide();
                jQuery('.c2record .head').click(function(e) {
                        jQuery(this).next('.body').stop().animate({opacity:'toggle', height:'toggle'});
                        e.preventDefault();
                });
                jQuery('.c2new .body').show();

                jQuery('.slider div').not(':first').css({opacity:0});
                jQuery(function() {
                        setInterval("slider_tick()", 3000);
                });

                jQuery('.slider2 div').not(':first').css({opacity:0});
                jQuery(function() {
                        setInterval("slider2_tick()", 4000);
                });
});

function showRequest(formData, jqForm, options) {
                options.dst = jqForm[0];
                jQuery(options.dst).find('.msg').html('').show().fadeTo(0, 1).height('auto');
                for (var i=0; i<jqForm[0].length; i++) {
                        if (jqForm[0][i].name == '1') {
                                jqForm[0][i].name = 2;
                        }
                }

                var queryString = jQuery.param(formData);

                return true;
}

function showResponse(responseText, statusText, xhr, $form)  {
        jQuery(this.dst).find('.msg').html(responseText);
        jQuery(this.dst).find('.msg').delay(4000).animate({opacity:0, height:0});
}

function slider_tick() {
        var checked = jQuery('.slider div.ischecked');

        if (checked.length == 0) {
                checked = jQuery('.slider div:last');
        }

        var next =  checked.next().length ? checked.next() : jQuery('.slider div:first');

        checked.addClass('lastchecked');

        next.css({opacity: 0.0}).addClass('ischecked').animate({opacity: 1.0}, 1000, function() { checked.removeClass('ischecked lastchecked'); });
        checked.css({opacity: 1.0}).animate({opacity:0.0}, 1000);
}

function slider2_tick() {
        var checked = jQuery('.slider2 div.ischecked');

        if (checked.length == 0) {
                checked = jQuery('.slider2 div:last');
        }

        var next =  checked.next().length ? checked.next() : jQuery('.slider2 div:first');

        checked.addClass('lastchecked');

        next.css({opacity: 0.0}).addClass('ischecked').animate({opacity: 1.0}, 1000, function() { checked.removeClass('ischecked lastchecked'); });
        checked.css({opacity: 1.0}).animate({opacity:0.0}, 1000);
}

function swf(src, width, height, noflash, isnoflash) {

        if (isnoflash) {
                return noflash;
        }

        var html = "";
        html += '<object height="'+height+'" width="'+width+'" type="application/x-shockwave-flash" data="'+src+'">\n';
        html += ' <param name="movie" value="'+src+'" />\n';
        html += ' <param name="quality" value="high" />\n';
        html += ' <param name="wmode" value="transparent" />\n';
        html += ' <embed src="'+src+'" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'" wmode="transparent"></embed>\n';
        html += ' '+noflash+'';
        html += '</object>\n';

        return html;
}

function attr_switch (id, option) {
        var e = document.getElementById(id);
        if (e) {
                var value = e.value;
                var re = new RegExp('\\s'+option+'\\s');
                if (value.match(re)) {
                        value = value.replace(re, " ");
                }
                else {
                        value = ' '+option+' '+value+' ';
                }
                value = ' '+value+' ';
                value = value.replace(/\s+/i, " ");
                e.value = value;
        }

        return 1;
}

function agvlinkto (link, id) {

        jQuery(id).each(function(e) {
                jQuery(this).attr('value', link);
        });
        jQuery('.c2href_popup').hide();
}
