﻿var AjaxObjectRequest;
var myGallery;
var countArticle;
var activePanel;
function getContent(contentPathOrid,bgImg,showlink)
{
    if($defined(activePanel)){
        activePanel.className = "contentpage";
    } else {
    $ES("div.contentpageActive","contentPanel").each( function(el){ el.className = "contentpage";});
    }; 
    if(contentPathOrid != "") {
        if($defined(AjaxObjectRequest)) {
           if(YAHOO.util.Connect.isCallInProgress(AjaxObjectRequest)){
              YAHOO.util.Connect.abort(AjaxObjectRequest)
           }
        }
        applyBGStyle(contentPathOrid,bgImg);
        if($defined(myGallery) && $defined(activePanel)) {
        $clear(myGallery);
        activePanel.remove();
        }
        if($(contentPathOrid)){
            $(contentPathOrid).className = "contentpageActive";
            activePanel = $(contentPathOrid)
        } else {
            var callback =
            {
                success:AjaxObject.handleSuccess,
                failure:AjaxObject.handleFailure,
                argument: [contentPathOrid,bgImg],
                scope: AjaxObject
            };
            $("ajaxload").className = "contentpageActive";
            AjaxObjectRequest = AjaxObject.startRequest(callback, contentPathOrid);
        }
    }
    if(YAHOO.util.Dom.get("GNRlinkContainer")){
        if(showlink == "true") {
            $("GNRlinkContainer").style.display = "block";
            $("GNRlinkContainer").setHTML("<a href='/?lbl=" + contentPathOrid + "'>"+ linktothispage +"</a>");
        } else {
            $("GNRlinkContainer").style.display = "none";
            $("GNRlinkContainer").empty();
        }
    }
}
function getImage(imgpos, containerID) {
    var imgsrc = eval("array_" + containerID + "["+imgpos+"]")
    if(imgsrc == null) {
        imgpos = 0;
        imgsrc = eval("array_" + containerID + "[0]");
    }
    var nextpos = Number(imgpos) + 1;
    if($(containerID + "_image_" + imgpos)) {
        $ES("a.imageLinkActive",containerID).each(function(item, index){
            item.className = "imageLink";
        });
        $(containerID + "_image_" + imgpos).className = "imageLinkActive"
    }
    var arrLinks = $ES("a.imageLink",containerID);
    $(containerID+"_imageFull").setHTML("<a href=\"javascript:getImage('"+nextpos+"','"+containerID+"')\"><img src=\""+ imgsrc +"\" /></a>");
    $ES("div.imageLegendActive",containerID).each(function(item, index){
            item.className = "imageLegend";
    });
    $(containerID + "_legend_" + imgpos).className = "imageLegendActive";
}

var AjaxObject = {
	handleSuccess:function(o){
		this.processResult(o);
	},
	handleFailure:function(o){
		alert("ko")
	},
	processResult:function(o){
	    var label = o.argument[0];
	    var bgImg = o.argument[1];
	    $("ajaxload").className = "contentpage";
        $("contentPanel").innerHTML += o.responseText;
        activePanel = $(label)
	},

	startRequest:function(callback,label) {
	   return YAHOO.util.Connect.asyncRequest('POST', 'ajax/ReturnPage.aspx', callback, "label="+label);
	}
}

