$(function(){
	$("#viewworkshop a").bind("click", function(){
		$("#supplypanel").fadeIn("slow").positionBy({
			target:$("#viewworkshop"),
			targetPos: 3,
			elementPos:0
		});
		return false;
	});
	
	$(".accordion").bind("click", function(){
		if($(this).next().css("display")=="none"){
			$(this).parent().addClass("subnavon");
			$(this).next().fadeIn();
		}else{
			$(this).parent().removeClass("subnavon");
			$(this).next().fadeOut();
		}
	});
	
	
	
	var options = {selectCallback: callbackFunction};
	$("select.pagesizeDown").niceSelect({
		virtualSelectClass:"pagesizeDown",
		virtualInputClass: "pagesizeDownInput",
		selectCallback: callbackFunction
	});
	$("select.sortbyDown").niceSelect({
		virtualSelectClass:"sortbyDown",
		virtualInputClass: "sortbyDownInput",
		selectCallback: callbackFunction
	});
	
	/*email a friend*/
	$("#emailfriend").bind("click", function(){
		if($("#sendcontainer").children().length<1)	{
			$.ajax({
				type: "GET",
				url: "sendfriend.html",
				beforeSend: function(){
					$("#sendcontainer").html("loading...").positionBy({
						target:$("#emailfriend"),
						targetPos: 0,
						elementPos:1
					});
				},
				success: function(data){
					$("#sendcontainer").html(data);
						$('#sendmail').validate({
								errorClass:'error',	
								highlight:function(element, errorClass) {
									$("#sendmail").find("label[for="+element.id+"]").addClass(errorClass);
								},
								unhighlight:function(element, errorClass) {
									$("#sendmail").find("label[for="+element.id+"]").removeClass(errorClass);
								},
								rules:{
									yourname:{required:true},
									friendname:{required:true},
									zip:{required:true,
				 							number: true},
									youraddress:{required:true,
				 							email:true},
									friendaddress:{required:true,
				 									email:true}
								},
								messages:{
									yourname: "",
									friendname: "",
									zip: "",
									youraddress :"",
									friendaddress: ""
								},
								errorElement:"span",
								submitHandler: function(form) {
									$.post("sendmail.aspx",
										{
										emailtype:$('#mailtype').val(),
										reguser:$('#yourname').val(),
										yourname:$('#yourname').val(),
										youraddress:$('#youraddress').val(),
										friendname:$('#friendname').val(),
										friendaddress:$('#friendaddress').val(),
										Comments:$('#Comments').val()					
										},
										function(responseText){	
											if(responseText=="True"){
												$("#sendinfo").html("Your e-mail to your friend was sent successfully.");
											}else{
												$("#sendinfo").html("Your e-mail to your friend was not sent successfully due to some reasons.");
											}
											$("#send").css("height", "auto");
											$("#sendinfo").show();
											$('#tb-info').hide();
											
										}
									);
							}
						});
						
						$('#btn-close').bind("click", function(){
							$("#sendcontainer").hide();
						});

				}
			});
		
		
		}else
		{
			$("#sendcontainer").show();
			$("#send").css("height", "404px");
			$("#sendinfo").hide();  
			$('#tb-info').show();
			
		}
		return false;
	});
	
	
	$(".arrowico").bind("click", function(){

	});
	
	
	
});
function callbackFunction(vals, select){
	__doPostBack("", "");
}

