﻿$(document).ready(function() {
    
    /*if ($.browser.msie ) {
        var FullscreenrOptions = { width:1600, height: 925, bgID: $("img.BackgroundImage")};
        $.fn.fullscreenr2(FullscreenrOptions );
    } else {
        var FullscreenrOptions = { width:1600, height: 925, bgID: $("img.BackgroundImage")};
        $.fn.fullscreenr(FullscreenrOptions );
    }*/
    
    $("#slider img").css("visibility","visible");
    
    
    
    // admin modification
    if($(".ControlPanel").size() > 0) {
        
        // duplicate 'Edit Content' button for bgMove pane so it's clearly visible
        if($(".bgMove").hasClass("DNNEmptyPane") == false) {
            var EditContentLink = $(".bgMove div.c_footer a.CommandButton").attr("href");
            $("#SiteWrapper").append($("<a href="+EditContentLink+" class='custom-bg-button'>Edit Page Background</a> "));
        }
        else {
            // temp fix - brings the main content down to a visible level..
            //$("#MainContent").css("margin-top","0px");
        }
        
        // hide the standard button
        $(".bgMove div.c_footer a.CommandButton").hide();
    }
    
    //
    if(window.location.pathname == "/login.aspx") {
        $("#MainContent").css("margin-top","0px");
    }
    var path = window.location.href;
    if(path.search("/Admin/") > 0 || path.search("/Host/") > 0) {
        $("#MainContent").css("height","auto");
        $(".ContentPane").css("height","auto");
        $("#Body").css("background","#fff");
        $("#footerBlock").remove();
        $(".SubHead").css("color","#333");
        $(".Head").css("color","#333");
    }
});

(function($) {
    var cache = [];
    // Arguments are image paths relative to the current page.
    $.preLoadImages = function() {
        var args_len = arguments.length;
        for (var i = args_len; i--; ) {
            var cacheImage = document.createElement('img');
            cacheImage.src = arguments[i];
            cache.push(cacheImage);
        }
    }
})(jQuery)
// jQuery.preLoadImages("image1.gif", "/path/to/image2.png");


jQuery.fn.basicSlideshow = function (number1, number2, options) {
    // this plugin takes a set of images and simply makes a simple slideshow
    myoptions = jQuery.extend ({
        //operation: "sum",
        //label: "The result is"    
    }, options);
    var currentImage = 1;
    var totalImage;    
    //$(this).html (myoptions.label + " (" + myoptions.operation + ")" + myoptions.number1+myoptions.number2);
    
    // custom slide show
	var totalImage = $("img", this).size();
	
	//console.log("size "+totalImage);
	$("img:first",this).css("display","block");
	$(this).everyTime(4000, function(){
	    // fades out all images within the container and immediately loads the current image
	    $("img",this).fadeOut(700);
	    $("img:eq(" + currentImage + ")", this).fadeIn(700);
	    if (currentImage + 1 == totalImage) currentImage = 0; else currentImage++;
    });	
}

jQuery.fn.imageSetup = function(options) {
    myoptions = jQuery.extend({
    	// default values if none were passed through
    	height: "705px",
    	width: "705px",
    	fadeSpeed: 600
    },
	options);
	// add CSS to the container called to be an image gallery
	$(this).css({
	    'width': myoptions.width, 
	    'height':myoptions.height,
	    //'padding-bottom':'30px',
	    //'float':'left',
	    'text-align':'center',
	    'position':'relative'
	});
	
	// preload images
	$("img", this).each(function(){
	    var path = $(this).attr("src");
		jQuery.preLoadImages(path);
	})
	
	currentImage = 0;
	totalImage = $("img", this).size();
	containerWidth = $(this).width();
	containerHeight = $(this).height();
	
	// center images vertically
	$("img", this).each(function(){
		$(this).load(function(){
		    $.imgWidth = $(this).width();
		    $.imgHeight = $(this).height();
		    widthCorrection = (containerWidth - $.imgWidth) / 2;
		    heightCorrection = (containerHeight - $.imgHeight) / 2;
		    $(this).css("margin-left", widthCorrection);
		    $(this).css("margin-top", heightCorrection);
		}).error(function(){
		    $(this).empty();
		    $(".GalleryContainer .Caption").html("Image not loaded");
		});
	})
	// ********************
	// TEMP - I don't think the above is called if the images were cached
	// ********************
	$("img", this).each(function(){
	    $.imgWidth = $(this).width();
	    widthCorrection = (containerWidth - $.imgWidth) / 2;
	    $.imgHeight = $(this).height();
	    heightCorrection = (containerHeight - $.imgHeight) / 2;
	    $(this).css("margin-left", widthCorrection);
	    $(this).css("margin-top", heightCorrection);
	})
	
	// add class to the image collection
	$("img", this).each(function(){
		$(this).addClass("GalleryImage");
	})
	
	// init first image
	$("img:eq(0)", this).load(function(){
	    //$(this).fadeIn(myoptions.fadeSpeed);
	});
	// ********************
	// TEMP
	// ********************
	//$("img:eq(0)", this).fadeIn(myoptions.fadeSpeed);
	
	$(this).basicSlideshow();
}
