
Browser.Popup=new Class({Implements:[Options,Events],options:{width:500,height:300,x:50,y:50,toolbar:0,location:0,directories:0,status:0,scrollbars:'yes',resizable:1,name:'popup'},initialize:function(url,options){this.url=url||false;this.setOptions(options);if(this.options.width=='max')this.options.width=screen.availWidth;if(this.options.height=='max')this.options.height=screen.availHeight;if(this.options.x=='center')this.options.x=Math.floor((screen.availWidth-this.options.width)/2);if(this.options.y=='center')this.options.y=Math.floor((screen.availHeight-this.options.height)/2);if(this.url)this.openWin();},openWin:function(url){url=url||this.url;var options='toolbar='+this.options.toolbar+',location='+this.options.location+',directories='+this.options.directories+',status='+this.options.status+',scrollbars='+this.options.scrollbars+',resizable='+this.options.resizable+',width='+this.options.width+',height='+this.options.height+',top='+this.options.y+',left='+this.options.x;this.window=window.open(url,this.options.name,options);if(!this.window){this.window=window.open('',this.options.name,options);this.window.location.href=url;}
this.focus.delay(100,this);return this;},focus:function(){if(this.window)this.window.focus();else if(this.focusTries<10)this.focus.delay(100,this);else{this.blocked=true;this.fireEvent('onBlock');}
return this;},focusTries:0,blocked:null,close:function(){this.window.close();return this;}});

window.addEvent('load', function(){

    var sameHeightMax = {};
    //var sameHeightElements = {};
    if ($('content') != null) {
        $('content').getElements('[same_height]').each(function(single){
            var row = single.getProperty('same_height');
            //sameHeightElements[row];
			var tmpMargin 	= single.getStyle('margin');
			var tmpPadding 	= single.getStyle('padding');
			single.setStyle('padding-top', '0')
				.setStyle('padding-bottom', '0')
				.setStyle('margin-top', '0')
				.setStyle('margin-bottom', '0');
            var currHeight = single.getCoordinates().height;
			single.setStyle('padding', tmpPadding).setStyle('margin', tmpMargin);
            if (sameHeightMax[row] == null || sameHeightMax[row] < currHeight)
                sameHeightMax[row] = currHeight;
        })

        $('content').getElements('[same_height]').each(function(single){
            var row = single.getProperty('same_height');
            single.setStyle('height', sameHeightMax[row] + 'px');
        })

    }
})

window.addEvent('domready', function(){
	
    /*
     $$('select.maximize').each(function(single){
     single.addEvent('focus', function(){
     var singleCoord = single.getCoordinates();
     single.pos = single.getProperty('position');
     single.width = singleCoord.width;
     single.wrapper = new Element('div').inject(single, 'before');
     single.wrapper.setStyle('width',  singleCoord.width);
     single.wrapper.setStyle('height',  singleCoord.height);
     single.setStyle('position', 'absolute')
     .setStyle('top', singleCoord.top)
     .setStyle('left', singleCoord.left)
     .setStyle('width', 'auto')
     })
     single.addEvent('blur', function(){
     single.wrapper.destroy();
     single.setStyle('position', single.pos);
     single.setStyle('width', single.width);
     })
     })
     */
	$('page').getElements('a[popup]').each(function(single){	
		single.addEvent('click', function(e){
			e.stop();
			var size = single.getProperty('popup').split(',');
				if (size[0]<= 0) size[0] = 800;
				if (size[1]<= 0) size[1] = 600; 
			//window.location.src = single.getProperty('href');
			var myPopup = new Browser.Popup(single.getProperty('href'),{
 				width: size[0],
  				height: size[1],
  				x: 'center',
  				y: 'center' 
			});
		});
	})
	
	$('page').getElements('[replaceValue]').each(function(single){		
			if (single.get('value') =='' || single.get('value') == single.getProperty('replaceValue'))
			{
				single.set('value', single.getProperty('replaceValue'));
				single.change = 'replace';
			}
			else
			{
				single.change = 'specific';			
			}
			single.addEvent('blur', function(){
				if (single.get('value') =='')
				{
					single.set('value', single.getProperty('replaceValue'));
					single.fireEvent('change', 'replace');
				}
				
			})
			single.addEvent('focus', function(){
				if (single.get('value') == single.getProperty('replaceValue'))
				{
					single.set('value', '');
					single.fireEvent('change', 'specific');
				}
			})
	});
	
    $('page').getElements('[class=more_slider]').each(function(single){
        var wrapper = new Element('div').injectAfter(single);
        single.injectInside(wrapper);
        var singleClone = single.clone().removeClass('more_slider').empty().injectAfter(single);
        singleClone.addClass('clone');
        var counter = 1;
        var testCounter = -1;
        var hideAfter = single.getProperty('hideafter');
        if (hideAfter <= 0) 
            hideAfter = 2;
        
        var makeToggle = 0;
        single.getChildren().each(function(child){
            testCounter++;
        })
        //console.log(testCounter, hideAfter);
        if (testCounter > hideAfter) {
            single.getChildren().each(function(child){
                if (counter > hideAfter) {
                    makeToggle = 1;
                    child.injectInside(singleClone);
                }
                counter++;
            })
        }
        if (makeToggle > 0) {
            var slider = new Fx.Slide(singleClone);
            var toggler = new Element('a').injectAfter(singleClone.parentNode);
            toggler.setStyle('padding-bottom', '5px').setStyle('font-weight', 'bold').setStyle('cursor', 'pointer').addClass('toggler').addEvent('click', function(e){
                if (e != null) 
                    e.stop();
                slider.toggle();
                toggler.set('html', status[slider.open]);
                if (slider.open == false) 
                    toggler.addClass('togglerOpen');
                else 
                    toggler.removeClass('togglerOpen');
            });
            toggler.fireEvent('click');
        }
    });
    
    if ($('content') != null) {
        $('content').getElements('[class=slider]').each(function(single){
            var slideEl = single.getElement('div');
            var slideId = slideEl.getProperty('id');
            var myVerticalSlide = new Fx.Slide(slideId);
            var toggler = single.getElement('a.toggler');
            toggler.setStyle('cursor', 'pointer').setStyle('font-weight', 'bold').addEvent('click', function(e){
                if (e != null)
                    e.stop();
                myVerticalSlide.toggle();
                toggler.set('html', status[myVerticalSlide.open]);
                if (myVerticalSlide.open == false)
                    toggler.addClass('togglerOpen');
                else
                    toggler.removeClass('togglerOpen');

            });
            
            toggler.fireEvent('click');
            
        })
    }
    if ($('page') != null){
		$('page').getElements('.sliderX').each(function(single){
            var togglerX = single.getElement('.toogler');
            var slideElX = single.getElement('.toogle');
				slideElX.slide('hide');
            	togglerX.addEvent('click', function(e){
                	if (slideElX.get('slide').open == false)
	                    togglerX.addClass('togglerOpen');
	                else
	                    togglerX.removeClass('togglerOpen');
					e.stop();
					slideElX.slide('toggle');
			});


		})
	}
});

