  jQuery(document).ready(function(){

     // video gallery modal box 
     
    jQuery(".videopopup").bind("click", function(event){

		event.preventDefault();
		// get screen image data
		var videoDataRaw = $(this).attr("id");
                
                // split first _
                var i = videoDataRaw.indexOf('_');
                var videoDataSplit = [videoDataRaw.slice(0,i), videoDataRaw.slice(i+1)];
                var videoData = videoDataSplit[1];

                var title = $(this).parent().parent().parent().children(".vgaltexts").children('div').html();
		// create image content string 
		if (title!=null)
                {
                   var string = '<div class="hd" ><h2 style="margin: none; padding: none;">'+title+'</h2></div>'; 
                }
                string += '<div class="bd" style="margin-bottom: 25px;><object width="425" height="350">';
		string += '<param name="movie" value="http://www.youtube.com/v/'+videoData+'">';
		string += '</param><param name="allowFullScreen" value="true">';
		string += '</param><param name="allowscriptaccess" value="always">';
		string += '</param><embed src="http://www.youtube.com/v/'+videoData+'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="350"></embed></object></div>';
                string += '</div>';


                $.colorbox({
                    html:string,
                    current: "Video {current} / {total}",
                    previous: "Viim.",
                    next: "Seur.",
                    close: "Sulje",
                    initialWidth: 0,
                    initialHeight: 0,
                    opacity: 0.72
                })
                
    });
     

    if($('.siteautogalcontainer').length != 0)
    {
    var gallery = $('.siteautogalcontainer').galleriffic({
            delay:                     5000, // in milliseconds
            numThumbs:                 99, // The number of thumbnails to show page
            preloadAhead:              1, // Set to -1 to preload all images
            enableTopPager:            false,
            enableBottomPager:         false,
            maxPagesToShow:            1,  // The maximum number of pages to display in either the top or bottom pager
            imageContainerSel:         '.showgallery', // The CSS selector for the element within which the main slideshow image should be rendered
            controlsContainerSel:      '', // The CSS selector for the element within which the slideshow controls should be rendered
            captionContainerSel:       '', // The CSS selector for the element within which the captions should be rendered
            loadingContainerSel:       '.loadgallery', // The CSS selector for the element within which should be shown when an image is loading
            renderSSControls:          false, // Specifies whether the slideshow's Play and Pause links should be rendered
            renderNavControls:         false, // Specifies whether the slideshow's Next and Previous links should be rendered
            playLinkText:              'Play',
            pauseLinkText:             'Pause',
            prevLinkText:              'Previous',
            nextLinkText:              'Next',
            nextPageLinkText:          'Next &rsaquo;',
            prevPageLinkText:          '&lsaquo; Prev',
            enableHistory:             false, // Specifies whether the url's hash and the browser's history cache should update when the current slideshow image changes
            enableKeyboardNavigation:  false, // Specifies whether keyboard navigation is enabled
            autoStart:                 true, // Specifies whether the slideshow should be playing or paused when the page first loads
            syncTransitions:           true, // Specifies whether the out and in transitions occur simultaneously or distinctly
            defaultTransitionDuration: 3000, // If using the default transitions, specifies the duration of the transitions
            onSlideChange:             undefined, // accepts a delegate like such: function(prevIndex, nextIndex) { ... }
            onTransitionOut:           undefined, // accepts a delegate like such: function(slide, caption, isSync, callback) { ... }
            onTransitionIn:            undefined, // accepts a delegate like such: function(slide, caption, isSync) { ... }
            onPageTransitionOut: function(callback) {
                this.fadeTo('fast', 1.0, callback);
            },
            onPageTransitionIn: function() {
                this.fadeTo('fast', 1.0);
            }, 
            onImageAdded:              undefined, // accepts a delegate like such: function(imageData, $li) { ... }
            onImageRemoved:            undefined  // accepts a delegate like such: function(imageData, $li) { ... }
    
        });

    }

    $('.mapContainer a').colorbox({photo: true,
        current: "Kartta {current} / {total}",
        previous: "Viim.",
        next: "Seur.",
        close: "Sulje",
        initialWidth: 0,
        initialHeight: 0,
        opacity: 0.72
    });
    
    $('.sitegalcontainer a.noauto').colorbox({


        onComplete: function() {
            $("#cboxTitle").hide();
            gal = $(this).parent('div').parent('div').children('.galtexts');
            title = gal.children('.header').html();
            comment = gal.children('.text').html(); 
            if (title!=null)
            {
                $("<div id='cboxTitle2'><h2>"+title+"</h2></div>").insertBefore("#cboxPhoto");
            }
            if (comment!=null)
            {
               $("<div id='cboxComment'>"+comment+"</div>").insertAfter("#cboxPhoto"); 
            } else {
            }
            $.fn.colorbox.resize();
        },
        current: "Kuva {current} / {total}",
        slideshowStart: "Aloita automaattinen kuvanvaihto",
        slideshowStop: "Lopeta automaattinen kuvanvaihto",
        previous: "Viim.",
        next: "Seur.",
        close: "Sulje",
        initialWidth: 0,
        initialHeight: 0,
        opacity: 0.72,
        slideshow: true,
        slideshowAuto: false,
        slideshowSpeed: 2500
    });


/* ie6 hover fix */
    $.single=function(a){return function(b){a[0]=b;return a}}($([1]));
        /*@cc_on
            if (!window.XMLHttpRequest) {
                $('#mainmenu li').each(function () {
                    this.attachEvent('onmouseenter', function (evt) { $.single(evt.srcElement).addClass('hovered'); });
                    this.attachEvent('onmouseleave', function (evt) { $.single(evt.srcElement).removeClass('hovered'); });
                });
            }
        @*/
});
