var ajax_req_entrypoint = "http:/luontaishoitoa.com/index.php";
var approot_url = "http://luontaishoitoa.com/";

$.extend({URLEncode:function(c){var o='';var x=0;c=c.toString();var r=/(^[a-zA-Z0-9_.]*)/;
  while(x<c.length){var m=r.exec(c.substr(x));
    if(m!=null && m.length>1 && m[1]!=''){o+=m[1];x+=m[1].length;
    }else{if(c[x]==' ')o+='+';else{var d=c.charCodeAt(x);var h=d.toString(16);
    o+='%'+(h.length<2?'0':'')+h.toUpperCase();}x++;}}return o;},
URLDecode:function(s){var o=s;var binVal,t;var r=/(%[^%]{2})/;
  while((m=r.exec(o))!=null && m.length>1 && m[1]!=''){b=parseInt(m[1].substr(1),16);
  t=String.fromCharCode(b);o=o.replace(m[1],t);}return o;}
});


	$(document).ready(function () {
		
		
		
		/**
		*	#####    FANCYBOXES START HERE ######
		*/
		
		$("a.zoom").fancybox();
		
		$(".fancy").fancybox({ 
				
			    'autoScale'         : false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'autoDimensions'    : false,
				'frameWidth'        : 600,
				'overlayShow'		: true,
				'frameHeight'       : 'auto'

				
		});
		$(".fancybig").fancybox({ 
				
			    'autoScale'         : false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'autoDimensions'    : false,
				'frameWidth'        : 850,
				'overlayShow'		: true,
				'frameHeight'       : 800

				
		});
		
		
		$(".kaavio").fancybox({ 
				titlePosition		: 'inside',
			    'autoScale'         : false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'autoDimensions'    : false,
				'frameWidth'        : 600,
				'overlayShow'		: true,
				'frameHeight'       : 'auto'

				
		});
		
		/**
		*	#####    FANCYBOXES END HERE ######
		*/
		
		
		/* ###### CYCLE SLIDESHOW ############# */
		$('.slideshow').cycle({
			fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		});
		
		$(".load_photos").click(function(e){
				e.preventDefault();
				var url = $(this).attr('href').split("=");
				$.get(ajax_req_entrypoint+$(this).attr('href'), {
							ajaxrequest: 'load_photos'
				}, function(data) {
					$(".photo_holder").html(data);
					$("a.zoom").fancybox();
				});
			});
		
		$("#toggle_admintools").click(function(e){
			e.preventDefault();
 		var sesval = $(this).attr('class');
 		$.post(ajax_req_entrypoint,{
 				ajaxrequest: "set_session_var",
 				sesvar: "hidden_tools",
 				sesval: sesval
 				},function(e) {
 					var url = window.location.href;
 					window.location = url;
 				}
 		)
 		});
 		
 		$("#denie_emails").click(function(){
 			if($("#denie_emails").is(':checked')) {
 				$("input[name=denie_emails]").attr('checked',true);
 			} else {
 				$("input[name=denie_emails]").attr('checked',false);
 			}
 		});
 		
 		$("#denie_sms").click(function(){
 			if($("#denie_sms").is(':checked')) {
 				$("input[name=denie_sms]").attr('checked',true);
 			} else {
 				$("input[name=denie_sms]").attr('checked',false);
 			}
 		});
		
		$("#listContestInfo").change(function(){
			window.location = "?contestinfo="+$(this).val();
		});
			
		
			
			$("#select_by_postalarea").change(function(e){
				e.preventDefault();
				var selected_val = $(this).attr('value');
				$.get(ajax_req_entrypoint+"?area="+selected_val+"&areaname="+$("#select_by_postalarea option[value='"+selected_val+"']").text(), {
					ajaxrequest: 'load_dists_by_parea'
				}, function(data) {
					$("#province_areas_list").html(data);
				});
			});
			
			
			/* ############## ADMIN POPUPS HERE ################### */
			
			$("#pagespopup").click(function(e){
				e.preventDefault();
				var pagespopup = window.open($(this).attr('href')+"&ajaxrequest=pagespopup",'Sivuhallinta','width=750px,height=600px,scrollbars=1');
				pagespopup.focus();
			});
			
			
			$("#photoalbum_popup").click(function(e){
				e.preventDefault();
				var photoalbumpopup = window.open("index.php?ajaxrequest=photoalbum_popup",'Kuva_albumien_hallinta','width=1000px,height=600px,scrollbars=1');
				photoalbumpopup.focus();
			});
			
			$("#lists_popup").click(function(e){
				e.preventDefault();
				var listspopup = window.open("?ajaxrequest=lists_popup",'Listojen_hallinta','width=1000px,height=600px,scrollbars=1');
				listspopup.focus();
			});
			
			$("#settings_popup").click(function(e){
				e.preventDefault();
				var settingspopup = window.open("?ajaxrequest=settings_popup",'Asetusten_hallinta','width=800px,height=600px,scrollbars=1');
				settingspopup.focus();
			});
			
			$(".toggle_next_ul").click(function(){
				var handle = $(this).parent('li').find('ul:first')
				handle.toggle();
				handle.find('li ul').hide();
			});
			
			
			$(".bugreport_bar a").click(function(e){
				e.preventDefault();
				$(this).parents('.bugreport_bar').find("div.bugreport_form").toggle();
			});
			
	
			//-------- ADMIN SLIDER ------------
			$('#admin_functions button').click(function() {
				
				$('#slidebottom').slideToggle(500);
				
			});
			
			//-------- TABIFIER -----------------
			var tabContainers = $('div.tabs > div');
			//tabContainers.hide().filter(':first').show();
			
			$('div.tabs ul.tabNavigation a').click(function () {
				tabContainers.hide();
				tabContainers.filter(this.hash).show();
				$('div.tabs ul.tabNavigation a').removeClass('selected');
				$(this).addClass('selected');
				return false;
			}).filter(this).click();
		
  
			//--------- VALIDATE FORM -----------
			$("#form").validate({
				rules: {
					userpass: "required",
					userpass_confirm: {
						equalTo: "#userpass"
					}
				}
			});
			
			//--------- VALIDATE FORM -----------
			$("#register_new_user").validate({
				rules: {
					password: "required",
					password_again: {
						equalTo: "#password"
					},
					usermail: "required",
					usermail_again: {
						equalTo: "#usermail"
					}
				}
			});
	

			//---------- BANNER TRACKER ----------
			$(".banner").click(function(e){
				
				// stop normal link click
				e.preventDefault();
	 
				// send request
				$.post(ajax_req_entrypoint, {
							ajaxrequest: 'bannertrack', 
							id: $(this).find('p').html(), 
							pageid: $(this).find('p').next().html()
				}, function(data) {
					// format and output result
	   
					//$(".banner").html(
					//url = $("true", data).text();
					url = data.replace(/[\r\n]+/g, "");
					
					//);
					
					//$(this).find('a:first').click();
					if(url != ''){window.open(url);}
					
				});
			});
			
			//contains bannerids loaded on page
			banner_array = new Array();
			
			$(".banner").each(function(e){
				
				banner_array.push($(this).find('p:first').html());
				
			});
			
			if(banner_array.length > 0) {
				// send request
				$.post(ajax_req_entrypoint, {
							ajaxrequest: 'bannerviews', 
							banner_ids: banner_array.join(',')}, 
							function(data) {
								
					// format and output result
				});
			}
			
						//---------- BANNER TRACKER ----------
			$(".banner2").click(function(e){
				// stop normal link click
				e.preventDefault();
	 
				// send request
				$.post(ajax_req_entrypoint, {
								ajaxrequest: 'bannertrack', 
								id: $(this).find('p').html(), 
								pageid: $(this).find('p').next().html()
				}, function(data) {
					// format and output result
	   
					//$(".banner").html(
					//url = $("true", data).text();
					
					url = data.replace(/[\r\n]+/g, "");
					//);
					
					//newWin = window.open('about:blank');
					//newWin.location.href = url;
					
					//$(this).find('a:first').click();
					if(url != ''){window.open(url);}
					
				});
			});

			
			//contains bannerids loaded on page
			banner_array2 = new Array();
			
			$(".banner2").each(function(e){
				
				banner_array2.push($(this).find('p:first').html());
				
			});
			
			if(banner_array2.length > 0) {
				// send request
				$.post(ajax_req_entrypoint, {
							ajaxrequest: 'bannerviews', 
							banner_ids: banner_array2.join(',')}, 
							function(data) {
								
					// format and output result
				});
			}
			
		   
			
		   //APPEND TO
		   $(".change_previous_input_value").click(function(){
			   id = "#" + $(this).prev().attr("id");
			   new_value =  $(this).find("#new_value").html();
			 $(id).attr("value", new_value);
		   });


			
			//---------- POSTALAREA SELECETLIST ACCORDING TO SELECTED PROVINCE ----------
			$("#dist_province").change(function(e){
				
				// send request
				$.post(ajax_req_entrypoint, {
							ajaxrequest: 'change_postalareas', 
							province: $("#dist_province").val(),
							referer: window.location.href
							}, function(data) {
					// format and output result
	   
					$("#dist_postalarea").html(
						data
					);
				});
			});
			
			//---------- BUILDS THE LIST VIEW FOR CLICKED PROVINCE IN DISTRIBUTORS SECTION ----------
			$(".province_trigger").click(function(e){
				e.preventDefault();
				$("#province_areas_list").html('');
				//$("#load_animation").css('display','block');
				// send request
				$.post(ajax_req_entrypoint, {
						ajaxrequest: 'get_province_areas',
						province: $(this).next().val(),
						referer: window.location.href
					}, function(data) {
					// format and output result
	   
					$("#province_areas_list").html(
						data
					);
					return false;
					//$("#load_animation").css('display','none');
				});
			});
			
			//---------- FETCHES NEWS OR SALES ANNOUNCEMENTS FOR DISTRIBUTOR IN THE DISTRIBUTOR PROFILE ----------
			$(".showdist_recent").click(function(e){
				
				// send request
				var distid = $("#ajax_distid").html();
				var more = $(this).parents(".jakelupaikat_box").find(".donot").html();
				$.post(ajax_req_entrypoint, {ajaxrequest: 'showdist_recent', distid: distid, more: more}, function(data) {
					// format and output result
	   
					$("#recent_and_sale_content").html(data);
					attatch_cufon();
				});
			});

			
			
			
			
			$(".multi_uploader_box").click(function() {  
				$(this).next().click();
			});
			
			/*
			$(".ajax_content").each(function(){ 
				var params = $(this).find('p:first').text().split(':?');
				
				var mid = params[0];
				var museid = params[1];
				var this_ajax_content = $(this);
			
				var get = params[2];
				$.post(ajax_req_entrypoint, {ajaxrequest: 'load_module', moduleid: mid, module_useid: museid, get: get}, function(module_data) {
					this_ajax_content.html(module_data);
					//if(mid == '82') { attatch_cufon(); }
					//if(mid == '1') { attatch_all(); }
					attatch_all_scripts(mid);
					
				});
			}); */
			
			$(".set_image_description").click(function(){
				$(this).next('div').toggle();
			});
			
			
			/* #### NARROW THE IMAGE WIDTH IN CONTENT IF IT EXCEEDS 400PX */
			$(".blog_body img").each(function() {
			  if($(this).width() > 400) {
				var h=$(this).height()/$(this).width()*400;
				  $(this).attr({height : h });
				  $(this).attr({width : "400"});
			   }
			});
			      
	delete_productpicture();
	delete_product();
	delete_confirm();
	//set_photo_description();
	add_user_album();
	delete_user_album();
	//set_photo_album_name();
	//startProgress();
	delete_user_album_use();

	delete_team();

	toggle_default();
	toggle_value();
	
	reveal_next();
	delete_team_photo();
	
	//edit_question();
	
	//delete_user_photo();
	//delete_user_album();
	
	confirm_delete();

	//attach_sliders();
	
  });
  
  
  
  function confirm_delete() {
	 $(".confirm_delete").click(function(){
		var new_display_state = ($(this).next().css('display') == 'none') ? 'inline' : 'none';
			$(this).next().css('display',new_display_state);
	}); 
  }
  
  
 	 /**
	  *	@param searchString: the current url
	  *	@param paramName: the param we are looking for ( f.ex. 'ref' )
	  *	@return val <- the paramNames value if existed
	  */
	function getParameter(searchString,paramName) {
	  var searchStringEnd = searchString.split("?");
	  if(searchStringEnd.length > 1) {
	     var params = searchStringEnd[1].split("&");
	      var val; 
	
		  for (i=0;i<params.length;i++) {
		    val = params[i].split("=");
		    if (val[0] == paramName) {
		      return unescape(val[1]);
		    }
		  }
	  }
	  return null;
	}
  
  	
  	function stringReverse(textString) {
			   if (!textString) return '';
			   var revString='';
			   for (i = textString.length-1; i>=0; i--)
			       revString+=textString.charAt(i)
			   return revString;
			}
		
			function emLink(name, server)
			{    
			     // the name and domain are reversed into the correct reading format
			     // the email link is then created on your website
			     // Because there is no actual email address in the expected format
			     // the email harvesters never see the links on your website.
			     var rname = stringReverse(name);
			     var rserver = stringReverse(server);
			     var email = rname + "@" + rserver;
			     var mailText = '<a href="mailto:' + email +'">' + email + '</a>';

			     return mailText;
			}
  
  function changeMainPic(id,dest,count){
	  for(i=1;i<=count;i++){ 
			document.getElementById(i).style.display = 'inline';
			}
		document.getElementById(id).style.display = 'none';
		document.getElementById('main_pic').src = dest;
	}	
	
	function addthis_over(i){
return addthis_open(i, '', '[URL]', '[TITLE]');
}