function getDiaporama(containerID) {
    var curimg = myGallery.getIter();
	myGallery.setOptions({
			fadeDuration: 500,
			timed: true,
			showArrows: false,
            showCarousel: false,
            embedLinks: false,
            showInfopane: false,
            slideInfoZoneOpacity : 1,
            slideInfoZoneSlide : false,
			delay: 2000},$(containerID+"_imageFull"));
	if($E(".carouselContainer", containerID+"_imageFull"))
	{
	    $E(".carouselContainer", containerID+"_imageFull").style.visibility = "hidden";
	}
	$E("div.contentpageActive").getElements('p').each(function(item, index){
            item.style.visibility = "hidden";
    });
	myGallery.startSlideShow(Number(curimg));
	$E("div.slideshowLinks", containerID).setHTML('<a href="javascript:getContent(\''+containerID +'\',\'\',false)">STOP</a>');
}
function getFader(imgpos, containerID) {
    
    var imgsrc = eval("array_" + containerID + "["+imgpos+"]");
    if(imgsrc == null) {
        imgpos = 0;
        imgsrc = eval("array_" + containerID + "[0]");
    }
    myGallery = new gallery($(containerID+"_imageFull"), {
                                timed: false,
                                showArrows: false,
                                showCarousel: false,
                                embedLinks: false,
                                showInfopane: true,
                                slideInfoZoneOpacity : 1,
                                slideInfoZoneSlide : false
                                
    },Number(imgpos), containerID +"_slideShowStuffs");
    myGallery.goTo(Number(imgpos))
    $(containerID + "_imageThumbs").style.display = "none";
    $(containerID +"_slideShowStuffs").style.display = "block";
}
function FaderMove(flag, containerID) {
    if(flag == 'prev'){
        myGallery.prevItem();
    } else {
        myGallery.nextItem();
    }
    $ES("div.imageLegendActive", containerID).each(function(item, index){
            item.className = "imageLegend";
    });
    
}
function applyBGStyle(eltID, styleStr){
    if(styleStr != ""){
        var bgScr = styleStr.split("|")[0];
        var repeat =  styleStr.split("|")[1]=="true"?"repeat":"no-repeat";
        var position =  styleStr.split("|")[2];
        document.body.style.backgroundImage = "url('"+bgScr+"')";
        document.body.style.backgroundRepeat = repeat;
        document.body.style.backgroundPosition = position;
  	} else {
  	    document.body.style.backgroundImage = ""
	}  
}
function getVideo(type, width, height, url) {
    var centerTop = (screen.availHeight-400)/2 - 200;
    var centerLeft = (screen.availWidth-400)/2 + 200;
    window.open("/popVideo.aspx?url="+url+"&type="+type+"&width="+width+"&height="+height,"video","top="+centerTop+",left="+centerLeft+",width="+width+",height="+height+",resizable,scrollbars=no,status=0");
}
function goFull(cursrc, width, height) {
   var centerTop = (screen.availHeight-400)/2 - 200;
   var centerLeft = (screen.availWidth-400)/2 + 200;
   window.open("/popImage.aspx?url="+cursrc.replace("../",""),"full","top="+centerTop+",left="+centerLeft+",width="+width+",height="+height+",resizable,scrollbars=no,status=0");
}
/* is this stuff defined? */
if (!document.ELEMENT_NODE) {
	document.ELEMENT_NODE = 1;
	document.ATTRIBUTE_NODE = 2;
	document.TEXT_NODE = 3;
	document.CDATA_SECTION_NODE = 4;
	document.ENTITY_REFERENCE_NODE = 5;
	document.ENTITY_NODE = 6;
	document.PROCESSING_INSTRUCTION_NODE = 7;
	document.COMMENT_NODE = 8;
	document.DOCUMENT_NODE = 9;
	document.DOCUMENT_TYPE_NODE = 10;
	document.DOCUMENT_FRAGMENT_NODE = 11;
	document.NOTATION_NODE = 12;
}

document._importNode = function(node, allChildren) {
	/* find the node type to import */
	switch (node.nodeType) {
		case document.ELEMENT_NODE:
			/* create a new element */
			var newNode = document.createElement(node.nodeName);
			/* does the node have any attributes to add? */
			if (node.attributes && node.attributes.length > 0)
				/* add all of the attributes */
				for (var i = 0, il = node.attributes.length; i < il;)
					newNode.setAttribute(node.attributes[i].nodeName, node.getAttribute(node.attributes[i++].nodeName));
			/* are we going after children too, and does the node have any? */
			if (allChildren && node.childNodes && node.childNodes.length > 0)
				/* recursively get all of the child nodes */
				for (var i = 0, il = node.childNodes.length; i < il;)
					newNode.appendChild(document._importNode(node.childNodes[i++], allChildren));
			return newNode;
			break;
		case document.TEXT_NODE:
		case document.CDATA_SECTION_NODE:
		case document.COMMENT_NODE:
			return document.createTextNode(node.nodeValue);
			break;
	}
};	
