$(document).ready(function() {
		$('#log').click(function() {
			$('#drop_down').slideToggle("slow");
		});

$(function() {
	    //find all form with class jqtransform and apply the plugin
	    $("form.jqtransform").jqTransform();
	$("form.contact_form").jqTransform();
	});
	
	$(function() {
	    $("#under_menu_nav").append("<div class='letterViewer' id='letterViewer_top'>");
	    $(".user-password_top").keypress(function(e) {
	        $("#letterViewer_top")
	            .html(String.fromCharCode(e.which))
	            .fadeIn(200, function() {
	                $(this).fadeOut(800);
	            });
	    });
	});
	
	$(function() {
	    $("#register_form .password").append("<div class='letterViewer' id='letterViewer_inner'>");
	    $(".user-password_inner").keypress(function(e) {
	        $(this).parent().parent().parent().next()
	            .html(String.fromCharCode(e.which))
	            .fadeIn(200, function() {
	                $(this).fadeOut(800);
	            });
	    });
	});
	
	$('#slideshow').cycle({ 
	    fx:     'fade', 
		speed:  950, 
		timeout: 7000, 
		pager:  '#nav' 
	});

//ratings

$('.show_hide').click(function() {
	$(this).parent().next().slideToggle("slow");
	$(this).toggleClass("highlight");
});

rating = {
	
	_rating: [],
	/*
	init: function(arr) {
	this._rating = arr;
	},
	*/

	add: function (elem) {
		this._rating.push(elem);
	},
	
	init: function() {
		try{
			/*
			for (var i=1; i <= video_rate; i++) {
				var r = document.getElementById("r" + i);
				r.className = "full";
			}
			*/
			for (var i=0; i <= 5; i++) {
				var r = document.getElementById("r" + (i+1));
				if(video_rate - i >= 1){
					r.className = "full";
				}
				else{
					if(video_rate - i < 1 && video_rate - i > 0){
						r.className = "half";
					}
				} 
			}
		}catch(e){}
			
	},
	
	onclick: function(obj) {
		//alert(rootpath + "setRate.php");
		$.get(rootpath + "setRate.php", {video:video_id, rate:obj.id.substr(1,1)}, function setRate(data){video_rate=data;
			for (var i=0; i <= 5; i++) {
			var r = document.getElementById("r" + (i+1));
			if (video_rate - i > 0) {
				r.className = "full";
				if (video_rate - i < 1) {
					r.className = "half";
				};
			}

			if (video_rate - i <= 0) {
				r.className = "";
			};
		}
			
		})
		
		
		/*
		data = eval(data);
		var image_url = data[0];
		var td_id = data[1];
		document.getElementById(td_id).style.backgroundImage = 'url(' + image_url + ')';
		change(control_id);
		*/
		//alert(obj.id.substr(1,1));
	 //var active = true;
	 /*
	 for (var i=1; i <= this._rating.length; i++) {
	 	
	 	var r = document.getElementById("r" + i);
	 	if ( active ) {
	 		r.className = "full";
	 	}
	 	else {
	 		r.className = "";
 		}
 		if (obj.id == "r" + i) {
	 		active = false;
	 	}
	 var k = obj.id.substr(1,1);
	 
	 };
	alert(k);
	*/
	}
	
	
}

rating.init();

var i = 0;

$("p.rates span").each(function() {
	rating.add('r'+i);
});



});	
	
// darkbox begin
	
	$(function() {
	$('a.darkbox').click(function() {				
				var link = $(this);		
				if(!$('div.darkbox-frame').length) {					
					darkbox = $('<div class="darkbox-frame"><div class="darkbox-shadow"></div><div class="darkbox-canvas"><div class="darkbox-button"></div></div></div>').appendTo('body');}
				var frame = darkbox.clone().appendTo('body').addClass('darkbox-frame-on');
				var shadow = frame.find('div.darkbox-shadow').animate({opacity:0.6},300);
				var canvas = frame.find('div.darkbox-canvas');
				var button = frame.find('div.darkbox-button');
				var image = $('<img src="'+ link.attr('href') +'" alt="'+ link.attr('title') +'"/>');
				image.appendTo(canvas);
				image.load(function(){
					var imageWidth = image.width();
					var imageHeight = image.height();
					var frameWidth = frame.width()-40;
					var frameHeight = frame.height()-40;
					if(imageWidth > frameWidth) {
						imageWidth = frameWidth;
						image.width(imageWidth);					
						while(image.height() > frameHeight) {
							image.width(imageWidth);
							imageWidth--;
						}
						imageHeight = image.height();
					}
					if(imageHeight > frameHeight) {
						imageHeight = frameHeight;
						image.height(imageHeight);						
						while(image.width() > frameWidth) {
							image.height(imageHeight);
							imageHeight--;
						}
						imageWidth = image.width();
					}
					canvas.addClass('darkbox-canvas-load').animate({
						width:imageWidth,
						marginLeft:-imageWidth/2,
						height:imageHeight,
						marginTop:-imageHeight/2
					},500,function() {
						canvas.addClass('darkbox-canvas-done');
						button.addClass('darkbox-button-on');
						button.addClass(navigator.platform.toLowerCase().indexOf('mac')+1?'darkbox-button-left':'darkbox-button-right');
						image.animate({opacity:1},500,function() {
							shadow.click(closer);
							button.click(closer);
						});
					});
				});
				var closer = function() {			
					canvas.remove();
					shadow.animate({opacity:0},300,function() {
						frame.remove();
					});
				}
				$(document).keydown(function(e) {
					if(e.which==27) closer();
				});
				return false;
			});
		});
		
// darkbox end	