//jQuery.noConflict();

function test() {// alert('test');
	
	jQuery("#kwicks li").hover(function() { 
				var thumbover = jQuery(this).find("img").attr("src");
				//alert(thumbover);
				jQuery(this).find("a.kwick").css({'background' : 'url(' + thumbover + ') no-repeat left bottom'});
				
				jQuery(this).find("span").stop().fadeTo('normal', 0 , function() {
			jQuery(this).hide() //Hide the image after fade
								
																			   }); }, function() { //on hover out...
		//Fade the image to full opacity 
		//alert('yes');
		jQuery(this).find("span").stop().fadeTo('normal', 1).show();
		});
	
	jQuery("#reg_form input[type=text], #reg_form textarea").each(function() {
						var name = jQuery(this).attr('name');
						var id = jQuery(this).attr('id');
						jQuery(this).attr('value',name);
						searchVal(id,name);
													   });
	
	

		jQuery("#con-open").toggle(function(){
											//alert('click1');
										   jQuery(this).css('background-position','-42px -1px');
											backdrop('1');
											
											}, function() {
												//alert('click2');
												jQuery(this).css('background-position','0px -1px');
												backdrop('2');	
												
												
												
											});
		
		jQuery("a#cta").click(function() {
					jQuery("#con-open").trigger('click');
					return false;
									 });
		jQuery("#reg_form").submit(function() {
					
					var error = false;
					jQuery("#reg_form h3").each(function(){
										jQuery(this).remove();				 
														 });
					jQuery("#reg_form input[type=text]").each(function() {
																	   
						ele = jQuery(this);
						if(ele.attr('value') == ele.attr('name')) {
							error = 'Please fill in this field';							
							ele.closest('li').append(jQuery("<h3 class='error'>").text(error));
						} else {
							
						}
																   });
								if(error) { 
									//alert('no val'); 
								} else { 
									//Passed val
									var con = jQuery("#contact");
									var theheight = jQuery("#reg_form").height();
									var loader = jQuery("<div id='loader'>");
									loader.css('height',theheight);
									jQuery("#reg_form").hide();
									jQuery("#reg-form h2:first").after(loader);
									
									var data1 = jQuery("#reg_form").serialize();
									//alert(data1);
									jQuery.post("http://lucidarts.net/wp-content/themes/riserdesign/sub.php", data1, function(data){
   //alert("Data Loaded: " + data);
								   	var res = jQuery("<div id='form-res'>").append(data);
									
									res.css('height',theheight);
								   
								  	loader.replaceWith(res);
									
									jQuery("#con-open").delay(2500).queue(function(){
														jQuery(this).trigger('click');
																				   });
   
 });
									
								}
						
								return false;			});
 }

 function sliders(){ 
				 //alert('sliders');
									 //alerted();
			var szNormal = 188, szSmall  = 120, szFull   = 460;
			
			var kwicks = $$("#kwicks .kwick"); //alert('hi');
			var fx = new Fx.Elements(kwicks, {wait: false, duration: 400, transition: Fx.Transitions.quadOut}); 
			
			kwicks.each(function(kwick, i) {
				kwick.addEvent("mouseenter", function(event) {
					//set up object
					var o = {};
					//set full width on hovered kwick
					o[i] = {width: [kwick.getStyle("width").toInt(), szFull]}
					//loop through kwicks again 
					kwicks.each(function(other, j) {
						//if its not the hovered kwick
						if(i != j) {
							//get its current width
							var w = other.getStyle("width").toInt();
						//if its not already small make it small
							if(w != szSmall) o[j] = {width: [w, szSmall]};
						}
					});
					//initialize animation
					fx.start(o);
					var myFx = new Fx.Tween(kwick);
					myFx.start('background-position','top');
					
				});
			});
			
			$("kwicks").addEvent("mouseleave", function(event) {
				var o = {};
				kwicks.each(function(kwick, i) {
					o[i] = {width: [kwick.getStyle("width").toInt(), szNormal]}
				});
				fx.start(o);
			})
			
			 //alert('sliders2');
		}
function searchVal(id,value) {
	
			jQuery("#"+id+"").focus(function() {
												 // alert(jQuery(this).val());
			if(jQuery(this).val() == value) {
			jQuery(this).val('');}});
		
			jQuery("#"+id+"").blur(function() {
			if(jQuery(this).val() == '') {
			jQuery(this).val(value);}});
			
		}
//adds backdrop for popups /passed ID value for close link
function backdrop(inst) {
	var form = jQuery("#contact");
	//Find out the window's width and set backdrop to match
	//Find out the document's height and set backdrop to match
	var theheight =(jQuery(document).height());
	theheight = theheight+'px';
	//Get top scrolling amount
	var thebody = jQuery("body");
	//build shadowbox
	var backdrop = jQuery("<div id='formback'>").css({'width':'100%','height':theheight,'background-color':'#000','z-index':'99999','position':'absolute'});
	if(inst == '1') {
	
	//insert and shadowbox into document
	thebody.prepend(backdrop);
	//create form element div holder
	//begin fade in's
	//jQuery('#band').css('display','none');
	backdrop.fadeTo(150,.80, function(){
								//formbox.fadeTo(300,1.0);
								var pos = form.position();
								form.css({"z-index":"99999","position":"absolute","top":pos.top});
								form.animate({
									marginLeft: "-337px"											 
											 },500,function(){});
											
									  });
	} else {
	//set close box link for form pop-up
	
				//fade out form and box
				 form.animate({
									marginLeft: "0px"											 
											 },500,function(){
												 form.css({'position':'fixed','top':'25px'});
												 jQuery("#formback").fadeTo(300,0.0, function(){jQuery("#formback").remove(); jQuery("#form-res").remove(); jQuery("#loader").remove();jQuery("#reg_form").show();
																			  
											
																			   });});
				
				//form.css({'position':'fixed','margin-left':'0'});						
					 	
	//Setup form submit event handler
	}
}

window.onload=function(){
test(); sliders();  }
