﻿var slideList = null;
var timeBetweenSlides = 5000;
var imgWidth = 0;
var isSliding = false;

//var j = jQuery.noConflict();

function printPage(){
  if(location.href.indexOf("&") > 0) {
    printWin=window.open(location.href+'&Printerfriendly=1','printit','');
  } else { 
    printWin=window.open(location.href+'?Printerfriendly=1','printit','');
  }
}

function changeArtPageTitle()
{
   var header = jQuery("#newsHeader").text();
   if (header != "")
      jQuery("#mainColoum h1").text(header);
}

function initScrollbars() {
        var counter = Math.ceil(jQuery(".imageList img").size() / 3);
        var width = jQuery(".imageList img:first").outerWidth() * counter;
        jQuery(".imageList").css({width:width});
        
        var sponsCount = Math.ceil(jQuery(".sponsorItem").size() / 2);
        var sponsWidth = jQuery(".sponsorItem:first").outerWidth() * sponsCount;
        jQuery(".sponsor").css({width:sponsWidth});

        var settings = {
        width: 508,
        height: 261,
        scrollSpeed: 500,
        scrollInInterval: true,
        scrollInIntervalEventsX: [{ firstSelector: ".right",
                         secondSelector: ".left",
                         scrollNudge: { pixels: 30,
                                        speed: 200 },
                         event: "mousedown",
                         scrollSpeed: 1000,
                         hideWhenNotNeeded: true}]
          };
          jQuery(".imageList").wrapInScrollbar(settings);

        settings = {
        width: 640,
        height: 261,
        scrollSpeed: 750,
        scrollInInterval: true,
        scrollInIntervalEventsX: [{ firstSelector: ".right",
                         secondSelector: ".left",
                         scrollNudge: { pixels: 30,
                                        speed: 200 },
                         event: "mousedown",
                         hideWhenNotNeeded: true}]
          };

          jQuery(".sponsor").wrapInScrollbar(settings );
}

function cloneObject(settings) {
var newObj = (this instanceof Array) ? [] : {};
  for (i in this) {
    if (this[i] && typeof this[i] == "object") {
      newObj[i] = this[i].cloneObject();
    } else newObj[i] = this[i]
  } return newObj;

}

function toggleIsSliding(){
	isSliding = !isSliding;
}
function initSlideShow(){
	slideList = jQuery("#slideShowContainer div");
	if(slideList.length != 1) return;
	if(slideList.children().length < 2){
		jQuery("#slideShowContainer span").css("display", "none");
		return;
	}
	if(slideList.children().length == 2){
		tmpObj=slideList.children().clone(true);
		slideList.append(tmpObj);
		slideList = jQuery("#slideShowContainer div");
	}
	var slideElements = slideList.children();
	slideList.css("width",slideElements.width()*slideElements.length);
	imgWidth = slideElements.width();
	slideList.prepend(slideList.children(":last"));
	slideList.css("left", -imgWidth);
	timeSlide=setTimeout(runSlideShow, timeBetweenSlides);
}

function runSlideShow() {
	goingLeft=arguments[0]=="goLeft";
	if(isSliding) return; 
	   toggleIsSliding();
	if(window.timeSlide) clearTimeout(timeSlide);
	slideList = jQuery("#slideShowContainer div");
	slideList.animate({
		left: parseInt(slideList.css("left")) - (goingLeft?imgWidth*-1:imgWidth)}, 
		500, 
		function(){
			slideList = jQuery("#slideShowContainer div");
			if(!goingLeft) slideList.append(slideList.children(":first"));
			else slideList.prepend(slideList.children(":last"));
			slideList.css("left", -imgWidth);
			timeSlide=setTimeout(runSlideShow, timeBetweenSlides);
			toggleIsSliding();
		});
}

function initSlideOutBoxes(){
	var slideOutBoxes = jQuery(".slideOutBox");
	if(slideOutBoxes.length<1) return;
	var boxHeight = parseInt(slideOutBoxes[0].offsetHeight-jQuery(".slideOutBox h3")[0].offsetHeight);
	var slidingSpeed = 250;
	slideOutBoxes.mouseover(function(){
		jQuery(this).children(":last").stop();
		jQuery(this).children(":last").animate({ 
			height: boxHeight+"px"
		}, slidingSpeed);
	});
	slideOutBoxes.mouseout(function(){
		jQuery(".slideOutBox div").stop();
		jQuery(".slideOutBox div").animate({ 
			height: "0px"
		}, slidingSpeed);
	});
}

jQuery(document).ready(function() {
  //initSlideShow();
//  initSlideOutBoxes();
  initScrollbars();
  var settings = {
    Play: '',
    ImageMarginBottom: 10,
    resizeSpeed01: 250,
    resizeSpeed02: 250,
    resizeSpeed03: 250,
    imageInformationHeight: 80,
    imageInformationTemplate: '<span id="imagenumber">[imagenumber]&nbsp;/&nbsp;[numberofimages]</span><span id="co3GalleryDescription">[description]</span><a href="/Admin/Public/Download.aspx?File=[downloadHref]">Download</a>'
    };
  var co3Gallery = jQuery(".rune").CreateGallery(settings);
});
