var openSlideByLink = new Object

window.addEvent( 'domready', function(){
  // for each toggleNest
  $$( '.rgaccord1-nest' ).each(function(item){
    var thisSlider = new Fx.Slide( item.getElement( '.csc-textpic-text' ), { duration: 500 } );
    thisSlider.hide();
    if(item.firstChild.nodeName.toLowerCase() == 'a'){
    	if ('#' + item.firstChild.id == window.location.hash) {thisSlider.slideIn(); }
    	openSlideByLink[item.firstChild.id] = function(){
    		thisSlider.slideIn(); 
    		return true;
    	}
    }
  
    item.getElement( '.csc-header' ).addEvent( 'click', function(){ 
      thisSlider.toggle(); 

      // add the act class
      if (item.getElement( '.csc-header' ).hasClass('act')) {
        item.getElement( '.csc-header' ).removeClass('act');
      } else {
        item.getElement( '.csc-header' ).addClass('act');
      }
    
    });
  });

  // for each csc-frame-frame2
  $$( '.csc-frame-frame2' ).each(function(item){
    var thisSlider = new Fx.Slide( item.getElement( '.csc-textpic-text' ), { duration: 500 } );
    thisSlider.hide();
    if(item.previousSibling.nodeName.toLowerCase() == 'a'){
    	if ('#' + item.previousSibling.id == window.location.hash) {thisSlider.slideIn(); }
    	openSlideByLink[item.previousSibling.id] = function(){
    		thisSlider.slideIn(); 
    		return true;
    	}
    }
    item.getElement( '.csc-header' ).addEvent( 'click', function(){ 
      thisSlider.toggle(); 

      // add the act class
      if (item.getElement( '.csc-header' ).hasClass('act')) {
        item.getElement( '.csc-header' ).removeClass('act');
      } else {
        item.getElement( '.csc-header' ).addClass('act');
      }
    
    });
  });
	
  //for each page link to accordeon
  $$( 'a' ).each(function(item){
  	if (item.href) {
 		var alink = parseUri(item.href);
		if(alink.anchor != '' && (alink.host == window.location.hostname || alink.host == '' )){
			if(openSlideByLink[alink.anchor]) {
				item.onclick = openSlideByLink[alink.anchor];
			}
		}
	}
  });
});

/*
	parseUri 1.2.1
	(c) 2007 Steven Levithan <stevenlevithan.com>
	MIT License
	
	sample: http://user:pass@host.com:81/directory/file.ext?query=1#anchor
	demo: http://stevenlevithan.com/demo/parseuri/js/
*/

function parseUri (str) {
	var	o   = parseUri.options,
		m   = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
		uri = {},
		i   = 14;

	while (i--) uri[o.key[i]] = m[i] || "";

	uri[o.q.name] = {};
	uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
		if ($1) uri[o.q.name][$1] = $2;
	});

	return uri;
};

parseUri.options = {
	strictMode: false,
	key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
	q:   {
		name:   "queryKey",
		parser: /(?:^|&)([^&=]*)=?([^&]*)/g
	},
	parser: {
		strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
		loose:  /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
	}
};