function str_replace (search, replace, subject, count) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Gabriel Paderni
    // +   improved by: Philip Peterson
    // +   improved by: Simon Willison (http://simonwillison.net)
    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +   bugfixed by: Anton Ongson
    // +      input by: Onno Marsman
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +    tweaked by: Onno Marsman
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   input by: Oleg Eremeev
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Oleg Eremeev
    // %          note 1: The count parameter must be passed as a string in order
    // %          note 1:  to find a global variable in which the result will be given
    // *     example 1: str_replace(' ', '.', 'Kevin van Zonneveld');
    // *     returns 1: 'Kevin.van.Zonneveld'
    // *     example 2: str_replace(['{name}', 'l'], ['hello', 'm'], '{name}, lars');
    // *     returns 2: 'hemmo, mars'
 
    var i = 0, j = 0, temp = '', repl = '', sl = 0, fl = 0,
            f = [].concat(search),
            r = [].concat(replace),
            s = subject,
            ra = r instanceof Array, sa = s instanceof Array;
    s = [].concat(s);
    if (count) {
        this.window[count] = 0;
    }
 
    for (i=0, sl=s.length; i < sl; i++) {
        if (s[i] === '') {
            continue;
        }
        for (j=0, fl=f.length; j < fl; j++) {
            temp = s[i]+'';
            repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
            s[i] = (temp).split(f[j]).join(repl);
            if (count && s[i] !== temp) {
                this.window[count] += (temp.length-s[i].length)/f[j].length;}
        }
    }
    return sa ? s : s[0];
}




