/*
 * lucy
 * v1109 Index.js
 */



var Index = new Class({

	Extends : Filters,
	
	// vars

	/////

	// ** contructor **  //////////////////////////////

	initialize : function(options){
		
		this.parent(options);
		
		this.setCategoryBlocks();
		
		this.initLastAdsList();
		
	},

	//* end contructor **  //////////////////////////////
	
	// ** setCategoryBlocks //////////////////////////////
	
	setCategoryBlocks : function (){
		
		var i = 0;
		var heightsDiv = new Array();
		
		$$('.category').each(function(el){
			heightsDiv[i] = parseInt(el.getElement('div.links').getStyle('height'));
			i ++;
		});
		
		heightsDiv = heightsDiv.sort(this.sortNumber);
		
		$$('.category').each(function(el){
		    el.getElement('div.links').setStyle("height", heightsDiv[0] + "px");
		});
	},
	
	//* end setCategoryBlocks **  //////////////////////
	
	// ** initLastAdsList //////////////////////////////
	initLastAdsList : function (){
		
		//this.scaleImages (50, 45, 'imgLastPublished');
		
		$$('.last-ads tr').addEvent('mouseover',function(event){
			var a = this.getElement('a.goto');
			a.setStyles({
				'color': '#eda10f',
				'text-decoration' : 'underline'
			});
		});
		
		$$('.last-ads td').addEvent('mouseout',function(event){
			var a = this.getElement('a.goto');
			a.setStyles({
				'color': '#4f5806',
				'text-decoration' : 'none'
			});
		});
		
		$$('.last-ads tr').addEvent('click',function(event){
			event.stop();
			tools.load(baseUrl + '/id-' + this.getProperty('id') + '-' + this.getElement('td').getProperty('id'),'#detail-container',loadDetailContent(),false);
			$$('#detail-container div.loading').setStyle('display','block');
			
		});
		
		$$('.last-ads a.goto').addEvent('click',function(event){
			event.stop();
			tools.load(this.getProperty('href'),'#detail-container',loadDetailContent(), false);
			return false;
		});
		
		function loadDetailContent (){
			
			var divid = 'detail-container';
			var Yheight = 550;
			var scrolledY;
			
			if( self.pageYoffset ) {
				scrolledY = self.pageYoffset;
			} else if( document.documentElement && document.documentElement.scrollTop ) {
				scrolledY = document.documentElement.scrollTop;
			} else if( document.body ) {
				scrolledY = document.body.scrollTop;
			}

			// Next, determine the coordinates of the center of browser's window
			var centerY;
			if( self.innerHeight ) {
				centerY = self.innerHeight;
			} else if( document.documentElement && document.documentElement.clientHeight ) {
				centerY = document.documentElement.clientHeight;
			} else if( document.body ) {
				centerY = document.body.clientHeight;
			}

			var topoffset = (scrolledY + (centerY - Yheight) / 2) - 130;
			var o = document.getElementById(divid);
			var r = o.style;
			r.top = topoffset + 'px';
			
			$$('#detail-container .crl-loading').setStyle('display','block');
			$j('#detail-container').animate({
			    width: '100%'
			 }, 500, function() {
			    // Animation complete.
			});
		}
	},
	//* end initLastAdsList **  //////////////////////
	
	// ** sortNumber //////////////////////////////
	
	sortNumber: function(a,b){
		return b - a;
	}
	
	//* end sortNumber **  //////////////////////
});
