var windowG;


function showImagePopup(p, aImg, nImg, ctr) {
		
	if (windowG) {
		windowG.destroy();
	}
	if (!p) {
		p = 1;
	}
	if(!aImg) {
		aImg = aImages;
	}
	if(!nImg) {
		nImg = nImages;
	}

	windowG = new Ext.Window({
		renderTo: Ext.getBody(),
		resizable:false,
		draggable: false,
		width: 880,
		cls: 'supportpopup',		
		minWidth: 300,
		minHeight: 200,
		bodyStyle:'',
		buttonAlign:'center',
		items: [{html:
			'<div id="imagecontainer"><img src="/js/libs/ext-2.3.0/resources/images/default/shared/blue-loading.gif" alt="loading" /></div>'			
		}],
		plain:false,
		floating:true,
		modal:true,
		closable: false,
		title:'',
		shadow:false
	});
	
	windowG.show(1, function() { loadImage(p, 0, aImg, nImg, ctr); });
	
}

function loadImage(p, inpage, aImg, nImg, ctr) {
	
	if (!inpage) {
		inpage = 0;
	}
	if(!aImg) {
		aImg = aImages;
	}
	if(!nImg) {
		nImg = nImages;
	}
	if(!ctr) {
		ctr = 'aImages,nImages';
	}

	registerPositionStore = new Ext.data.JsonStore({
		url: '/?event=cmp.cst.multimedia.getimagepopup&p=' + p + '&img=' + aImg[p] + '&max=' + nImg + '&ctr=' + ctr + '&inpage=' + inpage + '&random=' + Math.random(),
		root: 'DATA',
		autoLoad: true,
		fields: ['FORM','HEIGHT'],
		baseParams: {			
		},
		listeners: {
			load: function(store, records) {
				for(var i=0;i<records.length; i++){					
					document.getElementById('imagecontainer').innerHTML = records[i].data.FORM;

					dmy = Ext.get('gallery_nav_left');		
					if (dmy)
						dmy.applyStyles('height: '+records[i].data.HEIGHT+'px');
					dmy = Ext.get('gallery_nav_right');		
					
					if(dmy)
						dmy.applyStyles('height: '+records[i].data.HEIGHT+'px');
					if(dmy)
						dmy.applyStyles('margin-top: -'+(records[i].data.HEIGHT + 4)+'px');
					dmy = Ext.get('gallery_nav_left_a');	
					dmy2 = Math.round((records[i].data.HEIGHT-77)/2);
					if(dmy)
						dmy.applyStyles('margin-top: '+dmy2+'px');
					dmy = Ext.get('gallery_nav_right_a');	
					dmy2 = Math.round((records[i].data.HEIGHT-77)/2);
					if(dmy)
						dmy.applyStyles('margin-top: '+dmy2+'px');
				}		

				if(inpage == 0) {
					windowG.center();
				}
			}			
		}
	});
	
}

function loadImageInPage(p, inpage, aImg, nImg, ctr) {
	
	if (!inpage) {
		inpage = 0;
	}
	if(!aImg) {
		aImg = aImages;
	}
	if(!nImg) {
		nImg = nImages;
	}
	if(!ctr) {
		ctr = 'aImages,nImages';
	}
	if(!ivwcode) {
		ivwcode = '';
	}

	registerPositionStore = new Ext.data.JsonStore({
		url: '/?event=cmp.cst.multimedia.getimageinpage&p=' + p + '&img=' + aImg[p] + '&max=' + nImg + '&ctr=' + ctr + '&inpage=' + inpage + '&random=' + Math.random() + '&ivwcode=' + ivwcode,
		root: 'DATA',
		autoLoad: true,
		fields: ['FORM', 'HEIGHT'],
		baseParams: {			
		},
		listeners: {
			load: function(store, records) {
				for(var i=0;i<records.length; i++){					
					document.getElementById('imagecontainer').innerHTML = records[i].data.FORM;
					//alert(records[i].data.HEIGHT);
					dmy = Ext.get('gallery_nav_left');		
					if (dmy)
						dmy.applyStyles('height: '+records[i].data.HEIGHT+'px');
					dmy = Ext.get('gallery_nav_right');		
					if(dmy)
						dmy.applyStyles('height: '+records[i].data.HEIGHT+'px');
					if(dmy)
						dmy.applyStyles('margin-top: -'+(records[i].data.HEIGHT + 4)+'px');
					dmy = Ext.get('gallery_nav_left_a');	
					dmy2 = Math.round((records[i].data.HEIGHT-77)/2);
					if(dmy)
						dmy.applyStyles('margin-top: '+dmy2+'px');
					dmy = Ext.get('gallery_nav_right_a');	
					dmy2 = Math.round((records[i].data.HEIGHT-77)/2);
					if(dmy)
						dmy.applyStyles('margin-top: '+dmy2+'px');
					//document.getElementById('gallery_nav_left').style.height = records[i].data.HEIGHT;
				}					
			}			
		}
	});
	
}

function slide(trigger,type) {
	
	if(typeof(cMediacontent) != 'object') {
		cMediacontent = new Object();
	}
	if(typeof(cMediacontent[trigger]) != 'number') {
		cMediacontent[trigger] = 0;
	}
	
	
	dmy = Ext.select('#imagegallery_'+trigger+' #innerslide');

	if(type == 'next')	{
		cMediacontent[trigger]++;
		dmy.applyStyles('left: -'+ cMediacontent[trigger] * 178 +'px');			
	}
	else {
		cMediacontent[trigger]--;
		dmy.applyStyles('left: -'+ cMediacontent[trigger] * 178 +'px');		
	}
	
	if(cMediacontent[trigger] == 0)
		Ext.select('#imagegallery_'+trigger+' #sliderback').applyStyles('display:none');
	else
		Ext.select('#imagegallery_'+trigger+' #sliderback').applyStyles('display:block');

	if(cMediacontent[trigger] == eval('nMediacontents_'+trigger) - 3)
		Ext.select('#imagegallery_'+trigger+' #slidernext').applyStyles('display:none');
	else
		Ext.select('#imagegallery_'+trigger+' #slidernext').applyStyles('display:block');
}