function edit_question() {
	
	$(".edit_question").dblclick(function(){
		var obj = $(this);
		var elem_id = $(this).attr("id").split("_");
		var question_id = elem_id[1];
		var question = $(this).text();
		var contest_info_id = elem_id[2];
		$.post(ajax_req_entrypoint,{
			ajaxrequest: "contest_admin",
			moduleaction: "edit_question",
			question_id: question_id,
			question: question,
			contest_info_id: contest_info_id
		},function(response) {
			obj.replaceWith(response);
			save_question();
		});
	});
	
	
}

function save_question() {
	
	$("form[name=edit_question]").submit(function(submit){
		submit.preventDefault();
		var obj = $(this);
		var question_id = $(this).find("input[name=question_id]").val();
		var question = $(this).find("textarea[name=question]").val();
		var contest_info_id = $(this).find("input[name=contest_info_id]").val();
		$.post(ajax_req_entrypoint,{
			ajaxrequest: "contest_admin",
			moduleaction: "update_question",
			question_id: question_id,
			question: question,
			contest_info_id: contest_info_id
		},function(response) {
			obj.replaceWith(response);
		});
	});
	
	
}



function photo_slider() {
	$("#content-slider").slider({
			    animate: true,
			    change: handleSliderChange,
			    slide: handleSliderSlide
			  });
}


