//jQuery.fn.loadpic
//http://blog.zaimer.com/2010/07/16/jquery-image-zoom-vertical-and-horizontal-geometric-center-plug-loadpic/
jQuery.fn.loadpic = function(options){
    options = $.extend({
        src: "",
        mw: 120,
        mh: 120,
        mt: 0,
        ml: 0
    }, options);
    var _self = this;
    _self.hide();
    var img = new Image();
    $(img).load(function(){
        _self.attr("src", options.src);
        if (_self.width() > options.mw || _self.height() > options.mh) 
            _self.width() > _self.height() ? _self.width(options.mw) : _self.height(options.mh);
        if (_self.height() < options.mh) {
            _self.css('margin', ((options.mh - _self.height()) / 2 + parseInt(options.mt)) + 'px ' + (parseInt(options.ml) + parseInt(options.mw - _self.width()) * 0.5) + 'px').fadeIn('slow');
        }
        else {
            _self.css('margin', options.mt + 'px ' + (parseInt(options.ml) + parseInt(options.mw - _self.width()) * 0.5) + 'px').fadeIn('slow');
        }
    }).attr("src", options.src);
    return _self;
}
var common = {
    //<a href="javascript:void(0)" onClick="addBookmark()">favorites</a>
    addBookmark: function(){
        var url = parent.location.href;
        if (window.sidebar) {
            window.sidebar.addPanel(document.title, url, "");
        }
        else 
            if (document.all) {
                window.external.AddFavorite(url, document.title);
            }
            else 
                if (window.opera && window.print) {
                    return true;
                }
    },
    //<a href="javascript:void(0)" onclick="setHome(this,window.location)">set home</a> 
    setHome: function(obj, vrl){
        try {
            obj.style.behavior = 'url(#default#homepage)';
            obj.setHomePage(vrl);
        } 
        catch (e) {
            if (window.netscape) {
                try {
                    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
                } 
                catch (e) { //Sorry! Your browser does not support direct Homepage
                    alert('"Sorry! Your browser does not support direct Home. In the browser address bar enter "about: config" and press Enter and then [signed.applets.codebase_principal_support] is set to "true", click "Add to Favorites" to ignore safety tips, you can set up successfully."');
                }
                var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
                prefs.setCharPref('browser.startup.homepage', vrl);
            }
        }
    },
    lightbox: function(){
        $.getScript(webpath + 'js/jquery.include.js', function(){
            var files = [webpath + 'css/jquery.lightbox-0.5.css', webpath + 'js/jquery.lightbox-0.5.pack.js'];
            $.include(files, function(){
                if ($('.lightbox img').size() > 0) {
                    var maxwidth = $('.lightbox').attr('maxwidth');
                    $('.lightbox img').width() > maxwidth ? $('.lightbox img').width(maxwidth) : $('.lightbox img').width($('.lightbox img').width());
                    $('.lightbox img').css('cursor', 'pointer').lightBox();
                }
            });
        });
    },
    resize: function(){
        if ($('.h-v-resize').size() > 0 && $('.h-v-resize img.resize').size() > 0) {
            $('.h-v-resize').each(function(){
                var mw = $(this).attr('maxwidth');
                var mh = $(this).attr('maxheight');
                var mt = $(this).attr('mtop');
                var ml = $(this).attr('mleft');
                $('img.resize', this).each(function(){
                    $(this).loadpic({
                        src: $(this).attr('rel'),
                        mw: mw,
                        mh: mh,
                        mt: mt,
                        ml: ml
                    });
                });
            });
        }
    },
    cycle: function(){
        if ($('.banner').size() > 0) 
            $.getScript(webpath + 'js/jquery.cycle.all.min.js', function(){
                $('.banner').cycle({
                    fx: 'fade'
                });
            });
    },
    marquee: function(){
        if ($('.marquee').size() > 0) 
            $.getScript(webpath + 'js/jquery.marquee.js', function(){
            });
    }
};

$(function(){
    common.resize();
    common.cycle();
    common.marquee();
   // $.getScript(webpath + 'js/jquery.marquee.js');
    if ($('.zoom a').size() > 0) 
        $('.zoom a').lightBox({
            imageLoading: webpath + 'images/lightbox-ico-loading.gif', // (string) Path and the name of the loading icon
            imageBtnPrev: webpath + 'images/lightbox-btn-prev.gif', // (string) Path and the name of the prev button image
            imageBtnNext: webpath + 'images/lightbox-btn-next.gif', // (string) Path and the name of the next button image
            imageBtnClose: webpath + 'images/lightbox-btn-close.gif', // (string) Path and the name of the close btn
            imageBlank: webpath + 'images/lightbox-blank.gif' // (string) Path and the name of a blank image (one pixel)
        });
        
    $('li.sub').each(function(){
		$('ul',this).offset({ top: $(this).offset().top, left: $(this).offset().left + 170 });
		$('ul',this).find('li').each(function(){
			$(this).hover(function(){
				$(this).animate({ 
					'text-indent': "20px"
				  }, 100 );
				},function(){
					$(this).animate({ 
					'text-indent': "10px"
				  }, 100 );
					});
			});
		$(this).hover(function(){
			$('ul',this).stop(true,true).slideDown();
			},function(){
				$('ul',this).fadeOut();
				});
		});
	$.ajax({type:'POST',beforeSend:function(){},url:webpath+'pic.asp',data:'',dataType:'html',error:'',success:function(html){$('#right-ad').html(html);}});
});

