window.addEvent('domready', function() {

	// Fluid 16-column Grid
	// Auto-Select Toggle Elements
	
	// Select all boxes with h2 anchor elements and toggle the next div
	// The toggle-ajax anchor is excluded or the AJAX content box won't work
	$$('.box h2 a[id!=toggle-ajax]').each(function(item) {
		item.setStyle('cursor', 'pointer');
		var elToHide = item.getParent('h2').getNext('div');
		if (elToHide) {
			var mySlide = new Fx.Slide(elToHide);
			item.store('fx', mySlide);

			if (item.hasClass('hidden')){
				mySlide.hide();
			}

			item.addEvent('click', function(e) {
				e.stop();
				var fx = this.retrieve('fx');
				fx.toggle();

				if (item.hasClass('hidden')){
					item.removeClass('hidden').addClass('visible');
				}
				else {
					item.removeClass('visible').addClass('hidden');
				}
			});
		}
	});

	// Kwick Box
	if ($('kwick-box')) {
		var kwicks = $$('#kwick .kwick');
		var fx = new Fx.Elements(kwicks, {wait: false, duration: 200, transition: Fx.Transitions.quadOut});
		kwicks.each(function(kwick, i){
			kwick.addEvent('mouseenter', function(e){
				var obj = {};
				obj[i] = {
					'width': [kwick.getStyle('width').toInt(), 170]
				};
				kwicks.each(function(other, j){
					if (other != kwick){
						var w = other.getStyle('width').toInt();
						if (w != 63) obj[j] = {'width': [w, 63]};
					}
				});
				fx.start(obj);
			});
		});
		
		$('kwick').addEvent('mouseleave', function(e){
			var obj = {};
			kwicks.each(function(other, j){
				obj[j] = {'width': [other.getStyle('width').toInt(), 80]};
			});
			fx.start(obj);
		});
	}
	
	// Accordion Section Menu
	if ($('section-menu')) {
		var accordion = new Accordion('a.menuitem', 'ul.submenu', {
			opacity: false,
			onActive: function(toggler, element){
				toggler.addClass('current');
				element.addClass('current');
			},
			onBackground: function(toggler, element){
				toggler.removeClass('current');
				element.removeClass('current');
			}
		}, $('section-menu'));
	}

	// Accordion Content
	if ($('accordion')) {
		var accordion = new Accordion('h3.atStart', 'div.atStart', {
			opacity: false,
			onActive: function(toggler, element){
				toggler.setStyle('font-weight', 'bold');
				toggler.setStyle('background', '#fff');
			},
		 
			onBackground: function(toggler, element){
				toggler.setStyle('font-weight', 'normal');
				toggler.setStyle('background', '#eee');
			}
		}, $('accordion'));
	}

// Toggle and load AJAX content
	if ($('toggle-ajax')) {
		// Dynamically loaded AJAX content
		$('loading').setStyle('display', 'none'); // hides the loading image
		var content = new Fx.Slide('ajax-content').hide(); // creates new Fx.Slide object from ajax-content div, also the hide() function hides the div when the page loads
		$('toggle-ajax').addEvent('click', function(e) { // adds an onClick event to toggle-ajax div
			e = new Event(e); 	
			if ($('toggle-ajax').hasClass('hidden')) { // checks if the content is visible
				$('ajax-content').empty() // empties the ajax-content
				$('loading').setStyle('display', 'block'); // displays the loading image

				var req = new Request.HTML({
					method: 'get',
					url: 'quiltro960/data/ajax-response.html',
					update: $('ajax-content'),
					onComplete: function(html) { 
						$('loading').setStyle('display', 'none'); //Hides the loading image
						content.toggle(); //toggles the ajax-content
					}
				}).send();
			}
			else { 
				content.toggle(); //in case we dont want to send ajax request, we just slide it out
			}
			if ($('toggle-ajax').hasClass('hidden')){
				$('toggle-ajax').removeClass('hidden').addClass('visible');
			}
			else {
				$('toggle-ajax').removeClass('visible').addClass('hidden');
			}
			e.stop(); //this makes sure that the user wont be sent to given url (or that the page refreshes when using dummy url like "#") if the clicked element was a link 
		});
	}

																		  <!-- carga contenido 2 -->
																			//window.addEvent('domready', function() {
																			//var reqideo = new Request.HTML({
																								 //url: 'quiltro960/data/content4.html',
																								  //method: 'get',
																								 //update: 'meca',
																								  //evalScripts: true, /* this is the default */
																								  //onComplete: function(){console.log('ajax complete!')}
																							  //}).send();
																						  //});
																		  <!-- /carga contenido 2 -->

  //<!-- tiempo-->
			  //window.addEvent('domready', function() {
				  //var myswf = new Swiff('quiltro/images_index/hora.swf', {
					  //width: 260,
					  //height: 25,
					  //container: 'tiempo',
					  //params: {
						  //wmode: 'transparent',
					  //},
				  //});
			  //});	  
	  //<!-- /tiempo -->
	  
	// Toggle Grid
	if ($('toggle-grid')) {
		var grid = new Fx.Slide('grid').hide(); //creates new Fx.Slide object from grid div
		$('toggle-grid').addEvent('click', function(e) { //Adds an onClick event to toggle-grid div
			e = new Event(e);
				grid.toggle(); //toggles the div
			if ($('toggle-grid').hasClass('hidden')){
				$('toggle-grid').removeClass('hidden').addClass('visible');
			}
			else {
				$('toggle-grid').removeClass('visible').addClass('hidden');
			}
			e.stop(); //this makes sure that the user wont be sent to given url (or that the page refreshes when using dummy url like "#") if the clicked element was a link 
		});
	}
});


	// Opacity
			(function($){
				window.addEvent('domready',function() {
					//element collection and settings
					var opacity = 0.5, toOpacity = 0.9;

					//set opacity ASAP and events
					$$('div.opacity').set('opacity',opacity).addEvents({
						mouseenter: function() {
							this.tween('opacity',toOpacity);
						},
						mouseleave: function() {
							this.tween('opacity',opacity);
						}
					});
				});
			})(document.id);
	
	
	
																																  //Comentario_BySlideMenu
																															 //var verticaltextmenu;
																															 //window.addEvent('load', function(){
																															  
																																 // var textmenu = new BySlideMenu('textmenu', {
																																	// defaultIndex: 1,
																																	 //elementHeight: 30,
																																	  //elementWidth: 127
																																  //});
																															  
																															  
																															 //});

	