function getProgress(unique_id){
		
			$.post(ajax_req_entrypoint, {ajaxrequest: 'getprogress', progress_key: unique_id}, function(data) {
			// format and output result
			console.log(".progress" + unique_id);
			console.log(data.length);
			if(data.length>4){
				alert('Tiedosto on liian suuri (max. 40Mb), lataus katkaistaan.');
				window.location=data;
			}else{
			var percent = Number(data);
			 $(".progress" + unique_id).find(".progressmeter").html(data+"%");	
			 $(".progress" + unique_id).find(".progressmeter").css("color","white");
			 $(".progress" + unique_id).find(".progressmeter").css("background","green");
			 $(".progress" + unique_id).find(".progressmeter").css("height","15px");
			 $(".progress" + unique_id).find(".progressmeter").css("width",percent+"px");
			 $(".progress" + unique_id).find(".progressmeter").fadeIn("slow");
			   console.log($(".progress" + unique_id).find(".progressmeter").css("width"));
			   console.log(percent+'%');
			 $(".progress_percent" + unique_id).html(percent+'%');
			 $(".progress" + unique_id).css("display","block");
				 setTimeout(function(){ getProgress(unique_id) }, 1000);	
			}
			});
		
}


		function MM_openBrWindow(theURL,winName,features) { //v2.0
			window.open(theURL,winName,features);
		}
