
init_light = function () {
	promos = $$('.l-menu a');
	if (promos.length>0) {
		promos.each(function (promo) {
			promo.onclick = function() {
				var id = this.id.split('_');
				id = id[1];
				$$('.l-menu a').each(function (a) {a.removeClassName('c');});
				this.addClassName('c');
				
				$$('.light-box .pack').each(function (div) {
						if (div.visible() && (div!= $('pack_'+id)) ) {
							div.fade({duration: 0.5});
							}
						});
						
				if (!$('pack_'+id).visible()) {
					$('pack_'+id).appear({duration: 0.5});				 								
				}
										
			}});	
	} 		
} 

init_pav_tabs = function () {
	tabs = $$('.form_pavil .tabs a');
	if (tabs.length>0) {
		tabs.each(function (tab) {
			tab.onclick = function() {
				var id = this.id.split('_');
				id = id[1];
				
				$$('.form_pavil .tabs a').each(function (a) {a.removeClassName('current');});
				this.addClassName('current');
				
				$$('.form_pavil .tab_con').each(function (div) {
						if (div.visible() && (div!= $('pavc_'+id)) ) {
							div.fade({duration: 0.2});
							}
						});
						
				if (!$('pavc_'+id).visible()) {
					$('pavc_'+id).appear({duration: 0.2});				 								
				}
										
			}});	
	} 		
} 

init_mag_list = function (liste_main,liste_sec,id_pref) {
	liste = $$(liste_main);	
	if (liste.length>0) {
		liste.each(function (ls) {
			var id = ls.id.split('_');
				id = id[1];
			var lnk = $(ls).down('a');
			lnk.onclick = function () {
				show=true;
				if (ls.hasClassName('current'))
            show=false;
				$$(liste_main).each(function (lista) {
					lista.removeClassName('current');	
				});
				if (show)
          ls.addClassName ('current');
				$$(liste_sec).each(function (li) {
					//li.removeClassName('current')
					li.hide();
				});
				if (show)
          if ($(id_pref+id)!=null) {
            if (!$(id_pref+id).visible()) {
              
              $(id_pref+id).show();
            }
          }				
				return false;
			}
		});
	}
}

init_toggle = function() {
    $$('input.text-toggle').each(set_toggle);    	
    function set_toggle(elem) {
        if (elem.value=='') {
        	if (elem.alt != '') {
            	elem.value = elem.alt;
            } else {
            	if (elem.title != '') {
            		elem.value = elem.title;
            	}
            }
        }
        
        Event.observe(elem, 'focus', function() {
            if (elem.alt == elem.value) {
                elem.value = '';
                ///elem.focus();
            } else {
            	if (elem.title == elem.value) {
                	elem.value = '';
                }
            }
        });

        Event.observe(elem, 'blur', function() {
            if (elem.value=='') {
            	if (elem.alt != '') {
                	elem.value = elem.alt;
                } else {
                	if (elem.title != '') {
                		elem.value = elem.title;
               		}
                }
                //elem.blur();
            }
        });
    }
}


init_search = function(nr) {
    var sc_focus = false;
    var sc_over = false;
    var self = this;
    var id = ((nr==1)?'search-div':'news-div');
    var sc = $(id);
    
    var texte = $$('#'+id+' input.text');
    var sc_text = null;

    var stil_over = ((nr==1)?'sc-div-over':'nw-div-over');
    var stil_normal = ((nr==1)?'sc-div':'nw-div');
    
    
    if (texte.length>0) {
        sc_text = texte[0];
    } else {
        return;
    }
    

    Event.observe(sc_text, 'focus', function() {
        $(sc).addClassName(stil_over);
        $(sc).removeClassName(stil_normal);
        sc_focus = true;
    });

    Event.observe(sc_text, 'blur', function() {
        if (!sc_over) {
            $(sc).addClassName(stil_normal);
            $(sc).removeClassName(stil_over);
        }
        sc_focus = false;
    });
  	
    Event.observe(sc, 'mouseenter', function() {
        $(sc).addClassName(stil_over);
        $(sc).removeClassName(stil_normal);
        sc_over = true;
    });
    
    Event.observe(sc, 'mouseleave', function() {
        if (!sc_focus) {
            $(sc).addClassName(stil_normal);
            $(sc).removeClassName(stil_over);
        }
        sc_over = false;                        
    });
}