//-----------------------------------------------------------------------
        window.addEvent('domready', function(){
			   tb = new TinyTab($$('ul.tabs li'),$$('ul.contents li'));
        }); 

//--------------------------------------------------------------------------



													  //-------------------------------------------------------------------------------------------
													  
														  window.addEvent('domready', function(){
															  create();
														  });
													  
														  var create = function()
														  {
															  $('Sitefeature').setStyle('display', 'none');
													  
															  if($('Sandbox'))
															  {
																  $('Sandbox').dispose();
															  }
													  
															  var sandBox = $('Sitefeature').clone();
													  
															  sandBox.setStyle('display', 'block').set('id', 'Sandbox').inject($('Sitefeature'), 'after');
													  
															  var f = $$('form')[0];
															  f.addEvent('submit', function(e){
																  e.stop();
																  create();
															  });
													  
															  new SiteFeature($('Sandbox'), {
																autoPlay: true,
																autoPlayInterval: 5000,
																fxDuration: 500,
																fxTransition: 'sine:in',
																navigationOrientation: 'left',
																overlayOpacity: 0.8,
																pauseOnMouseOver: true,
																showLayerOnMouseOverOnly: false,
																trigger: 'click'
															  });
													  
													  }
												  //-------------------------------------------------------------------------------------------




//<!-- NEWS ROTATE -->	
		window.addEvent('domready',function(){
			var rotater = new Rotater('.slide_noticia',{ 		//Class of elements that should rotate.
				slideInterval:3000, 					//Length of showing each element, in milliseconds
				transitionDuration:1000 				//Length crossfading transition, in milliseconds
			});
		});	
