/* Redirect Comments for Lazyest Gallery */
/* Copyright (c) Brimosoft http://brimosoft.nl */
/* By Marcel Brinkkemper */

function lg_redirectComments() {
	if ( typeof(lazyestGallery) != 'undefined' ) {
		theHash = window.location.hash;
		if ( theHash != '' ) {
			if ( theHash.match('comment-') ) {
				olList = document.getElementsByTagName('ol');
				for (var i=0; i<olList.length; i++)	{
					if ( olList[i].className == 'commentlist' ) {
						commentList = olList[i];
						break;
					}
				}
				anchors = commentList.getElementsByTagName('a');
				found = false;
				for (var i=0; i<anchors.length; i++) {
					if ( anchors[i].getAttribute('href') && anchors[i].getAttribute('href').match(theHash) ) found = true;
				}
				if ( !found ) {
					responseDiv = document.getElementById('comments');
					if ( responseDiv ) responseDiv.innerHTML = 'Searching for comment...';					
					commentList.innerHTML = '<li>Please wait while Lazyest Gallery searches for ' + theHash.substr(1) + ' </li>';
					newSearch = 'lg_comment=' + theHash.substr(9) + theHash;
					if ( window.location.search != '' ) {
						newSearch = window.location.search + '&' + newSearch;
					} else {
						newSearch = '?'+ newSearch;			
					}
					with ( window.location ) {
					newLocation = protocol + '//' + hostname + pathname + newSearch;
					replace(newLocation);
					}
				}
			}
		}
	}
}

jQuery(window).load(function() {
  lg_redirectComments();
}) ;

