function preloadImg(image) {
        var img = new Image();
        img.src = image;
}
preloadImg('/nyro/img/ajaxLoader.gif');
preloadImg('/nyro/img/prev.gif');
preloadImg('/nyro/img/next.gif');
preloadImg('/nyro/img/next.gif');
preloadImg('/resources/images/interface/nyro/close.png');
preloadImg('/resources/images/interface/loader.gif');
//gallery interface
preloadImg('/resources/images/interface/gallery/back-on.png');
preloadImg('/resources/images/interface/gallery/forward-on.png');
preloadImg('/resources/images/interface/gallery/next-on.png');
preloadImg('/resources/images/interface/gallery/pause-16x16-on.png');
preloadImg('/resources/images/interface/gallery/play-on.png');
preloadImg('/resources/images/interface/gallery/rewind-on.png');


jQuery.noConflict();
jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
        return -c * ((t=t/d-1)*t*t*t - 1) + b;
};

//nyro
jQuery(document).ready(function($){
//--------------------------
//badBrowser = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");
//above line causing problems in IE7 - just commenting out for moment
var badBrowser;
if(badBrowser) {
    $('img[src$=.png]').each(function() {
        $(this).pngfix();
    });
}

$("#content").css({
        backgroundRepeat:   "no-repeat",
        backgroundImage:    "url(/resources/images/interface/loader.gif)",
        backgroundPosition: "center"
});
galleryImgTitleColor=$("#gallery-imgTitle").css("color");


//if (!badBrowser) {
    $("#gallery-nav img").hover(
        function() {
            var src = $(this).attr("src");
            var imgBase = src.substring(0,(src.length - 4));
            $(this).attr("src",imgBase+'-on.png');
            if($(this).parent().attr("id")=='controls') {
                $("#gallery-slideshowText").css("color","#FFF");
            }
        },
        function() {
            var src = $(this).attr("src");
            var imgBase = src.substring(0,(src.length - 7));
            $(this).attr("src",imgBase+'.png');
            if($(this).parent().attr("id")=='controls') {
                $("#gallery-slideshowText").css("color",galleryImgTitleColor);
            }
        }
    );
    
    $("#gallery-slideshowText").hover(
        function() {
            $(this).css("color","#FFF");
            var controls = $("#controls img");
            var src = $(controls).attr("src");
            var imgBase = src.substring(0,(src.length - 4));
            $(controls).attr("src",imgBase+'-on.png');
        },
        function() {
            $(this).css("color",galleryImgTitleColor);
            var controls = $("#controls img");
            var src = $(controls).attr("src");
            var imgBase = src.substring(0,(src.length - 7));
            $(controls).attr("src",imgBase+'.png');
        }
    );

//}

$("#gallery-imgTitle").hover(
    function() {
        $(this).css("color","#FFF");
    },
    function() {
        $(this).css("color",galleryImgTitleColor);
    }
);





$.fn.nyroModal.settings.minWidth=200;

$.fn.nyroModal.settings.css={
    bg: {
            zIndex: 100,
            position: 'fixed',
            top: 0,
            left: 0,
            height: '100%',
            width: '100%',
            opacity: 0.5
    },
    wrapper: {
            zIndex: 101,
            position: 'absolute',
            top: '200px',
            left: '50%'
    },
    wrapper2: {
    },
    content: {
            overflow: 'auto'
    },
    loading: {
            zIndex: 102,
            position: 'absolute',
            top: '200px',
            left: '50%',
            marginTop: '-50px',
            marginLeft: '-50px'
    }
};

$.fn.nyroModal.settings.showBackground = function(elts, settings, callback) {
    elts.bg.css({opacity:0}).fadeTo(500, 0.3, callback);
};

$.fn.nyroModal.settings.beforeHideContent = function(elts, settings, callback) {
    /*elts.content.hide();*/
}

$.fn.nyroModal.settings.hideContent = function(elts, settings, callback) {
    elts.contentWrapper
        .animate({
            /*
            height: '50px',
            width: '50px',
            marginTop: 25+settings.marginScrollTop+'px',
            marginLeft: 25+settings.marginScrollLeft+'px'
            */
            opacity: 0

        }, {duration: 350, complete: function() {
            elts.contentWrapper.hide();
            callback();
        }});

}

$.fn.nyroModal.settings.endFillContent = function(elts, settings) {
        if(badBrowser) {
            $("a#closeBut").pngfix().css("right","-24px").css("text-indent", "-9999em");
        }
        //set backgrounds to transparent, etc.
        $("#nyroModalBg").css({
                /*background:"transparent",
                opacity:0.5*/
        });
        $.nyroModalSettings({
                //margin: "50px"
        });
        $("#nyroModalContent").css({
                overflowX:"hidden"
        });
};
$.fn.nyroModal.settings.endShowContent = function(elts, settings) {
        //$("a#closeBut").pngfix();
        $("#nyroModalContent").css({
                overflowX:"hidden"
        });
        $.nyroModalSettings({
                //overflowX: "hidden"
        });
};
//--------------------------
});