/*
function startProgress(){

	$('.multiuploader_loader').change(function(){
		
		var unique_id = $(this).next("p").html();
		console.log(unique_id);
		    //setTimeout("getProgress(" + unique_key + ")", 1000);
		   getProgress(unique_id);
		   

		    

	});
} */

function reveal_next() {
				$(".reveal_next").click(function(){ 
					
				  $(this).next(".reveal_this").show();
				  $(this).css("display","none");
			   });
			}
			
			
/**
#####################################################################################################################################
	Function toggle_default()
	21.11.09
	Toggle the default value of texxt field or textarea on focus or blur
	<input type="text" class="toggle_default" value="kirjoita">
#####################################################################################################################################	
*/			
swapValue = [];			
function toggle_default() {

	$(".toggle_default").each(function(i){
	   swapValue[i] = $(this).val();
	   $(this).focus(function(){
		  if ($(this).val() == swapValue[i]) {
			 $(this).val("");
		  }
		  $(this).addClass("focus");
	   }).blur(function(){
		  if ($.trim($(this).val()) == "") {
			 $(this).val(swapValue[i]);
		 $(this).removeClass("focus");
		  }
	   });
	});
}

swapValue2 = [];			
function toggle_value() {

	$(".toggle_value").each(function(i){
	   swapValue2[i] = $(this).val();
	   $(this).focus(function(){
		  if ($(this).val() == swapValue2[i]) {
			 $(this).val("");
		  }
		  $(this).addClass("focus");
	   }).blur(function(){
		  if ($.trim($(this).val()) == "") {
			 $(this).val(swapValue2[i]);
		 $(this).removeClass("focus");
		  }
	   });
	});
}
		


