// More Text Scripts:


///// VARIABLES ////////////////////////////////////////////////////////////////

// jQuery section
var iSizeArray	= []; // needs to be global...

///// RESIZE ///////////////////////////////////////////////////////////////////

		//jQuery code: ///////////////////////
		
		$(document).ready(function(){
			// this load before the images are loaded...
		
			var rS 			= myDivLists();
			var xElSwap 	= myElementById("elemSwap");
			var iSubscribe	= "subscription";
			var iSupport	= "support";
			var alertLoadFn = false;

        // TEXT SIZE ///////////////////////////////////////////////////////////

			$(rS.elID +'[class^='+rS.clNm+']').each(function() {
				$(this).data('iSize', $(this).attr("class").substring(4));
				iSizeArray[iSizeArray.length] = $(this).data('iSize');
				return;
			});
			
			window.alertLoadFn = (window.alertLoadFn == undefined) ? false: window.alertLoadFn;
			$("#" + rS.cImg).data("origW", 1*$("#" + rS.cImg).attr("width"));
			altImg(rS.lImg, rS.tImg, rS.cImg);

			$('#txtObj').load(function(){
				if (window.alertLoadFn) {
					//newH = altImg(rS.lImg,rS.tImg, rS.cImg);
					//$("#" + rS.cImg).data('diffH', newH - $("#" + rS.cImg).attr('height'));
					$("#" + rS.cImg).data("origW", 1*$("#" + rS.cImg).attr("width"));
					//alert($("#" + rS.cImg).data("origW"));
					window.alertLoadFn = false;
					altImg(rS.lImg, rS.tImg, rS.cImg);
				}
				//alert('loaded: ' + window.alertLoadFn);
				return;
			});
			
			$('#txtIncrease').click(function(){
				var myCount = 0;
				if (Array.min(iSizeArray) < 14) {
					$(rS.elID+'[class^='+rS.clNm+']').each(function() {
						iSizeArray = altClass(myCount, this, 1, iSizeArray); 
						myCount+=1 ;
	        			return;
					});
				};
				altImg(rS.lImg,rS.tImg, rS.cImg);
        		return;
        	});

			$('#txtDecrease').click(function(){
				var doChange = false;
				var myCount = 0;
				if (Array.max(iSizeArray) > 8) {
					$(rS.elID+'[class^='+rS.clNm+']').each(function() {
						iSizeArray = altClass(myCount, this, -1, iSizeArray); 
						myCount+=1 ;
	        			return;
					});
				};
				altImg(rS.lImg,rS.tImg, rS.cImg);
        		return;
        	});
        	
        // MAGNIFICENCE ////////////////////////////////////////////////////////
        	
   			$('img[id^=vid]').each(function(){
   				var elID 	= $(this).attr("id");
  				var myPos	= elID.charAt(elID.length-1);
   				var newHTML	= myVideo(myPos);
   				var txtElem = myElementById(elID+"txt");
   				var txtHTML = txtElem.innerHTML;

   				$(this).data("newHTMLtxt",newHTML.myTxt);
   				$(this).data("oldHTMLtxt",newHTML.orTxt);

   				$(this).data("txtElem",txtElem);
				return; 
 	      	});
			
   			$('img[id^=vid]').click(function(){
	   			var eID 	= $(this).attr("id");
  				var myName	= eID.substring(0,eID.length-1);
	  			var mPos	= eID.charAt(eID.length-1)-1;
	  			var vidNum	= eID.charAt(eID.length-1)*1;
				var	myVideo = '#' + myName + 'eo' + vidNum;															//xElSwap.innerHTML = $(this).data("newHTMLvid");

	   			if ($(myVideo).css('display') == 'none') {  
	   				// video
					resetVid('elemSwap');
   					$(myVideo).css('display','block');
			 		// text
 					resetTxt('vid');
 	  				$(this).data("txtElem").innerHTML = $(this).data("newHTMLtxt");
  				} else {
	   				// video
					resetVid('elemSwap');
  					$('#elemSwap').css('display','block');
 			 		// text
					resetTxt('vid');
   				}
    			return;
   			});


        // SUBSCRIPTION ////////////////////////////////////////////////////////

   			$('#' + iSubscribe).each(function(){
				var txtElem 	= myElementById(iSubscribe);
   				$(this).data("subscr",true);
				return; 
 	      	});

   			$('#' + iSubscribe).click(function(){
   				var meTxt 	= meSubscribe();
				xElSwap.innerHTML = meTxt.sCode;
   				return;
   			});
		
        
        // SUPPORT /////////////////////////////////////////////////////////////

   			$('#' + iSupport).each(function(){
				var txtElem = myElementById(iSupport);
   				$(this).data("support",true);
				return; 
 	      	});

   			$('#' + iSupport).click(function(){
   				var meTxt 	= meSupport();
				xElSwap.innerHTML = meTxt.sCode;
   				return;
   			});
   			return;
        });
		
        
		
///// VIDEO / TEXT SWAP ////////////////////////////////////////////////////////
		
		function resetVid(wDiv) {
			$('.' + wDiv).each(function(){
	   			$(this).css('display','none');
	   		});
	 		return;
	 	}

		function resetTxt(wDiv, cond) {
			$('img[id^=vid]').each(function(){
				$(this).data("txtElem").innerHTML = $(this).data("oldHTMLtxt");
	   		});
	 		return;
	 	}

///// TEXT INCREASE-DECREASE ///////////////////////////////////////////////////
        
		function altClass(mCount, myObj, adj, myArray) {
			x = $(myObj).data('iSize') * 1 + adj;
			myArray[mCount] = x
			$(myObj).data('iSize', x);					
			if ((x < 15) && (x > 7)) {
				myClass = $(myObj).attr("class");
				myName  = myClass.substring(0,4);
				newClass = myName + x;
				$(myObj).removeClass(myClass);
				$(myObj).addClass(newClass);
			};
			return myArray;
		}
		
		function altImg(lstImg, txtImg, ctrImg) {
			
			var imgList = [lstImg, txtImg, ctrImg];
			
			//alert("last: " + lstImg + "  control: " +  ctrImg + "  text: " + txtImg);
			var offset  = [];
	
			for (var i=0;i<imgList.length;i++) {
				offset[i] = $("#"+imgList[i]).offset();
				window.alertLoadFn = ($("#"+imgList[i]).height() < 1) ? true: window.alertLoadFn;
				//alert(i + " top: " + offset[i].top + "  h: " + $("#"+imgList[i]).height() + "  alert: " + window.alertLoadFn);
			}

			if (! window.alertLoadFn) {
				var ctrlImgH	= offset[0].top - offset[2].top - $("#"+imgList[1]).height() + $("#"+imgList[0]).height();

				//ctrlImgH = ctrlImgH - $("#" + imgList[2]).data("diffH");
				var w = $("#"+imgList[2]).width();
				//var myWidth = $("#"+imgList[2]).data("origW");
				if (window.alertLoadFn == false) {
					//alert(window.alertLoadFn + '  w: ' + w + ' h: ' + ctrlImgH);
					$("#"+imgList[2]).css("height", ctrlImgH + "px");
					$("#"+imgList[2]).css("width", w + "px");
				}
			}
			return;
		}

////////////////////////////////////////////////////////////////////////////////