function regTester(input,div) {
	var x = Array();
	x['nume']= /[a-z]+$/i;	
	x['prenume'] = /^[a-z]+$/i;
	x['email'] = /^[a-z0-9]+(\.|_|-)?[a-z0-9]+@([a-z0-9-]+\.)+[a-z]+$/i;
	str = input.value.replace(/^\s+|\s+$/g,"");
	if (x[input.name]!=null) {
		if(!str.match(x[input.name]) || (input.value == input.title)) {
			$(div).removeClassName('fr_valid');
			$(div).addClassName('fr_error');
		} else {
			$(div).removeClassName('fr_error');
			$(div).addClassName('fr_valid');
		}
	} else {
		$(div).addClassName('fr_valid');
	}
		
}

function init_inputs() {
	
	var stil_over = 'fr_focus';
	var stil_normal = 'fr_normal';
	var stil_valid = 'fr_valid';
	var stil_error = 'fr_error';
	
	if ($$('div.for_text').length>0) {
	
	$$('div.for_text').each(function (div) {
		var inp = $(div).down('input');
		Event.observe(inp, 'focus', function() {
	        $(div).addClassName(stil_over);
	        $(div).removeClassName(stil_normal);	        
	        $(div).removeClassName(stil_valid);
	        $(div).removeClassName(stil_error);
    	});
    	
    	Event.observe(inp, 'blur', function() {    		
	        $(div).addClassName(stil_normal);
	        $(div).removeClassName(stil_over);
			regTester(inp,div);	        
    	});    
		
		Event.observe(inp, 'keyup', function() {    		
		//	regTester(inp,div);	        
    	}); 
			
	});
	}
}

function init_check() {
	boxes = $$('a.checkbox, a.checkbox_s');
	if (boxes.length>0) {
		boxes.each(function (box) {
			box.onclick = function() {
				if ($(this).hasClassName('check')) {
					
					$(this).addClassName('checked');
					$(this).removeClassName('check');
					if ($(this).rel != null) {
						$($(this).rel).value = 1;
					}
				} else {
					$(this).addClassName('check');
					$(this).removeClassName('checked');
					if ($(this).rel != null) {
						$($(this).rel).value = 0;
					}										
				}										
			}});	
	}
}

function init_check_blog() {
	boxes = $$('a.checkbox2');
	if (boxes.length>0) {
		boxes.each(function (box) {
			box.onclick = function() {
				if ($(this).hasClassName('check')) {
					
					$(this).addClassName('checked');
					$(this).removeClassName('check');
					$(this.rel).checked = 'checked';
				} else {
					$(this).addClassName('check');
					$(this).removeClassName('checked');
					$(this.rel).checked = '';										
				}										
			}});	
	}
}


function init_access() {

	var bplus = $('text_plus');
	var bminus = $('text_minus');
  
	if (bplus!=undefined && bminus!=undefined) {
	
		var lista = $$(".con p, .con h2, .con label, .con h3, .con a, .con div, .con strong, .con span");
		
	bplus.onclick = function () {	

		lista.each(function (elem) {
		var size = $(elem).getStyle('font-size');
		size = size.replace("px","");
		size = size.replace("em","");
		size ++;		
		$(elem).setStyle({fontSize: size+'px'}); 
		
		var ln = $(elem).getStyle('line-height');
		ln = ln.replace("px","");
		ln = ln.replace("em","");
		ln ++;		
		$(elem).setStyle({lineHeight: ln+'px'}); 
	});
	}
	
	bminus.onclick = function () {	
		lista.each(function (elem) {
		var size = $(elem).getStyle('font-size');
		size = size.replace("px","");
		size = size.replace("em","");
		size = size - 1;		
		$(elem).setStyle({fontSize: size+'px'}); 
		
		var ln = $(elem).getStyle('line-height');
		ln = ln.replace("px","");
		ln = ln.replace("em","");
		ln--;		
		$(elem).setStyle({lineHeight: ln+'px'}); 
	});
	}
	}
	return false;
}