/**
#####################################################################################################################################
	Function delete_user_album()
	9.10.2009
	Deletes a user album
#####################################################################################################################################
*/
function delete_user_album(){
	/*
	$(".delete_user_album").click(function(keypress){
		
		var id = $(this).next("p").html();
		var div = $(this).parents("div.img_albumit");
		
		$.post(ajax_req_entrypoint, { 
					ajaxrequest: 'delete_user_album', 
					delete_user_album: id
					}, function(data) {
								div.fadeOut("fast");
								$(".album_content").html("");
		});
	}); */
}

/**
#####################################################################################################################################
	Function add_user_album()
	9.10.2009
	Creates a user album
#####################################################################################################################################	
*/
function add_user_album(){
	/*
	$("form[name='add_user_album_form']").submit(function(submit) {
		submit.preventDefault();
		var name = $(this).find("input[name='album_name']").val();
		var name_area = $(this).find("input[name='album_name']");
		$.post(ajax_req_entrypoint, { 
					ajaxrequest: 'new_user_album', 
					new_album: name
					}, function(data) {
								$(".img_add_area").after(data);
								name_area.val('');
						if(typeof(attach_sliders)!='function'){
						attach_sliders();
					}
								delete_user_album();
		});
	})
	*/;
	/*
	$(".add_user_album").click(function(keypress){
		keypress.preventDefault();

		var name = $(this).prev("input").val();
		var name_area = $(this).prev("input");	
		
		$.post(ajax_req_entrypoint, { 
					ajaxrequest: 'new_user_album', 
					new_album: name
					}, function(data) {
								$(".img_add_area").after(data);
								name_area.val('');
								attach_sliders();
								delete_user_album();
		});
	});
*/	
}

/**
#####################################################################################################################################
	DELETE TEAM PHOTO
#####################################################################################################################################
*/

function delete_team_photo(){
	$(".delete_team_photo").click(function(keypress){
		
		var params = $(this).next("p").html().split(':?');
		var id = params[1];
		var holder = $(this);
		
		$.post(ajax_req_entrypoint, { 
					ajaxrequest: 'delete_team_photo', 
					team_photo_id: id
					}, function(data) {
								holder.parents("div.added_images").fadeOut("fast");
		});
	});	
}

/**
#####################################################################################################################################
	DELETE USER PHOTO
#####################################################################################################################################
*/

function delete_user_photo(){
	/*
	$(".delete_user_photo").click(function(keypress){
		
		var params = $(this).next("p").html().split(':?');
		var aid = params[0];
		var id = params[1];
		var holder = $(this);
		
		$.post(ajax_req_entrypoint, { 
					ajaxrequest: 'delete_user_photo', 
					delete_from_user_album: aid,
					delete_user_photo: id
					}, function(data) {
								holder.parents("div.added_images").fadeOut("fast");
		});
	});	
	*/
}

/**
#####################################################################################################################################
	DELETE delete_user_album_use
#####################################################################################################################################
*/

function delete_user_album_use(){
	
	$(".delete_user_album_use").click(function(keypress){
		
		var params = $(this).next("p").html().split(':?');
		var aid = params[0];
		var pageid = params[1];
		var holder = $(this);
		
		$.post(ajax_req_entrypoint, { 
					ajaxrequest: 'delete_user_album_use', 
					aid: aid,
					pageid: pageid
					}, function(data) {
								holder.parent("div").fadeOut("fast");
		});
	});	
}

/**
#####################################################################################################################################
	DELETE PRODUCTPICTURE
#####################################################################################################################################
*/

function delete_productpicture(){

	$(".delete_productpicture").click(function(keypress){
			
		var params = $(this).next("p").html().split(':?');
		var id = params[1];
		var holder = $(this);
		
		$.post(ajax_req_entrypoint, { 
					ajaxrequest: 'delete_productphoto', 
					/*delete_from_user_album: aid,*/
					delete_productphoto: id
					}, function(data) {
								holder.parents("div.added_images").fadeOut("fast");
									
		});
	});	
}