var Rotater=new Class({Implements:[Options,Events],options:{slideInterval:4000,transitionDuration:1000,startIndex:0,autoplay:true},initialize:function(B,A){this.setOptions(A);this.slides=$$(B);this.createFx();this.showSlide(this.options.startIndex);if(this.slides.length<2){this.options.autoplay=false}if(this.options.autoplay){this.autoplay()}return this},toElement:function(){return this.container},createFx:function(){if(!this.slideFx){this.slideFx=new Fx.Elements(this.slides,{duration:this.options.transitionDuration})}this.slides.each(function(A){A.setStyle("opacity",0)})},showSlide:function(B){var A={};this.slides.each(function(C,D){if(D==B&&D!=this.currentSlide){A[D.toString()]={opacity:1}}else{A[D.toString()]={opacity:0}}},this);this.fireEvent("onShowSlide",B);this.currentSlide=B;this.slideFx.start(A);return this},autoplay:function(){this.slideshowInt=this.rotate.periodical(this.options.slideInterval,this);this.fireEvent("onAutoPlay");return this},stop:function(){$clear(this.slideshowInt);this.fireEvent("onStop");return this},rotate:function(){current=this.currentSlide;next=(current+1>=this.slides.length)?0:current+1;this.showSlide(next);this.fireEvent("onRotate",next);return this}});
//<!-- /NEWS ROTATE -->


  //<!-- abierto y cerrado -->
			  window.addEvent('domready', function() {
				  var status = {
					  'true': '+',
					  'false': 'x'
				  };
				//--horizontal
				  var myHorizontalSlide = new Fx.Slide('horizontal_slide', {mode: 'horizontal'});
				  $('h_toggle').addEvent('click', function(e){
					  e.stop();
					  myHorizontalSlide.toggle();
				  });
				  myHorizontalSlide.addEvent('complete', function() {
					  $('horizontal_status').set('html', status[myHorizontalSlide.open]);
				  });
			  });
	  //<!-- /abierto y cerrado -->
	  
	   //<!-- SmoothScroll-->
			  window.addEvent('domready',function() { 
				  new SmoothScroll({ duration:700 }, window); 
			  });
	  //<!-- /SmoothScroll-->
	  
//--Opacity to Show Focus 	  
(function() {
	window.addEvent('domready',function() {
		$$('.fade-area').each(function(container) {
			container.getChildren().each(function(child) {
				var siblings = child.getParent().getChildren().erase(child);
				child.addEvents({
					mouseenter: function() { siblings.tween('opacity',0.5); },
					mouseleave: function() { siblings.tween('opacity',1); }
				});
			});
		});
	});
})();
//--Opacity to Show Focus

  //<!-- Strict Doctype Opening Links in a New Window-->
			  window.addEvent('domready', function() { 
				   $$('a.newWindow').addEvent('click', function(){ 
				   $$('a.newWindow').setProperties({ 
				   target: '_blank' }); }); });
	  //<!-- /Strict Doctype Opening Links in a New Window-->
	  



//----------------------------------------
//--- buscar -------------------------
//----------------------------------------
window.addEvent('domready',function(){

  /* search */
  var searchBox = $('search-box'), searchLoaded=false, searchFn = function() {

    /*
      We're lazyloading all of the search stuff.
      After all, why create elements, add listeners, etc. if the user never gets there?
    */
    if(!searchLoaded) {
      searchLoaded = true; //set searchLoaded to "true"; no more loading!

      //build elements!
      var container = new Element('div',{ id: 'search-results' }).inject($('search-area'),'after');
      var wrapper = new Element('div',{
        styles: {
          position: 'relative'
        }
      }).inject(container);
      new Element('div',{ id: 'search-results-pointer' }).inject(wrapper);
      var contentContainer = new Element('div',{ id: 'search-results-content' }).inject(wrapper);
      var closer = new Element('a', {
        href: 'javascript:;',
        text: 'Close',
        styles: {
          position: 'absolute', //position the "Close" link
          bottom: 35,
          right: 20
        },
        events: {
          click: function() {
            container.fade(0);
          }
        }
      }).inject(wrapper);

      //google interaction
      var search = new google.search.WebSearch(),
        control = new google.search.SearchControl(),
        options = new google.search.DrawOptions();

      //set google options
      options.setDrawMode(google.search.SearchControl.DRAW_MODE_TABBED);
      options.setInput(searchBox);

      //set search options
      search.setUserDefinedClassSuffix('siteSearch');
      search.setSiteRestriction('inpsasel.gob.ve');
      search.setLinkTarget(google.search.Search.LINK_TARGET_SELF);

      //set search controls
      control.addSearcher(search);
      control.draw(contentContainer,options);
      control.setNoResultsString('No results were found.');

      //add listeners to search box
      searchBox.addEvents({
        keyup: function(e) {
          if(searchBox.value && searchBox.value != searchBox.get('placeholder')) {
            container.fade(0.9);
            control.execute(searchBox.value);
          }
          else {
            container.fade(0);
          }
        }
      });
      searchBox.removeEvent('focus',searchFn);
    }
  };
  searchBox.addEvent('focus',searchFn);
});