//slideshow
//_____________________________________________________________________________________________________________________________________
window.onload=function() {
jQuery(document).ready(function($){
//--------------------------
$('#slideshow').html(htmlStr);
    $('#slideshow img:first').load( function() {
        $("#content").css({
                background: "none"
        });

        function onBefore() {
            //$("#gallery-imgTitle span").fadeOut("fast");
            var ind = parseInt($(this).attr("index") + 1);
            //console.log($("#nav"+ind));
            //console.log('ImgIndex:'+$(this).attr("index"));
            //if($(this).attr("index") > 8 && $(this).attr("index") <= 11 ) {
            /*
            if($(this).attr("index") > 0 && $(this).attr("index") <= 11 ) {
                    $("#gallery-navLinks").trigger( 'next' );
            }
            */
            $("#gallery-navLinks").trigger( 'goto', [$(this).attr("index")] );
            //don't need below - above is enough now since serial's index and cycle's index are in sync
            //if($(this).attr("index") == (11 - 1)) {
                //console.log("Going to 0 serialScroll");
                //$("#gallery-navLinks").trigger( 'goto', [0] );
            //}
        }
        function onAfter() {
            if($(this).attr("title").length > 0) {
                //$("#gallery-imgTitle span").text(': ' + $(this).attr("title"));
                //$("#gallery-imgTitle span").text($(this).attr("title"));
                //$("#gallery-imgTitle span").fadeIn("fast");
            }
            
        }
        function onPagerClick(ind,el) {
        }
        
        $("#gallery-next a").click(function() {
            var ind = $(".activeSlide").attr("id").substring(3);
            var jump = (parseInt(ind) + 6);
            //console.log("---");
            //console.log("Ind: "+ind);
            //console.log("Jump: "+jump);
            if( jump < 11 ) {
                $('#nav'+jump).trigger('click');
                //console.log("Going to: "+jump);
                var serialInd = (jump - 1);
                $("#gallery-navLinks").trigger( 'goto', [serialInd] );
                //console.log("Scrolling to: "+serialInd);
            } else {
                $('#nav11').trigger('click');
                //console.log("Going to: 11");
                var serialInd = (11 - 1);
                $("#gallery-navLinks").trigger( 'goto', [serialInd] );
                //console.log("Scrolling to: "+serialInd);
            }
            //console.log("---");
        });
        
        $("#gallery-prev a").click(function() {
            var ind = $(".activeSlide").attr("id").substring(3);
            var jump = (parseInt(ind) - 6);
            //console.log("---");
            //console.log("Ind: "+ind);
            //console.log("Jump: "+jump);
            if( jump > 0 ) {
                $('#nav'+jump).trigger('click');
                //console.log("Going to: "+jump);
                var serialInd = (jump - 1);
                $("#gallery-navLinks").trigger( 'goto', [serialInd] );
                //console.log("Scrolling to: "+serialInd);
            } else {
                $('#nav1').trigger('click');
                //console.log("Going to: 1");
                $("#gallery-navLinks").trigger( 'goto', [0] );
                //console.log("Scrolling to: 0");
            }
            //console.log("---");
        });

        $('#slideshow').cycle({
            fx:     'fade',
            speed:   2000,
            timeout: 6000,
            pager:  '#gallery-navLinks div',
            before: onBefore,
            after: onAfter,
            prev:'#gallery-imgprev a',
            next:'#gallery-imgnext a',
            //pauseOnPagerHover: true,
            //pagerEvent: 'mouseover',
            pagerClick: onPagerClick,
            pagerAnchorBuilder: pagerFactory,
            fastOnEvent: true
        });
        
        $('#slideshow').cycle('pause');

        function pagerFactory(idx, slide) {
            //var s = idx > 5 ? ' style="display:none"' : '';
            //return '<a '+s+' id="nav'+idx+'" href="#">'+(idx+1)+'</a>';
            var pre='';
            if(idx<10) pre='&nbsp;';
            else pre='';
            return '<a id="nav'+(idx+1)+'">'+(idx+1)+'</a>';
        };
        
        
        $('#content').hover(
            function() {
                //$('#controls').show();
            },
            function() {
                //if($('#controls img').attr("title")!='paused') {
                    //$('#controls').hide();
                //}
            }
        );
        
        $('#controls').toggle(
            function() {
                //$('#controls').html('<img src="/resources/images/interface/gallery/pause-16x16.png">');
                $('#controls img').attr("src","/resources/images/interface/gallery/pause-16x16-on.png");
                $('#slideshow').cycle('resume',true);
            },
            function() {
                //$('#controls').html('<img src="/resources/images/interface/gallery/play.png" title="paused">');
                $('#controls img').attr("src","/resources/images/interface/gallery/play-on.png");
                $('#controls img').attr("title","paused");
                $('#slideshow').cycle('pause');
            }
        );


    //______________________
    
    $('#gallery-navLinks').serialScroll({
            items:'a',
            //prev:'#gallery-prev a',
            //next:'#gallery-next a',
            //prev:'#gallery-imgprev a',
            //next:'#gallery-imgnext a',
            offset:0, //when scrolling to photo, stop 230 before reaching it (from the left)
            start:0, //as we are centering it, start at the 2nd
            duration:1000,
            force:true,
            stop:true,
            lock:false,
            cycle:false, //don't pull back once you reach the end
            step: 1,
            //easing:'easeOutQuart', //use this easing equation for a funny effect
            jump: false, //click on the images to scroll to them
            //exclude: 9
            //interval: 1
            //lazy: true
            constant: false,
            onBefore:function( e, elem, $pane, $items, pos ){
                /**
                 * 'this' is the triggered element
                 * e is the event object
                 * elem is the element we'll be scrolling to
                 * $pane is the element being scrolled
                 * $items is the items collection at this moment
                 * pos is the position of elem in the collection
                 * if it returns false, the event will be ignored
                 */
                 //those arguments with a $ are jqueryfied, elem isn't.
                 //alert(pos);
                 //console.log('serialPos:'+pos);
                 //$("#gallery-navLinks").trigger( 'goto', [0] );

            },
            onAfter:function(elem) {
            /*
                if($(elem.id)=='nav11') {
                    $("#gallery-navLinks").trigger( 'goto', [0] );
                }
            */
            }


    });

    
    //______________________

});


$.preloadCssImages();

//--------------------------
});
}