/**
#####################################################################################################################################
	DELETE PRODUCT
#####################################################################################################################################
*/

function delete_product(){

	$(".delete_product").click(function(keypress){
			
		var id = $(this).next("p").html();
			
		var holder = $(this);
		
		$.post(ajax_req_entrypoint, { 
					ajaxrequest: 'delete_product', 
					/*delete_from_user_album: aid,*/
					delete_product: id
					}, function(data) {
								holder.parent('span').parent('li').fadeOut("fast");
									
		});
	});	
}

/**
#####################################################################################################################################
	DELETE TEAM
#####################################################################################################################################
*/

function delete_team(){

	$(".delete_team").click(function(keypress){
			
		var team = $(this).next("p").html();
			
		var holder = $(this);
		
		$.post(ajax_req_entrypoint, { 
					ajaxrequest: 'delete_team', 
					/*delete_from_user_album: aid,*/
					delete_team: team
					}, function(data) {
								holder.parents('div.team_member').fadeOut("fast");
									
		});
	});	
}

function delete_confirm() {

			$(".delete_options_reveal").click(function(){ 
			   $(this).prev(".delete_options").css("display","inline");
		   });
		   
		   $(".delete_cancel").click(function(){
			   $(".delete_options").css("display","none");
		   });
}

/**
#####################################################################################################################################
	SET PHOTO ALBUM NAME 13.11.2009
	Sets new value for album name according recieved album id
	@response success or error message
#####################################################################################################################################
*/
	
var last_saved_album_name;

function set_photo_album_name() {
	
/*
	$("form[name='save_album_name']").submit(function(submite){
	
	submite.preventDefault();
	var thisform = $(this);
	var newname = $(this).find("input[name='album_name']").val();
	var aid = $(this).find("input[name='albumid']").val();
	
	if(last_saved_album_name != newname) {
	
		if(newname && aid) {
			$.post(ajax_req_entrypoint,{
				
				ajaxrequest: 'set_photo_album_name',
				album_name: newname,
				albumid: aid
				
			},function(notice){
				thisform.find("input:last").after(notice);
				setTimeout(function() { thisform.find(".notice").fadeOut("slow"); },1000);
				last_saved_album_name = newname;
			});
		
		}
	} else {
		var notice = "<p class=\"notice_success notice\">Tallennettu</p>";
		thisform.find("input:last").after(notice);
		setTimeout(function() { thisform.find(".notice").fadeOut("slow"); },1000);
	}
	
	});
*/
}


/**
#####################################################################################################################################
	HANDLE PHOTO SLIDER CHANGE
#####################################################################################################################################
*/
	
function handleSliderChange(e, ui)
{
  var maxScroll = $("#content-scroll").attr("scrollWidth") - $("#content-scroll").width();
  $("#content-scroll").animate({scrollLeft: ui.value * (maxScroll / 100) }, 1000);
}

/**
#####################################################################################################################################
	HANDLE PHOTO SLIDERS SLIDE
#####################################################################################################################################
*/
function handleSliderSlide(e, ui)
{
  var maxScroll = $("#content-scroll").attr("scrollWidth") - $("#content-scroll").width();
  $("#content-scroll").attr({scrollLeft: ui.value * (maxScroll / 100) });
}

/**
#####################################################################################################################################
	ATTATCH SLIDERS
#####################################################################################################################################
*/	
function attach_sliders(){
	//---------- CURSOR HOVER THINGIE ----
		   $(".hoverpointer").hover(function(){
			document.body.style.cursor = 'pointer';
			  },function(){
			document.body.style.cursor = 'default';
			  });
	
		   //----------- NEW NEXT SLIDER ------
		   $(".slide_next").click(function(){
			   
			  $(this).next().slideToggle("fast");
		   });
		   
		   //----------- NEW NEXT SLIDER ------
		   $(".hide_onclick").click(function(){
			  $(this).css("display","none");
		   });
		   //----------- NEW NEXT SLIDER ------
		   $(".show_prev_hide_this_onclick").click(function(){
			  $(this).parent().prev().css("display","inline");
			  $(this).parent().css("display","none");
		   });
		   
		   //----------- NEW NEXT and PREVIOUS SLIDER ------
		   $(".slide_next_and_prev").click(function(){
			  $(this).prev().slideToggle("fast");
			  $(this).next().slideToggle("fast");
		   });	
		   
		   
		   $(".delete_options_reveal").click(function(){
			   $(this).prev(".delete_options").css("display","block");
		   });
		   
		   $(".delete_cancel").click(function(){
			   $(".delete_options").css("display","none");
		   });
		   
		   $(".reveal_prev").click(function(){
			  $(this).parents(".reveal_this").css("display","inline");
			  $(this).css("display","none");
		   });
		   
}



