//---------------
// - studio17Profiles.js - 
//		- Copyright (c) 1999 - 2005  Monkey (monkey@subelement17.net)
//		- Yes, you may use this code as is, or parts of it, but leave 
//		- a ref to Code Monkey (monkey@subelement17.net) and subelement17.net
//      - Remember that we have ways to find out where you live :)
//---------------
/*
	aContent - holds the content of the objects we manipulate.
	aCollectionOfObjIds - holds all ids that we can manipulate
*/

var expandColl = {
	sCurrentId:null,
	aContent:new Array(),
	iOpacity:0,
	iTextCounter:0,
	sTextDirection:'+',
	aCollectionOfObjIds:new Array(),
	iNrOfPages:null,
	init:function(sWhat)
	{
		this.iOpacity = 0;
		if(!expandColl.aCollectionOfObjIds.length)
		{
			expandColl.aCollectionOfObjIds = this._getIdsByClassName('profileItem','div');
			for(var i = 0; i < expandColl.aCollectionOfObjIds.length; i++)
			    this.aContent[expandColl.aCollectionOfObjIds[i]] = document.getElementById(expandColl.aCollectionOfObjIds[i]).innerHTML;
		}
		if(sWhat != this.sCurrentId)
		{
		    expandColl.iTextCounter = 0;
		    expandColl.iNrOfPages = null;
			this.sCurrentId = sWhat;
			this._minimize();
			this._maximize();
		}
	},
	_minimize:function()
	{
		sID = (this.sCurrentId=='cmo')?'cpo':'cmo';
		document.getElementById(sID).className = 'profileMini';
		document.getElementById(sID).innerHTML = '<img src="_images_/'+sID+'_cropped.gif" class="cursor" onclick="expandColl.init(this.parentNode.id);" height="142px" width="20px"  alt="click to open" />';
	},
	_maximize:function()
	{
		document.getElementById(expandColl.sCurrentId).className = 'profileMax';
		if(expandColl.aContent[expandColl.sCurrentId])
		{
		    aTextArr = eval(eval("'a'+expandColl.sCurrentId.toUpperCase()"));
	        //Uppdate the number of pages found for this item
	        aArr = eval(eval("'a'+expandColl.sCurrentId.toUpperCase()"));
	        sMaxLength = 6;
	        for(var i = 0; i < sMaxLength; i++)
	        {
	            if(aTextArr['text'+i])
	                expandColl.iNrOfPages++;
	            else
	                break;
	        }
		    sHeading = aTextArr['heading']
		    sHeadingImg = aTextArr['heading_img'];
		    sImg = aTextArr['img'];
		    tmpCurrPage = expandColl.iTextCounter;
	    
		    var sCounter = '('+ (tmpCurrPage +1)/1 + '/'+expandColl.iNrOfPages+')';
		    var sText = aTextArr['text'+expandColl.iTextCounter];
		    expandColl.iTextCounter++;
		    
			sTEXT = '<table border="0"><tbody><tr><td colspan="2" align="center">';
			    sTEXT += '<img src="_images_/'+sHeadingImg+'" alt="'+sHeading+'">'
			sTEXT += '</td></tr><tr><td valign="top">';
			    sTEXT += '<img src="_images_/'+sImg+'" class="cursor" alt="'+sHeading+'" onclick="expandColl.backToOrg();">'
			sTEXT += '</td><td valign="top" >'
			    sTEXT +='<table border="0" class="profileTextTable" width="104px"><tbody><tr><td id="pageCounter" height="13px" valign="top" align="right">'+sCounter+'</td></tr><tr>'
			    sTEXT +=  '<td id="textTD" height="111px" valign="top">' + sText;
			    sTEXT += '</td></tr><td id="turnPage" valign="top" height="13px">'
			    sTEXT += '<div  style="text-align:center;" id="pageImages">'+ expandColl._returnPagesImages(true) +'</div>';
			    sTEXT += '</td></tr></tbody></table>'
			sTEXT += '</td></tr></tbody></table>'
			
			document.getElementById(expandColl.sCurrentId).innerHTML = sTEXT;
		}
		expandColl._applyFilter(this.iOpacity);
	},
	turnPage: function(obj)
	{
	    sObjID =obj.id;
	    if(sObjID == 'next' || sObjID == 'back')
	    {
	        if(sObjID == 'next')
	            iGoToPage = Number(expandColl.iTextCounter)+1;
	        else
	            iGoToPage = Number(expandColl.iTextCounter)-1;
	    }
	    else
	        iGoToPage = obj.id.split('book_')[1]
	    if(iGoToPage == 0)
	        iGoToPage = expandColl.iNrOfPages;
	    if(iGoToPage > expandColl.iNrOfPages)
	        iGoToPage = 1
	    aTextArr = eval(eval("'a'+expandColl.sCurrentId.toUpperCase()"));
        var sCounter = '('+ iGoToPage + '/'+expandColl.iNrOfPages+')';
	    document.getElementById('pageCounter').innerHTML = sCounter;
	    tmpGoTo = iGoToPage-1
	    var sText = aTextArr['text'+tmpGoTo]
	    expandColl.iTextCounter = iGoToPage;
	    document.getElementById('textTD').innerHTML = sText;
	    expandColl._returnPagesImages();
	},
	backToOrg:function()
	{
	    for(var i = 0; i < expandColl.aCollectionOfObjIds.length; i++)
	    {
			 document.getElementById(expandColl.aCollectionOfObjIds[i]).innerHTML = this.aContent[expandColl.aCollectionOfObjIds[i]];
			 document.getElementById(expandColl.aCollectionOfObjIds[i]).className ='profileItem';
	    }
	    expandColl.sCurrentId = null;
	    expandColl.iTextCounter = 0;
	    expandColl.iNrOfPages = 0;
	},
	_returnPagesImages:function(bAsString)
	{
	    if(bAsString)
	    {
	        var sImgStr = '<div>';
            var sImages = ''
            for(var i = 0; i < expandColl.iNrOfPages;i++)
            {
                currentPos = i + 1;
                if(currentPos != expandColl.iTextCounter)
                    sImages += '<img style="'+sHoverHand+'" id="book_'+currentPos+'" class="navigationBook" src="_images_/smallbooksnav/book.gif" title="move on to page '+currentPos+'" height="15px" width="10px" onclick="expandColl.turnPage(this)" />'
                else
                {
                    sImages += '<img style="'+sHoverHand+'" id="book_'+currentPos+'" class="navigationBook" src="_images_/smallbooksnav/book_active.gif" title="move on to page '+currentPos+'" onclick="expandColl.turnPage(this)" height="15px" width="10px" />'
                    iActive = currentPos;
                }
	        }
	        sNext = iActive+1
	        prev = iActive-1;
	    
	        //if(iActive != 1)
	        sImgStr += '<img style="'+sHoverHand+'" onclick="expandColl.turnPage(this)" id="back" title="move back" src="_images_/smallbooksnav/back.gif" height="15px" width="10px" />'
	        //else
            //  sImgStr += '<img style="'+sHoverHand+'" onclick="expandColl.turnPage('+expandColl.iNrOfPages+')" title="go to last page.." src="_images_/smallbooksnav/back.gif" height="15px" width="10px" />'
	        sImgStr += sImages;
  
	        //if(sNext <= expandColl.iNrOfPages)
	         sImgStr += '<img style="'+sHoverHand+'" class="navigationBook" onclick="expandColl.turnPage(this)" id="next" title="move on" src="_images_/smallbooksnav/next.gif" height="15px" width="10px" />'
	        //else
	        //    sImgStr += '<img src="_images_/smallbooksnav/next.gif" class="navigationBook" style="'+sHoverHand+'" title="start all over again..." onclick="expandColl.turnPage(1)" height="15px" width="10px" />'
	        sImgStr += '</div>';
	        return sImgStr;
	    }
	    else
	    {
	        var aImgs = expandColl._getIdsByClassName('navigationBook','img',true)
	        //Reset all images to book.gif and the active one to book_active.gif
	        for(var i = 0; i<aImgs.length;i++)
	        {
	            if(aImgs[i].src.indexOf('book_active.gif')!=-1)
	            {   
	                aImgs[i].src = aImgs[i].src.split('book_active.gif')[0] + 'book.gif'
	            }
	            if(aImgs[i].id == 'book_'+expandColl.iTextCounter)  
                    aImgs[i].src = aImgs[i].src.split('book.gif')[0] + 'book_active.gif'
	        }	        
	    }
	},
	_applyFilter:function(iOpac)
	{
		/*set filter alpha to invisible and then make it visible step by step */
		expandColl.iOpacity = expandColl.iOpacity + iOpac;
		if(expandColl.iOpacity <= 100)
		{
			if(document.getElementById(this.sCurrentId).style.display != 'block')
				document.getElementById(this.sCurrentId).style.display = 'block';
			if(bIE)
				document.getElementById(this.sCurrentId).style.filter = eval('"alpha(opacity=\''+expandColl.iOpacity+'\')"');
			else if (bisSafari)
				document.getElementById(this.sCurrentId).style.opacity = expandColl.iOpacity /100;
			else
			{
				//we hope its Mozilla :-)
				document.getElementById(this.sCurrentId).style.MozOpacity = expandColl.iOpacity /100 // Mozilla does not use filer. It uses "-moz-opacity:0%" in the css.
			}	
			setTimeout("expandColl._applyFilter(25)",150);
		}
	},
	_getIdsByClassName:function(sClassName,sTagName,bAsObj)
	{
		if(!sClassName)
			alert('must specify a classname to look for');
		var aFoundObjIDs = new Array();		
		if(sTagName)		
			aObjs = document.getElementsByTagName(sTagName);
		else
			aObjs = document.getElementsByTagName('*');
		for(var i = 0; i < aObjs.length;i++)
		{
			if(aObjs[i].className == sClassName)
			{
				if(!bAsObj)
				    aFoundObjIDs[aFoundObjIDs.length] = aObjs[i].id
				else
				    aFoundObjIDs[aFoundObjIDs.length] = aObjs[i]
		    }
		}
		return aFoundObjIDs;
	}
}
