function stripHTML(oldString) {

   var newString = "";
   var inTag = false;
   for(var i = 0; i < oldString.length; i++) {
   
        if(oldString.charAt(i) == '<') inTag = true;
        if(oldString.charAt(i) == '>') {
              if(oldString.charAt(i+1)=="<")
              {
              		//dont do anything
	}
	else
	{
		inTag = false;
		i++;
	}
        }
   
        if(!inTag) newString += oldString.charAt(i);

   }

   return newString;
}

function liveSearch(obj)
{
	p = obj;
	while (p.parentNode && !Element.hasClassName(p, 'livesearch-section')) {
		p = p.parentNode;
	}
	lis = Element.select(p, '.livesearch-in');
	for (i = 0; i < lis.length; i++) {

		html = stripHTML(lis[i].innerHTML.toUpperCase());
		val = obj.value.toUpperCase();
		t = lis[i]; while (t.parentNode&&t.tagName.toUpperCase() != 'LI') t = t.parentNode; // find the parent l		
		if (html.indexOf(val) != -1) {
			Element.show(t);
		} else {
			Element.hide(t);
		}
		
			
		if ((!val)&&(Element.hasClassName(t, 'allvids'))) {
			Element.hide(t);
		}

	}
}



Event.observe(window, 'load', function() {
	$$('.livesearch-box').each( function(item) {
		searchtext = 'Cautare';
		Event.observe(item, 'focus', function() {
			if (this.value == searchtext) this.value = '';
		}
		);

		Event.observe(item, 'blur', function() {
			if (this.value == '') this.value = searchtext;
		}
		);

		Event.observe(item, 'keyup', function() { 
			liveSearch(this); 
			scrollbar.recalculateLayout(); 
			}
		);		 
		
	}
	);

	$$('.detailed-list ul li, .hoverable ul li').each(function(item) {
		Event.observe(item, 'mouseover', function() { this.addClassName('hover'); } );
		Event.observe(item, 'mouseout', function() { this.removeClassName('hover'); } );
	}
	);
	
	$$('.full-hover').each(function(item) {
		Event.observe(item, 'mouseover', function() {
			item.addClassName('hover');
		}
		);

		Event.observe(item, 'mouseout', function() {
			item.removeClassName('hover');
		}
		);	
		
		Event.observe(item, 'click', function() {
			fnd = Element.select(item, '.hover-starter');
			if (!fnd.length) return true;
			f = fnd[0];
			window.location = f.href;
		}
		);	
	}
	);
	
	$$('.row').each(function(item) {
		cp = Element.select(item, '.page');
		for (i = 1; i < cp.length; i++) {
			Element.hide(cp[i]);
		}
	}
	);
	
}
);


function gotoNextPage(dir, obj)
{

	els = Element.select(obj, 'SPAN.disabled');
	if (els.length) return false;
	
	contr = obj;
	while (contr.parentNode&&!Element.hasClassName(contr, 'controls')) contr = contr.parentNode;

	
	
	cont = contr; // cont va tine parintele paginilor
	while (cont.parentNode&&!Element.hasClassName(cont, 'row')) cont = cont.parentNode;	

	
	cp = Element.select(cont, '.page');
	
	pnos = Element.select(contr, '.pageno');
	pno = pnos[0];

	ccp = pno.innerHTML - 1;
	
	ncp = ccp + 0 + dir;

	
	for (i = 0; i < cp.length; i++) {
		Element.hide(cp[i]);
	}

	if (typeof cp[ncp] == 'undefined') {
		ncp = 0;
	} 

	Element.show(cp[ncp]);
	ccp = ncp;



	
	
	el = Element.select(contr, 'div.next span');

	if (ncp >= cp.length-1) {
		el[0].addClassName('disabled');
	} else {
		el[0].removeClassName('disabled');		
	}

	el = Element.select(contr, 'div.prev span');
	if (ncp == 0) {
		el[0].addClassName('disabled');
	} else {
		el[0].removeClassName('disabled');		
	}	

	
	pno.innerHTML = ncp + 1;
	
}


function loadArtist(id) {
	new Ajax.Updater(
		'artist-preview',
		'/artists/preview/'+ id
	);
	
	$$('.artist-results li').each(function(item) { item.removeClassName('selected'); });

	Element.addClassName('artist-'+id, 'selected');
	
	new Ajax.Updater(
		'artist-albums',
		'/artists/albums/'+id,
		{
			onComplete: function() {	
				item = $('artist-albums'); 
				cp = Element.select(item, '.page');
					for (i = 1; i < cp.length; i++) {
						Element.hide(cp[i]);
					}

					$$('#artist-albums .full-hover').each(function(item) {
						
						Event.observe(item, 'mouseover', function() {
							item.addClassName('hover');
						});

						Event.observe(item, 'mouseout', function() {
							item.removeClassName('hover');
						});	
						
						Event.observe(item, 'click', function() {
							fnd = Element.select(item, '.hover-starter');
							if (!fnd.length) return true;
							f = fnd[0];
							window.location = f.href;
						});	
					}
					);
			}
		}
	);

	return false;
}


function checkValue(obj, val)
{
	obj.value = '';
}

function checkValueB(obj, val)
{
	if (obj.value == '') {
			obj.value = val;
	}
}