function clockpick(){
			//---------- TIME PICKER -------------
			$(".clockpick").clockpick({
				starthour : 00,
				endhour : 23,
				showminutes : true
			}); 
			//console.log('clockpick');
}

function datepick(){
				//---------- DATE PICKER -------------
			$(".datepicker").datepicker();
			//console.log('datepick');
}


function show_only(value){
		switch(value){
			case '1' : 
			document.getElementById('area1').click();
			
			break;
			
			case '2' : 
			document.getElementById('area2').click();
			break;
			
			case '3' : 
			document.getElementById('area3').click();
			break;
			
			case '4' : 
			document.getElementById('area4').click();
			break;
			
			case '5' : 
			document.getElementById('area5').click();
			break;
			
			case '6' :
			document.getElementById('area6').click();
			break;
		}
		
	}


	function vaihdaKartta(value, value2, root){
		
		var kartta = document.getElementById('kartta');
		
		switch(value){
		case "etelasuomi" : kartta.src=root+"map/jakelupisteet_map_etelasuomi.png"; 
		//document.getElementById('maakuntanimi').innerHTML = value2;
		break;
			
		case "itasuomi" : kartta.src=root+"map/jakelupisteet_map_ita_suomi.png"; 
		//document.getElementById('maakuntanimi').innerHTML = value2;
		break;
		
		case "lansisuomi" : kartta.src=root+"map/jakelupisteet_map_lansisuomi.png"; 
		//document.getElementById('maakuntanimi').innerHTML = value2;
		break;
		
		case "lapinlaani" : kartta.src=root+"map/jakelupisteet_map_lapinlaani.png"; 
		//document.getElementById('maakuntanimi').innerHTML = value2;
		break;
		
		case "oulunlaani" : kartta.src=root+"map/jakelupisteet_map_oulunlaani.png"; 
		//document.getElementById('maakuntanimi').innerHTML = value2;
		break;
		
		default : kartta.src=root+"map/jakelupisteet_map.png";
		//document.getElementById('maakuntanimi').innerHTML = value2;
		}
	}	

/**
#####################################################################################################################################
	ATTATCH ALL SCRIPTS
#####################################################################################################################################
*/
function attatch_all_scripts(mid){
	
		$('div.top_boxes').pngFix( );
		$('div.logo').pngFix( );
		
		
		//Attach scripts per module mid = module id
		switch(mid){
			case '7' : //Attach comment send ajax 
				send_comment();
				delete_comment(); 
				reveal_next();
				toggle_default();
			break;
			
			default: break;
		}
		
		//tooltips();
		
		input_grows();
		
		
	}

/**
#####################################################################################################################################
	Javascript equivalent to print_r();
#####################################################################################################################################
*/
	
function print_r(theObj){
  if(theObj.constructor == Array ||
     theObj.constructor == Object){
    document.write("<ul>")
    for(var p in theObj){
      if(theObj[p].constructor == Array||
         theObj[p].constructor == Object){
document.write("<li>["+p+"] => "+typeof(theObj)+"</li>");
        document.write("<ul>")
        print_r(theObj[p]);
        document.write("</ul>")
      } else {
document.write("<li>["+p+"] => "+theObj[p]+"</li>");
      }
    }
    document.write("</ul>")
  }
}



