$(document).ready(function(){

	if ($.isFunction($.fn.corner)) {
		$("div.box, div.info").corner("top 10px");
	}
	if ($.isFunction($.fn.facebox)) {
		$('a[rel*=facebox]').facebox();
	}

	// MODELS HOVER
	$(".cam_list").mouseover(function(){
		$(this).addClass("selected");
	});
	$(".cam_list").mouseout(function(){
		$(this).removeClass("selected");
	});
	
	//MODELS HOVER (OLD)
	$(".model").mouseover(function(){
		$(this).addClass("selected");
	});
	$(".model").mouseout(function(){
		$(this).removeClass("selected");
	});

});

function toggle(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != 'none' ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
	}
}


// SHOW / HIDE PASSWORD FIELDS

function show_hide_password(elem) {
	var eData={v:elem.value, t:elem.type, s:elem.size, n:elem.name, c:elem.className, i:elem.id},
	newElem, newType=(eData.t=='password'?'text':'password');
	try {
		newElem=document.createElement("<input type='"+newType+"' name='"+eData.n+"' value='"+eData.v+"' size='"+eData.s+"' class='"+eData.c+"' id='"+eData.i+"'>");
	}
	catch(e) {
		newElem=document.createElement('input');
		newElem.name=eData.n;
		newElem.name=eData.n;
		newElem.type=newType;
		newElem.size=eData.s;
		newElem.value=eData.v;
		newElem.className=eData.c;
		newElem.id=eData.i;
	}
	elem.parentNode.replaceChild(newElem, elem);
	return newElem.type;
}

(function($) {
	/**
	 * attaches a character counter to each textarea element in the jQuery object
	 * usage: $("#myTextArea").charCounter(max, settings);
	 */
	
	$.fn.charCounter = function (max, settings) {
		max = max || 100;
		settings = $.extend({
			container: "<span></span>",
			classname: "charcounter",
			format: "(%1 karakters over)",
			pulse: true,
			delay: 0
		}, settings);
		var p, timeout;
		
		function count(el, container) {
			el = $(el);
			if (el.val().length > max) {
			    el.val(el.val().substring(0, max));
			    if (settings.pulse && !p) {
			    	pulse(container, true);
			    };
			};
			if (settings.delay > 0) {
				if (timeout) {
					window.clearTimeout(timeout);
				}
				timeout = window.setTimeout(function () {
					container.html(settings.format.replace(/%1/, (max - el.val().length)));
				}, settings.delay);
			} else {
				container.html(settings.format.replace(/%1/, (max - el.val().length)));
			}
		};
		
		function pulse(el, again) {
			if (p) {
				window.clearTimeout(p);
				p = null;
			};
			el.animate({ opacity: 0.1 }, 100, function () {
				$(this).animate({ opacity: 1.0 }, 100);
			});
			if (again) {
				p = window.setTimeout(function () { pulse(el) }, 200);
			};
		};
		
		return this.each(function () {
			var container;
			if (!settings.container.match(/^<.+>$/)) {
				// use existing element to hold counter message
				container = $(settings.container);
			} else {
				// append element to hold counter message (clean up old element first)
				$(this).next("." + settings.classname).remove();
				container = $(settings.container)
								.insertAfter(this)
								.addClass(settings.classname);
			}
			$(this)
				.unbind(".charCounter")
				.bind("keydown.charCounter", function () { count(this, container); })
				.bind("keypress.charCounter", function () { count(this, container); })
				.bind("keyup.charCounter", function () { count(this, container); })
				.bind("focus.charCounter", function () { count(this, container); })
				.bind("mouseover.charCounter", function () { count(this, container); })
				.bind("mouseout.charCounter", function () { count(this, container); })
				.bind("paste.charCounter", function () { 
					var me = this;
					setTimeout(function () { count(me, container); }, 10);
				});
			if (this.addEventListener) {
				this.addEventListener('input', function () { count(this, container); }, false);
			};
			count(this, container);
		});
	};

})(jQuery);



