// for movie rating
var star = new Array()
star[1] = "";
star[2] = "";
star[3] = "";
star[4] = "";
star[5] = "";

function changeStar(value, count) {
	var start_from = String(count).substring(0,String(count).length-1) + '1';
	if (value == "in") {
		for (i=start_from; i<=count; i++) {
			star_value = String(i).substring(String(i).length-1,String(i).length);
			star[star_value] = document.getElementById('star'+i).className;
			document.getElementById('star'+i).className = 'starhighlight';
		}
	} else {
		for (i=start_from; i<=count; i++) {
			star_value = String(i).substring(String(i).length-1,String(i).length);
			document.getElementById('star'+i).className = star[star_value];
			star[star_value] = "";
		}
	}
}

// for index modules
function changePictures(type, value) {	
	if (value != '') value = "_over";
	eval('document.getElementById("'+ type + '_top").className = "' + type + '_top' + value + '"');
	eval('document.getElementById("'+ type + '_bottom").className = "' + type + '_bottom' + value + '"');
	eval('document.getElementById("'+ type + '_box_content").className = "' + type + '_content' + value + '"');
	eval('document.getElementById("'+ type + '_title").className = "' + type + '_title' + value + '"');
}

// for popup
function wopen(url, name, w, h) {
	w += 32;
	h += 96;
	var win = window.open(url, name, 'width=' + w + ', height=' + h + ', ' + 'location=no, menubar=no, ' + 'status=no, toolbar=no, scrollbars=yes, resizable=no');
	win.resizeTo(w, h);
	win.focus();
}

// for autocompleter
$(document).ready(function() {
	var cssObj = { 'box-shadow' : '#888 5px 5px 10px', // Added when CSS3 is standard
		'-webkit-box-shadow' : '#888 5px 5px 10px', // Safari
		'-moz-box-shadow' : '#888 5px 5px 10px'}; // Firefox 3.5+
	$("#suggestions").css(cssObj);
	$("input").blur(function(){
	$('#suggestions').fadeOut();
	});
});

function lookup(inputString) {
	if(inputString.length < 4 && inputString.length > 10) {
		$('#suggestions').fadeOut();
	} else {
		$.post("/search-ajax.php", {queryString: ""+inputString+""}, function(data) {
			$('#suggestions').fadeIn();
			$('#suggestions').html(data);
		});
	}
}

// for rounded corners
var cbb = {
	init : function() {
		if (!document.getElementById || !document.createElement || !document.appendChild) return false;
		var oElement, oOuter, oI1, oI2, tempId;
		var arrElements = document.getElementsByTagName('*');
		var oRegExp = new RegExp("(^|\\s)cbb(\\s|$)");
		for (var i=0; i<arrElements.length; i++) {
			oElement = arrElements[i];
			if (oRegExp.test(oElement.className)) {
				oOuter = document.createElement('div');
				oOuter.className = oElement.className.replace(oRegExp, '$1cb$2');
				if (oElement.getAttribute("id")) {
					tempId = oElement.id;
					oElement.removeAttribute('id');
					oOuter.setAttribute('id', '');
					oOuter.id = tempId;
				}
				oElement.className = 'i3';
				oElement.parentNode.replaceChild(oOuter, oElement);
				oI1 = document.createElement('div');
				oI1.className = 'i1';
				oOuter.appendChild(oI1);
				oI2 = document.createElement('div');
				oI2.className = 'i2';
				oI1.appendChild(oI2);
				oI2.appendChild(oElement);
				cbb.insertTop(oOuter);
				cbb.insertBottom(oOuter);
			}
		}
	},
	insertTop : function(obj) {
		var oOuter, oInner;
		oOuter=document.createElement("div");
		oOuter.className="bt";
	    oInner=document.createElement("div");
	    oOuter.appendChild(oInner);
		obj.insertBefore(oOuter,obj.firstChild);
	},
	insertBottom : function(obj) {
		var oOuter, oInner;
		oOuter=document.createElement("div");
		oOuter.className="bb";
	    oInner=document.createElement("div");
	    oOuter.appendChild(oInner);
		obj.appendChild(oOuter);
	},
	addEvent : function(obj, type, fn) {
		if (obj.addEventListener)
			obj.addEventListener(type, fn, false);
		else if (obj.attachEvent) {
			obj["e"+type+fn] = fn;
			obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
			obj.attachEvent("on"+type, obj[type+fn]);
		}
	}
};

cbb.addEvent(window, 'load', cbb.init);