function imagePreview(){	
	/* CONFIG */
		xOffset = 10;
		yOffset = 30;
		
	$("img.preview").hover(function(e){			
		$("body").append("<p id='preview'><img src='"+ $(this).attr("preview") + "' />"+ "</p>");								 
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){			
		$("#preview").remove();
    });	
	$("img.preview").mousemove(function(e){
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};


$(document).ready(function(){

	imagePreview();
	
	// Lien Change On Form	
	$("#lien_position_select").change(function(){		
	 	var lien_count = parseInt($(this).val().substr(0,1));
		for (var i=1; i < 4; i++) {
			if (i < lien_count) {				
				$('#lien_info_submit_' + i).show();				
			}else{
				$('#lien_info_submit_' + i).hide();				
			};
		};	
	})
		
	$('#auction_end').datepicker({})
	$('#start_date').datepicker({})
	$('#end_date').datepicker({})	

	// County select in search	
	$("#stateSearch").change(function(){
		$("#search_county_list").html("");		
		  jQuery.ajax({
		  	type: "POST",
		  	url: BASE + '/content/counties/' + $(this).val(),
			data: "",
			dataType: "html",
			success: function(html){					
				$("#search_county_list").html(html);
			}
		})
	})	
		
	$("#genericDialog").dialog({	
			modal: true,
			width: 360,
			height: 380,
			buttons: {
				"Ok": function() { 
					$(this).dialog("close"); 
				}
			}	
	});
	

	$(".privateDialog").dialog({	
			autoOpen: false,
			modal: true,				
			width: 360,
			height: 300,
				buttons: {
						"Close": function() { 
							$(this).dialog("close"); 

						}						
					}
			});
	
	$(".private_listing").bind("click", function(){
				$('.privateDialog').dialog("open");
				return false;
	})
	
	
	function init_dialogs()
	{
		$(".private_listing").bind("click", function(){
			$(".privateDialog").dialog({	
					modal: true,
					width: 360,
					height: 300,
						buttons: {
								"Close": function() { 
									$(this).dialog("close"); 

								}						
							}
					});
					return false;
		})
	}
	

	$("#registerDialog").dialog({
			autoOpen: false,	
			modal: true,
			width: 360,
			height: 280,
			buttons: {
					"REGISTER": function() { 
						window.open(BASE + "register");
					},
					"No Thanks": function() { 
						$(this).dialog("close"); 
					}						
				}	
			});		

	  $('.protectedFeature').click(function(){
			$("#registerDialog").dialog('open');
		})
		
		$("#cantBid").dialog({
				autoOpen: false,	
				modal: true,
				width: 360,
				height: 280,
				buttons: {
						"CLOSE": function() { 
							$(this).dialog("close"); 
						}						
					}	
				});		

		  $('.noBid').click(function(){
				$("#cantBid").dialog('open');
			})	
		
				
	  $("#signupDialog").dialog({	
			modal: true,
			width: 360,
			height: 380,
			buttons: {
						"Ok": function() { 
							$(this).dialog("close"); 
						}
					}	
			});
				
	  $("#enquireDialog").dialog({	
			autoOpen: false,
			modal: true,
			width: 360,
			height: 480,
			buttons: { 
				"Send": function() { sendMessage() },
				"Cancel": function() { $(this).dialog("close"); }
				}		
			});
			
			

				
				
			  $("#adminUserMessage").dialog({	
					autoOpen: false,
					modal: true,
					width: 360,
					height: 480,
					buttons: { 
						"Send": function() { sendMessage() },
						"Cancel": function() { $(this).dialog("close"); }
						}		
					});
	

			
			
			

	  $("#confirmDialog").dialog({	
			autoOpen: false,
			modal: true,
			width: 360,
			height: 380,
			buttons: { 
				"Close": function() { $(this).dialog("close"); }
				}		
			});
			
			$("#adminUserConfirmDialog").dialog({	
					autoOpen: false,
					modal: true,
					width: 360,
					height: 380,
					buttons: { 
						"Close": function() { $(this).dialog("close"); }
						}	
				});
	  
	  $('#questionButton').click(function(){
			$("#enquireDialog").dialog('open');
		})
					
		$("#tocDialog").dialog({	
			autoOpen: false,
			modal: true,
			width: 500,
			height: 450,
			buttons: { 
				"Agree": function() { agreeTerms() },
				"Disagree": function() { $(this).dialog("close"); }
				}		
			});
			
			
		$("#bidHistory").dialog({	
			autoOpen: false,
			modal: true,
			width: 500,
			height: 450,
			buttons: { 
				"Close": function() { $(this).dialog("close"); }
				}		
			});	
			

		$("#placeBid").dialog({	
			autoOpen: false,
			modal: true,
			width: 500,
			height: 450,
			buttons: { 
				"Close": function() { $(this).dialog("close"); }
				}		
			});	
			
		$('#viewTerms').click(function(){
			$("#tocDialog").dialog('open');
		})


		// if ($('#contactForm').length > 0) {		
		// 	$('#contactForm').validate();		
		// };

		if ($('#pressForm').length > 0) {		
			$('#pressForm').validate();		
		};	
				
		setInterval("reloadSidebar()", 7000 );	
})

function reloadSidebar()
{
	  jQuery.ajax({
	  	type: "POST",
	  	url: BASE + '/main/new_sidebar/',
		data: "",
		dataType: "html",
		success: function(html){					
			$('#listingsHolder').hide();
			$('#listingsHolder').html(html);
			$('#listingsHolder').fadeIn(1000);//removed for ie text aliasing problem
		}
	})
}


function agreeTerms()
{
	$("#tocButton").attr('checked', true);
	$("#tocDialog").dialog('close');
}

function sendMessage()
{
	var message = $('#dialogMessage').val();
	var listing_id = $('#dialogListingId').val();
		
	  jQuery.ajax({
	  	type: "POST",
	  	url: BASE + '/user/interest/' + listing_id,
		data: "message=" + message,
		dataType: "html",
		success: function(html){					
			//console.log(html);
			$('#enquireDialog').dialog("close");
			$('#confirmDialog').dialog("open");
		},
		error: function(){
			//console.log('error');
		}		
	})
}



//new account form carousel



jQuery(document).ready(function() {
  jQuery("#basic-carousel").jcarousel({
    scroll: 1,
	pager: function (carousel){
      return carousel.list.children("li").size() > 1;
    },
	 initCallback: mycarousel_initCallback
        // This tells jCarousel NOT to autobuild prev/next buttons
        //buttonNextHTML: null,
        //buttonPrevHTML: null,
	    //wrap:'last'
  });

});

jQuery(document).ready(function() {
  jQuery("#basic-carousel2").jcarousel({
    scroll: 1,
	pager: function (carousel){
      return carousel.list.children("li").size() > 1;
    },
	 initCallback: mycarousel_initCallback
        // This tells jCarousel NOT to autobuild prev/next buttons
        //buttonNextHTML: null,
        //buttonPrevHTML: null,
	    //wrap:'last'
  });

});

/**
 * We use the initCallback callback
 * to assign functionality to the controls
 */
function mycarousel_initCallback(carousel) {
    jQuery('.jcarousel-control a').bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
        return false;
    });

    jQuery('.jcarousel-scroll select').bind('change', function() {
        carousel.options.scroll = jQuery.jcarousel.intval(this.options[this.selectedIndex].value);
        return false;
    });

    jQuery('#mycarousel-next').bind('click', function() {
        carousel.next();
        return false;
    });

    jQuery('#mycarousel-prev').bind('click', function() {
        carousel.prev();
        return false;
    });
};