function initHSfriend() {
	/*
	hs.graphicsDir = 'jscripts/graphics/';
	hs.outlineType = 'rounded-white';
	hs.wrapperClassName = 'draggable-header';
	hs.align = 'center';
	hs.showCredits = false;		
	hs.dimmingOpacity = 0.75;
	*/
	try {
	$('rec_friend').onclick = function () {
			return hs.htmlExpand(this, {contentId:'my-content', objectType: 'iframe'});
			//(this, {contentId:'my-content', objectType:'iframe'})
			//return hs.htmlExpand(this, {contentId:'my-content', objectType:'ajax'})
	}
	} catch(err) { }
	try {
    $('revistaDoraly').onclick = function () {
        return hs.htmlExpand(this, {contentId:'my-revista', objectType: 'iframe'});
    }
	} catch(err) { }

}

function initHS() {
	hs.showCredits = false;		
	hs.graphicsDir = 'jscripts/graphics/';
	hs.align = 'center';
	hs.transitions = ['expand', 'crossfade'];
	hs.loadingText = 'Se incarca';
    hs.marginTop = 5;
    hs.marginBottom = 35;
//	hs.outlineType = 'rounded-white';
	hs.fadeInOut = true;
//	hs.headingEval = 'this.a.title'; 
	hs.captionEval = 'this.a.title';
	hs.wrapperClassName = 'borderless';	
	hs.allowMultipleInstances = false; 
	hs.dragByHeading = false;
	hs.restoreTitle = "Click pentru a inchide preview-ul. Apasati pe sageti pentru navigare.";	
	hs.dimmingOpacity = 0.75;
	
	hs.registerOverlay({
	html: '<div class="closebutton" onclick="return hs.close(this)" title="Close"></div>',
	position: 'top right',
	fade: 2, // fading the semi-transparent overlay looks bad in IE
	useOnHtml: false
});
	
	// Add the controlbar
	hs.addSlideshow({
	slideshowGroup: 'group2',
	interval: 5000,
	repeat: false,
	useControls: true,
	fixedControls: false,
	overlayOptions: {
		opacity: .75,
		position: 'bottom center',
		hideOnMouseOut: true
	}
});

	hs.addSlideshow({
	slideshowGroup: 'group1',
	interval: 5000,
	repeat: false,
	useControls: true,
	fixedControls: false,
	overlayOptions: {
		opacity: .75,
		position: 'bottom center',
		hideOnMouseOut: true
	}
});

	hs.addSlideshow({
	slideshowGroup: 'revista',
	interval: 5000,
	repeat: false,
	useControls: true,
	fixedControls: false,
	overlayOptions: {
        offsetY: 50,
		opacity: .75,
		position: 'bottom center',
		hideOnMouseOut: true
	}
});


	$$('a.hs1').each (function (a) {
		a.onclick = function () {
			return hs.expand($(a), { slideshowGroup: 'group1' });
		}
	});
	
	$$('a.hs2').each (function (a) {
		a.onclick = function () {
			return 	hs.expand($(a), { slideshowGroup: 'group2' });
		}
	});
    
   	$$('a.hsx').each (function (a) {
		a.onclick = function () {
			return 	hs.expand($(a), { slideshowGroup: 'revista' });
		}
	});


}

cmm_ajaxRequest=function()
{
	/* [ incarcam link-urile ce au request-urile de ajax */
	$$('.cmm_ajaxRequest').each(function(item) {		
		item.onclick=function(){ return func_cmm_ajaxRequest(this);  }
	});
	
}



document.observe("dom:loaded", function() {
	
    init_search(1);
    init_search(2);
      init_toggle();
    new cmm_init_forms(); // initializeaza formularele
    
    init_check();
    init_check_blog();

    
    cmm_ajaxRequest(); // linkuri ajax
    init_mag_list('.mgz li.main','.mgz li.sec','scat_');
    init_mag_list('.mgz-s li.main','.mgz-s li.sec','scat_');    
    
    init_light(); // homepage lightbox
    init_pav_tabs(); //pavilioane si impartire form  

    initHS();

    initHSfriend();
    init_access(); // plus si minus
    cmm_toolTips(); // red custom toolTips
    
    
}); 
