(function ($) {
		"use strict";

    $(document).ready(function () {
    	$.get("ajax/active_now.php", function() { });
    	
    	
        $('#login_username').focus();
        // Open formview
          $("#form_link").click(function () {
            $("#form_link").slideUp(500,function () {
                $("#form_fill").slideDown(500);
                $('[name=text]').focus();
            });
            return false;
          });
        
        //popup
        $('[click=edit_help]').click(function () {
            $('<div id="dim_background" style="display: none;"></div>').appendTo('body');
            $('#dim_background')
            .css("height", $(document).height())
            .show()
            .css({
                'position' : 'fixed',
                'top' : '0px',
                'left' : '0px',
                'border' : '2px solid #333333',
                'background' : '#000000',
                'opacity' : '0.4',
                'width' : '100%',
                'z-index' : '100'
            });
            //console.log("window");
            $(window).bind("resize", function () {  
              $("#dim_background").css("height", $(window).height());  
            }); 
            //console.log("window done");
            $('<div id="help_edit_box" style="display: none;"></div>').appendTo('body');
            $('#help_edit_box')
            .show()
            .css({'position' : 'fixed',
                'border' : '2px solid #333333',
                'height' : '200px',
                'width'  : '300px',
                'background' : '#cccccc',
                'z-index' : '200',
                'top' : '50%',
                'left' : '50%',
                'margin-top' : '-100px',
                'margin-left' : '-150px',
                'padding' : '10px'
              });
              //console.log("ajax.php?module=Jb-HelpText&view=edit&name=" + this.id);
            //$('#help_edit_box').load("pages/helptext/edit.php?name=" + $(this).attr('name'), function () {
            $('#help_edit_box').load("ajax.php?module=helptext&view=edit&name=" + $(this).attr('name'), function () {
              $('#help_submit').click(function () {
                //console.log('Data: ' + $('#help_name').val() + $('#help_text').val());
                //console.log("ajax.php?module=Jb-HelpText&view=save&name=" + $('#help_name').val() + "&text=" + $('#help_text').val());
                $.get("ajax.php?module=helptext&view=save&name=" + $('#help_name').val() + "&text=" + $('#help_text').val());
                $('#dim_background').remove();
                $('#help_edit_box').remove();
              });
              $(document).keydown(function (e) {
                  if (parseInt(e.keyCode, 10) === 27) {
                      $('#dim_background').remove();
                      $('#help_edit_box').remove();
                  }
              });
              $('#dim_background').click(function() {
                      $('#dim_background').remove();
                      $('#help_edit_box').remove();
              });
            });
        });

/*
				var closetimer;
        closetimer = 0;    
        $('[tooltip_old]').hover(function(e){
//          console.log('Mouse over' + $(this).attr('tooltip'));
						var current;
            current = this;
            closetimer = window.setTimeout(function () {
                    $("#pop").html($(current).attr('tooltip'));
                    $("#pop").css("top",($(current).offset().top+20)+"px");
                    $("#pop").css("left",$(current).offset().left+"px");
                    $("#pop").show();
                    $("#pop").mouseleave(function () {
                      $("#pop").hide();
                    });
            }, 500);
        }, function () {
          $("#pop").hide();
          window.clearTimeout(closetimer); closetimer = null;
        });
*/
        $('[tooltip]').tooltip({ 
            bodyHandler: function () { 
                return $(this).attr('tooltip'); 
            }, 
            showURL: false,
            fade: 500,
            opacity: 1.00
        });

/* 
        $('[tooltip]').hover(function(){
        	$(this).removeAttr('title');
        });
        $('[tooltip]').tipTip({	activation: "hover",
																keepAlive: false,
																maxWidth: "400px",
																edgeOffset: 3,
																defaultPosition: "bottom",
																delay: 400,
																fadeIn: 200,
																fadeOut: 200,
																attribute: "tooltip",
																content: false // HTML or String to fill TipTIp with
													});
*/        
    });

/*
    $(window).load(function () {
    });
    $(document).ready(function () {
      $('<div id="pop" class="tooltip">Text here </div>').appendTo("body"); //.hide().fadeIn("slow");
      $("#pop").hide();
      //console.log('Adding popupdiv...');
      
    });
*/

  $(document).ready(function () {
//  $(window).load(function () {
      //return true;
//    $('<div id="submenu" style="position: absolute;"><div id="inner_submenu"></div></div>').appendTo("body"); //.hide().fadeIn("slow");
//    $("#submenu").hide();
    //$(".mainmenu").css('background','yellow');
      var menuLoaded, timeout, closetimer, mainShown, subShown, menuItem;
      menuLoaded = false;
      timeout    = 50;
      closetimer = 0;
      mainShown = false;
      subShown = false;
      menuItem = 0;
      //$('#page').mouseover(function () {
      
      if (menuLoaded) {
        return false;
      }
      menuLoaded = true;
      //$('#hidden_menues').load('ajax/load_menu.php', '',
      //function () {
          $('.submenu a.active').parent().css({background:'#ffb973'});

          $("#menu .mainmenu a").click(function () {
            //return false;
          });
          $("[menu=dropdown]").mouseenter(function(e) {
            if (menuItem !== $(this).attr('id')){
              $(".visible_submenu").hide().attr('class','hidden_submenu');
            }
            //console.log('am In: ' + menuItem);
            menuItem = $(this).attr('id');
            if ($("#submenu_" + menuItem).html() !== '') {
              if(closetimer) {  window.clearTimeout(closetimer); closetimer = null;}
              if (!mainShown) {
                //console.log('m In: ' + menuItem);
                $("#submenu_" + menuItem)
                .css({'position':'absolute', 'z-index':'200' 
                    }).attr('class','visible_submenu');
                if (menuItem === 'forum') { // || menuItem === 'language'
                  $("#submenu_" + menuItem).css("top",($(this).offset().top+23)+"px");
                } else {
                  $("#submenu_" + menuItem).css("top",($(this).offset().top+32)+"px");
                }
                $("#submenu_" + menuItem).css("left",($(this).offset().left-10)+"px");
                $("#submenu_" + menuItem).show();
                
                $('.visible_submenu .submenu').hover(function () {
                  $(this).css({background:'#ffb973'});
                }, function () {
                  $(this).css({background:'none'});
                  $('.submenu a.active').parent().css({background:'#ffb973'});
                });
                mainShown = true;
                
              }
            }
          });
          $(".hidden_submenu").mouseenter(function () {
              //console.log('s In: ' + menuItem);
            subShown = true;
            mainShown = false;
          });
          $(".hidden_submenu").mouseleave(function () {
              //console.log('s Out: ' + menuItem);
            subShown = false;
            closetimer = window.setTimeout(function () {
              if (!subShown && !mainShown) {
                $("#submenu_" + menuItem).hide().attr('class','hidden_submenu');
              }
            }, timeout);
          });
          $("[menu=dropdown]").mouseleave(function () {
              //console.log('m Out: ' + menuItem);
            mainShown = false;
            closetimer = window.setTimeout(function () {
              if (!subShown && !mainShown) {
                $("#submenu_" + menuItem).hide().attr('class','hidden_submenu');
              }
            }, timeout);
          });
      //});
      //});
      
      $('#follow_menu_item').mouseenter(function () {
            if (menuItem !== $(this).attr('id')){
              $(".visible_submenu").hide().attr('class','hidden_submenu');
            }
            //console.log('am In: ' + menuItem);
            menuItem = $(this).attr('id');
            //console.log($("#follow_menu").html());
            if ($("#follow_menu").html() !== '') {
              if(closetimer) {  window.clearTimeout(closetimer); closetimer = null;}
              if (!mainShown) {
                //console.log('m In: ' + menuItem);
                $("#follow_menu")
                .css({'position':'absolute', 'z-index':'200' 
                    }).attr('class','visible_submenu');
                $("#follow_menu").css("top",($(this).offset().top+19)+"px");
                $("#follow_menu").css("left",($(this).offset().left-10)+"px");
                $("#follow_menu").show();
                mainShown = true;
              }
            }
      });
          $("#follow_menu").mouseenter(function () {
              //console.log('s In: ' + menuItem);
            subShown = true;
            mainShown = false;
          });
          $("#follow_menu").mouseleave(function () {
              //console.log('s Out: ' + menuItem);
            subShown = false;
            closetimer = window.setTimeout(function () {
              if (!subShown && !mainShown) {
                $("#follow_menu").hide().attr('class','follow_menu');
              }
            }, timeout);
          });
          $("#follow_menu_item").mouseleave(function () {
              //console.log('m Out: ' + menuItem);
            mainShown = false;
            closetimer = window.setTimeout(function () {
              if (!subShown && !mainShown) {
                $("#follow_menu").hide().attr('class','follow_menu');
              }
            }, timeout);
          });
          $("#follow_menu_item").click(function () {
            return false;
          });
  });

  $('document').ready(function () {
    $('cite').each(function () {
      $(this).attr('height', $(this).height());
    });
    $('cite').css({'overflow': 'hidden'});
    $('cite').animate({height: '14px'}, 500);
    $('cite').hover(function () {
    	var height;
      //$('cite').css('height', '');
      height = $(this).attr('height');
      $(this).stop().animate({height: height+'px'}, 500);
    },
    function () {
      $(this).stop().animate({height: '10'}, 500);
    });
  });


  $('document').ready(function () {
    $('#vip_activate').change(function () {
    	var n;
      n = $(this).val();
      if (n > 0) {
        $('#vip_club').show();
      } else {
        $('#vip_club').hide();
      }
    });
  });
  
  
  // calendar.js...
  $('document').ready(function () {

      if (!$('[name=pay]').attr('checked')) {
          $('#event_cost').hide();
      }
      $('[name=pay]').click(function () {
        if (!$('[name=pay]').attr('checked')) {
            $('#event_cost').hide();
        } else {
            $('#event_cost').show();
        }
      });


    $('.language_key').click(function () {
    		var thisKey;
        thisKey = $(this);
        $('<div id="dim_background" style="display: none;"></div>').appendTo('body');
        $('#dim_background')
        .css("height", $(document).height())
        .show()
        .css({
            'position' : 'fixed',
            'top' : '0px',
            'left' : '0px',
            'border' : '2px solid #333333',
            'background' : '#000000',
            'opacity' : '0.4',
            'width' : '100%',
            'z-index' : '100'
  
        });
        //console.log("window");
        $(window).bind("resize", function () {  
          $("#dim_background").css("height", $(window).height());  
        }); 
        //console.log("window done");
        $('<div id="language_box" style="display: none;">' +
          $(this).attr('id') +
          ' - ' + $(this).attr('lang') + 
          ' <textarea id="language_translation"></textarea><input type="submit" id="translation_save" value="Spara"></div>').appendTo('body');
        $('#language_translation')
        .css({'width'  : '270px',
              'height' : '150px'});

        $('#language_box')
        .show()
        .css({'position' : 'fixed',
            'border' : '2px solid #333333',
            'height' : '200px',
            'width'  : '300px',
            'background' : '#cccccc',
            'z-index' : '200',
            'top' : '50%',
            'left' : '50%',
            'margin-top' : '-100px',
            'margin-left' : '-150px',
            'padding' : '10px'
        });

        $('#translation_save').click(function () {

            //save data from textarea into database
            $.get("ajax/save_language.php?tag=" + thisKey.attr('id') + "&text=" + $('#language_translation').val());

            //update page with new text
            thisKey.html($('#language_translation').val());

            $('#dim_background').remove();
            $('#language_box').remove();
        });

        $(document).keydown(function(e){
            if (e.keyCode === 27) {
                $('#dim_background').remove();
                $('#language_box').remove();
            }
        });
        $('#dim_background').click(function() {
                $('#dim_background').remove();
                $('#help_edit_box').remove();
        });
    });
    
    $(':submit').click(function () {
        var ok, fields, field, re;
        ok = true;
        fields = '';
        $('.mandatory').each(function () {
            if (($(this).val() === '') || ($(this).val() === '0') || ($(this).val() === '---') || ($(this).val() === 'Select') || ($(this).val() === '0000-00-00 00:00:00')) {
                re = new RegExp(/<span.*<\/span>/);
                field = $(this).parent().prev().html();
                field = field.replace(re, '');
                fields = fields + field + ', ';
                $(this).css({'border-width': '3px'});
                ok = false;
            }
        });
        if (!ok) {
            //fields = fields.replace(new RegExp("[\,|\s|\:]+$", "g"), "");
            fields = fields.replace(/\s+$/g,"");
            fields = fields.replace(/\,+$/g,"");
            fields = fields.replace(/\s+$/g,"");
            fields = fields.replace(/\:+$/g,"");
            alert(fields);
            return false;
        }
    });


      $('#gallery_image').click(function () {
        //alert('klick');
            $('<div id="dim_background" style="display: none;"></div>').appendTo('body');
            $('#dim_background')
            .css("height", $(document).height())
            .show()
            .css({
                'position' : 'fixed',
                'top' : '0px',
                'left' : '0px',
                'border' : '2px solid #333333',
                'background' : '#000000',
                'opacity' : '0.4',
                'width' : '100%',
                'z-index' : '100'
            });
            //console.log("window");
            $(window).bind("resize", function () {  
              $("#dim_background").css("height", $(window).height());  
            }); 
            //console.log("window done");
            $('<div id="image_box" style="display: none;"></div>').appendTo('body');
            $('#image_box')
            .show()
            .css({'position' : 'fixed',
                'border' : '3px solid #333333',
                'height' : '500px',
                'width'  : '500px',
                'background' : '#cccccc',
                'z-index' : '200',
                'top' : '50%',
                'left' : '50%',
                'margin-top' : '-250px',
                'margin-left' : '-250px',
                'padding' : '0px'
              });
              //console.log("ajax.php?module=Jb-HelpText&view=edit&name=" + this.id);
            $('#image_box').load("ajax.php?module=user&view=large_picture&id=" + $(this).attr('profile'), function () {
              $('#dim_background').click(function () {
                  $('#dim_background').remove();
                  $('#image_box').remove();
              });
              $('#image_box').click(function () {
                  $('#dim_background').remove();
                  $('#image_box').remove();
              });
              $(document).keydown(function(e){
                  if (e.keyCode === 27) {
                      $('#dim_background').remove();
                      $('#image_box').remove();
                  }
              });
              $('#dim_background').click(function() {
                      $('#dim_background').remove();
                      $('#help_edit_box').remove();
              });
            });
        
        return false;
      });

      /*
      $('#query_results_table tr').each(function () {
          if ($(this).attr('id') !== 'query_result_page') {
              $(this).hide();
          }
      });
      $('#query_result_link').html('show');
      */
      $('#query_result_link').click(function () {
        if ($('#query_result_link').html() === 'show') {
          $('#query_result_link').html('hide');
          $('#query_results_table tr').each(function () {
              if ($(this).attr('id') !== 'query_result_page') {
                  $(this).show();
              }
          });
        } else {
          $('#query_result_link').html('show');
          $('#query_results_table tr').each(function () {
              if ($(this).attr('id') !== 'query_result_page') {
                  $(this).hide();
              }
          });
        }
      });
      
      
      
      $('#log_result_link').click(function () {
        if ($('#log_result_link').html() === 'show') {
          $('#log_result_link').html('hide');
          $('#log_results_table tr').each(function () {
              if ($(this).attr('id') !== 'log_result_page') {
                  $(this).show();
              }
          });
        } else {
          $('#log_result_link').html('show');
          $('#log_results_table tr').each(function () {
              if ($(this).attr('id') !== 'log_result_page') {
                  $(this).hide();
              }
          });
        }
      });
      
      
/*      var marker = new google.maps.Marker({
          address: 'Malmö, Sweden', 
          id: 'eventLocation',
          title: $('[name=title]').val(),
          draggable: true
      });
*/
    var map, locationMarker, oid;
    function setAddress(address, locationMarker, init) {
        var geocoder, latlng, lat, lng, latCheck, pos;
        geocoder = new google.maps.Geocoder();
        geocoder.geocode( { 'address': address}, function(results, status) {
          if (status === google.maps.GeocoderStatus.OK) {
              latlng = results[0].geometry.location;

              lat = 0;
              lng = 0;
              if (parseInt(init, 10) === 1) {
                latCheck = parseInt($('[name=latitude]').val(), 10);
                if ( latCheck > 0) {
                  lat = $('[name=latitude]').val();
                  lng = $('[name=longitude]').val();
                }
              }
              if (parseInt(lat, 10) === 0) {
                lat = latlng.lat(); //parseFloat(latlng[0]);
                lng = latlng.lng(); //parseFloat(latlng[1]);
              }
              $('[name=latitude]').val(lat);
              $('[name=longitude]').val(lng);
              //console.log(lat + ', ' + lng);
              pos = new google.maps.LatLng(lat, lng);
              
              map.setCenter(pos);

              locationMarker.setPosition(pos);
              
          //} else {
            //alert("Geocode was not successful for the following reason: " + status);
          }
        });
    }

    $('#in_address').keyup(function () {
        var address;
        address = $('#event_city_id :selected').text() + ' ' + $('#in_address').val();
        //console.log(address);
        setAddress(address,locationMarker, 0);
    });
		/*
    $('[name=location_name]').change(function () {
        address = $('#event_city_id :selected').text() + ' ' + $('#in_address').val();
        //console.log(address);
        setAddress(address,locationMarker, 0);
    });
		*/  
    $('#event_city_id').change(function () {
        var address;
        address = $('#event_city_id :selected').text() + ' ' + $('#in_address').val();
        setAddress(address, locationMarker, 0);
    });
    /*
    //Im not sure why this is here
    $('[name=title]').keyup(function () {
      var title = $('[name=title]').val();
      locationMarker.setTitle(title);
    });
    */
    function showMap(hidden) {
	    //console.log('* ' + $('#map_area').length);
      var geocoder, address, myOptions;
	    if ($('#map_area').length > 0 && !hidden) {
	      //console.log($('#map_area').length > 0);
	      geocoder = new google.maps.Geocoder();
	      address = $('#event_city_id :selected').text() + ' ' + $('#in_address').val();
	      locationMarker = new google.maps.Marker({
	            id: 'eventLocation',
	            title: $('[name=title]').val(),
	            draggable: true
	      });
	
	      myOptions = {
	        zoom: 12,
	        mapTypeId: google.maps.MapTypeId.ROADMAP 
	      };
	      map = new google.maps.Map(document.getElementById("map_area"), myOptions);
	      
	      locationMarker.setMap(map);
	      
	      google.maps.event.addListener(locationMarker, 'dragend', function () {
            var choord, lat, lng;
	          choord = locationMarker.getPosition(); 
	          lat = choord.lat();
	          lng = choord.lng();
	          $('[name=latitude]').val(lat);
	          $('[name=longitude]').val(lng);
	      });
	      setAddress(address, locationMarker, 1);
	    }
	  }
    showMap(true);
    $('.show_map').click(function () {
      showMap(false);
      $('[name=title]').attr('class', 'mandatory');
    });

		$('#contmenu.js a').click(function () {
			var me;
			me = $(this);
			$('.tab_box').hide();
			$('.buttonselected').attr('class', 'button');
			$('.buttonselectedexit').attr('class', 'buttonexit');
			$('[name=title]').attr('class', '');
			$('#' + $(this).attr('tab')).show(0, function () {
				if (me.attr('map') === 'show_map') {
					showMap(false);
					$('[name=title]').attr('class', 'mandatory');
				}
			});
			//console.log($(this).attr('class'));
			if ($(this).attr('class') === 'buttonexit') {
				$(this).attr('class', 'buttonselectedexit');
			} else {
				$(this).attr('class', 'buttonselected');
			}
			return false;
		});

      $('[name=location_id]').attr('name','old_location_id').css({'display': 'none'}).next().remove().next().remove();
      $('#guide_link').hide();
      $('[name=location_id_new]').attr('name','location_id');
      $('[name=location_name]').show();
      //console.log($('#event_sport_select').attr('cnt'));
      if ($('#event_sport_select').attr('cnt') > 0) {
          $('#event_sport').show();
      } else {
          $('#event_sport').hide();
      }
      //$('#event_sport').hide();
      $('body').append('<div id="search_list"></div>');
      $('body').append('<div id="search_list_tmp"></div>');
      $('#search_list').css({display: 'none', border: '2px solid #333333'});
      $('#search_list_tmp').css({display: 'none', border: '2px solid #333333'});

      $('[name=location_name]').keydown(function (e) {
      	var cid;
        cid = 0;
        //console.log(e.keyCode);
        if (parseInt(e.keyCode, 10) === 40) { // select with arrows
            if ($('#search_list div').hasClass('selected')) {
                $('#search_list div.selected')
                .removeClass('selected')
                .next().addClass('selected');
            } else {
                $('#search_list').find('div:first').addClass('selected');
            }
        } else if (parseInt(e.keyCode, 10) === 38) { // select with arrows
            if ($('#search_list div').hasClass('selected')) {
                $('#search_list div.selected')
                .removeClass('selected')
                .prev().addClass('selected');
            } else {
                $('#search_list').find('div:last').addClass('selected');
            }
        } else if (parseInt(e.keyCode, 10) === 13) { // select with arrows
            if ($('#search_list div').hasClass('selected')) {
                cid = $('#search_list div.selected').attr('cid');
                $('[name=location_id]').val($('#search_list div.selected').attr('cid'));
                $('[name=location_name]').val($('#search_list div.selected').html());
                $('#search_list div.selected')
                .removeClass('selected');
                $('#search_list').hide();
                $.get("ajax/event_sport.php?guide_id="+cid, function (data) {
                    $('#event_sport_div').html(data);
                    //console.log($('#event_sport_select').attr('cnt'));
                    if ($('#event_sport_select').attr('cnt') > 0) {
                        $('#event_sport').show();
                    } else {
                        $('#event_sport').hide();
                    }
                });
                $.get("ajax/event_guide_info.php?guide_id="+cid, function (data) {
                    var address;
                    $('#in_address').val($(data).find('address').html());
                    $('#in_homepage').val($(data).find('homepage').html());
                    $('#in_price').val($(data).find('price').html());

                    address = $('#event_city_id :selected').text() + ' ' + $('#in_address').val();
                    setAddress(address,locationMarker, 0);
                });  
                return false;
            }
        } else if (parseInt(e.keyCode, 10) === 9) { // select with arrows
            if ($('#search_list div').hasClass('selected')) {
                cid = $('#search_list div.selected').attr('cid');
                $('[name=location_id]').val(cid);
                $('[name=location_name]').val($('#search_list div.selected').html());
                $('#search_list div.selected')
                .removeClass('selected');
                $('#search_list').hide();
                $.get("ajax/event_sport.php?guide_id="+cid, function (data) {
                    $('#event_sport_div').html(data);
                    if ($('#event_sport_select').attr('cnt') > 0) {
                        $('#event_sport').show();
                    } else {
                        $('#event_sport').hide();
                    }
                });
                $.get("ajax/event_guide_info.php?guide_id="+cid, function (data) {
                  var address;
                  $('#in_address').val($(data).find('address').html());
                  $('#in_homepage').val($(data).find('homepage').html());
                  $('#in_price').val($(data).find('price').html());

                  address = $('#event_city_id :selected').text() + ' ' + $('#in_address').val();
                  setAddress(address,locationMarker, 0);
                });  
            }
        } else if (parseInt(e.keyCode, 10) === 27) {
            $('[name=location_id]').val('');
            $('[name=location_name]').val('');
            $('#search_list').hide();
        }
    });
    oid = 0;
    $('[name=location_name]').keyup(function(e){
        if ( (parseInt(e.keyCode, 10) !== 27) && (parseInt(e.keyCode, 10) !== 13) && (parseInt(e.keyCode, 10) !== 38) && (parseInt(e.keyCode, 10) !== 40) && (parseInt(e.keyCode, 10) !== 9) ) {
            $('#search_list')
            .css("top",($(this).offset().top+22)+"px")
            .css("left",$(this).offset().left+"px")
            .css({
                'background' : '#f7f7f7',
                'border' : '1px solid #333333',
                'position' : 'absolute',
                'padding' : '10px'
            });
            $('#search_list div').css({'display' : 'block'});
            if ($('#search_list').css('display') === 'none') {
                $('#search_list').html('');
                $('#search_list').show();
            }
            oid = oid + 1;
            /*
            $('#search_list')
            .load(
            */

            $.get(
            'ajax/event_guide_list.php?location_name='+escape($('[name=location_name]').val())+'&city_id='+$('[name=city_id]').attr('value') + '&oid=' + oid,
            function(data) {
                $('#search_list_tmp').html(data);
                //console.log(oid + ' != ' + parseInt($('#search_list_tmp #oid').val(), 10));
                if (oid === parseInt($('#search_list_tmp #oid').val(), 10)) {
                  //console.log('in: ' + parseInt($('#oid').val(), 10));
                  $('#search_list').html(data);
                  $('[hover]').hover(function () {
                    //console.log($(this).attr('hover'));
                    if ($(this).attr('hover') !== '') {
                      $('<div id="popup_box">' + $(this).attr('hover') + '</div>').appendTo('body');
                      $('#popup_box')
                      .css("top",($(this).offset().top+22)+"px")
                      .css("left",$(this).offset().left+"px")
                      .css({
                      'background' : '#eeeeee',
                      'border' : '2px solid #333333',
                      'position' : 'absolute',
                      'padding' : '10px'
                    
                      });
                    }
                  }, function () {
                    $('#popup_box').remove();
                    $('#popup_box').remove();
                  });
                  $('#search_list div').css('padding', '2px');
                  $('#search_list div').hover(function () {
                    $(this).css('background', '#333333');
                    $(this).css('color', '#ffffff');
                  }, function () {
                    $(this).css('background', '');
                    $(this).css('color', '');
                  });
                  $('#search_list div').css({'display' : 'block'});
                  $('#search_list div').click(function () {
                      //console.log($(this).attr('cid'));
                      var cid;
                      $('[name=location_id]').val($(this).attr('cid'));
                      $('[name=location_name]').val($(this).html());
                      $('#search_list').hide();
                      cid = $(this).attr('cid');
                      /*
                      $.get("ajax/event_sport.php?guide_id="+$(this).attr('cid'),function(data){
                          $('#event_sport_div').html(data);
                      });
                      */
                      $.get("ajax/event_sport.php?guide_id="+cid, function (data) {
                          $('#event_sport_div').html(data);
                          if ($('#event_sport_select').attr('cnt') > 0) {
                              $('#event_sport').show();
                          } else {
                              $('#event_sport').hide();
                          }
                      });
                      $.get("ajax/event_guide_info.php?guide_id="+$(this).attr('cid'),function (data) {
                          var address;
                          $('#in_address').val($(data).find('address').html());
                          $('#in_homepage').val($(data).find('homepage').html());
                          $('#in_price').val($(data).find('price').html());
  
                          address = $('#event_city_id :selected').text() + ' ' + $('#in_address').val();
                          setAddress(address,locationMarker, 0);
                      });
                      return false;
                  });
                }
            });
        }
        if (parseInt(e.keyCode, 10) === 8 && $('[name=location_name]').val() === '') {
            $('[name=location_id]').val('');
            $('[name=location_name]').val('');
            $('#product_name').html('');
            $('#search_list').hide();
        }
    });
    
    $('.follow_btn').click(function () {
      var followBtn;
      followBtn = $(this); //
      $.get('ajax/follow.php?user_id=' + $(this).attr('user_id') + 
                            '&item_id=' + $(this).attr('item_id') +
                            '&type_id=' + $(this).attr('type_id') +
                            '&ignore=' + $(this).attr('ignore'),
        function () {
          // Change image, ignore status,
          var btn, ignore;
          btn = '[key=follow_btn_' + followBtn.attr('item_id') + ']';
          ignore = parseInt($(btn).attr('ignore'), 10);
          if (ignore === 0) {
            $(btn).attr('ignore', 1);
            $(btn).html('<div class="sprite-follow" title="' + followBtn.attr('txt_function () {') + '"></div>');
          } else {
            $(btn).attr('ignore', 0);
            $(btn).html('<div class="sprite-unfollow" title="' + followBtn.attr('txt_follow') + '"></div>');
          }
          return false;
        });
      return false;
    });
    
    $('.img_warning').hover(function () {
        $(this).attr('class', 'sprite-btn_warning_hover');
      }, function () {
        if ($(this).attr('active') !== 'active') {
          $(this).attr('class', 'sprite-btn_warning');
        }
    });
    
    $('.img_warning').each(function () {
      if ($(this).attr('active') === 'active') {
          $(this).attr('class', 'sprite-btn_warning_hover');
      }
    });
    
    $('.warning_btn').click(function () {
    				var img;
            img = $(this + ' img');
            $('<div id="dim_background" style="display: none;"></div>').appendTo('body');
            $('#dim_background')
            .css("height", $(document).height())
            .show()
            .css({
                'position' : 'fixed',
                'top' : '0px',
                'left' : '0px',
                'border' : '2px solid #333333',
                'background' : '#000000',
                'opacity' : '0.4',
                'width' : '100%',
                'z-index' : '100'
            });
            //console.log("window");
            $(window).bind("resize", function () {  
              $("#dim_background").css("height", $(window).height());  
            }); 
            //console.log("window done");
            $('<div id="warn_edit_box" style="display: none;"></div>').appendTo('body');
            $('#warn_edit_box')
            .show()
            .css({'position' : 'fixed',
                'border' : '2px solid #993333',
                'height' : '300px',
                'width'  : '350px',
                'background' : '#ffffff',
                'z-index' : '200',
                'top' : '50%',
                'left' : '50%',
                'margin-top' : '-150px',
                'margin-left' : '-180px',
                'padding' : '10px',
                'overflow' : 'hidden'
              });
              //console.log("ajax.php?module=Jb-HelpText&view=edit&name=" + this.id);
            $('#warn_edit_box').load("ajax.php?module=warning&view=warn&user_id=" + $(this).attr('user_id') + "&item_id=" + $(this).attr('item_id') + "&type_id=" + $(this).attr('type_id'), function () {
              $('[name=motivation_text]').keyup(function(e){
                //alert('keydown');
                var motivering, chars;
                motivering = $('[name=motivation_text]').val();
                chars = motivering.length
                
                if (chars > 0) {
                  $('#warn_submit').removeAttr('disabled');
                } else {
                  $('#warn_submit').attr('disabled', 'disabled');
                }
                
              });
              //$('#warn_submit').
              $('#warn_submit').click(function () {
                $.get("ajax.php?module=warning&view=save&user_id=" + $('[name=user_id]').val() + 
                                            "&item_id=" + $('[name=item_id]').val() + 
                                            "&type_id=" + $('[name=type_id]').val() +
                                            "&notifier_id=" + $('[name=notifier_id]').val() +
                                            "&selection=" + $('[name=selection]:checked').val() +
                                            "&motivation_text=" + $('[name=motivation_text]').val()
                                            );
                //img.attr('active', 'active');
                //img.attr('src', 'graphics/btn_warning_hover.jpg');
                $('#dim_background').remove();
                $('#warn_edit_box').remove();
              });
              $('#warn_cancel').click(function () {
                  $('#dim_background').remove();
                  $('#warn_edit_box').remove();
              });
              $(document).keydown(function (e) {
                  if (e.keyCode === 27) {
                      $('#dim_background').remove();
                      $('#warn_edit_box').remove();
                  }
              });
              $('#dim_background').click(function() {
                      $('#dim_background').remove();
                      $('#help_edit_box').remove();
              });
            });
      
      return false;
    });

		var goodBadClick, orgImg;
    goodBadClick = false;
    orgImg = '';
    /*
    $('.good_btn, .good_btn_me').hover(function() {
    	$("#tiptip_content").html($('#hover_good_' + $(this).attr('item_id') + '_' + $(this).attr('type_id')).html());
    });
		$('.good_btn, .good_btn_me').tipTip({'content': false });
    */
    $('.good_btn, .good_btn_me').tooltip({
        bodyHandler: function () { 
		        //orgImg = $(this).find('.img_bad').attr('class');
		        orgImg = this;
		        $(this).find('.img_good').attr('class', 'img_good sprite-btn_good_hover');
            return $('#hover_good_' + $(this).attr('item_id') + '_' + $(this).attr('type_id')).html(); 
        }, 
        showURL: false,
        fade: 500,
        opacity: 1.00
    });
    $('.xgood_btn, .xgood_btn_me').hover(function () {
        //orgImg = $(this).find('.img_good').attr('src');
        //$(this).find('.img_good').attr('src', 'graphics/btn_good_hover.jpg');
        $('#hover_good_' + $(this).attr('item_id') + '_' + $(this).attr('type_id'))
        .css({'position':'absolute', 'z-index':'200',
              'top': ($(this).offset().top + 29) + 'px',
              'left': ($(this).offset().left) + 'px'
            }).show();
      }, function () {
        //$(this).find('.img_good').attr('src', orgImg);
        $('#hover_good_' + $(this).attr('item_id') + '_' + $(this).attr('type_id'))
            .hide();
    });
    var goodAddMe, goodRemoveMe, badAddMe, badRemoveMe;
    goodAddMe = function (obj) {
      //if (!goodBadClick) {
      	var notifierId, orgImg, itemId, typeId, listPicture, username;
        notifierId = obj.attr('notifier_id');
        orgImg = obj.find('.img_good').attr('src');
        itemId = obj.attr('item_id');
        typeId = obj.attr('type_id');
        listPicture = obj.attr('pic');
        username = obj.attr('notifier');
        //goodBadClick = true;
        $.get("ajax.php?module=warning&view=good_bad_save&user_id=" + obj.attr('user_id') + 
                                    "&item_id=" + obj.attr('item_id') + 
                                    "&type_id=" + obj.attr('type_id') +
                                    "&notifier_id=" + obj.attr('notifier_id') +
                                    "&card=1" + 
                                    "&status=1"
                                    , function(goodBad){
                                    	var value, remove;
                                      if (!($('#hover_good_' + itemId + '_' + typeId + ' #good_bad_like_table #good_bad_list_' + notifierId).attr('id'))) {
                                        value = parseInt($('#good_' + obj.attr('item_id') + '_' + obj.attr('type_id')).html(), 10) + 1;
                                        $('#good_' + itemId + '_' + typeId).html(value);
                                        if ($('#hover_bad_' + itemId + '_' + typeId + ' #good_bad_unlike_table #good_bad_list_' + notifierId).attr('id')) {
                                          //console.log('remove from bad');
                                          remove = parseInt($('#bad_' + obj.attr('item_id') + '_' + obj.attr('type_id')).html(), 10) - 1;
                                          $('#bad_' + itemId + '_' + typeId).html(remove);
                                        }
                                        $('#hover_good_' + itemId + '_' + typeId + ' #good_bad_like_table #good_bad_list_' + notifierId).remove();
                                        $('#hover_bad_' + itemId + '_' + typeId + ' #good_bad_unlike_table #good_bad_list_' + notifierId).remove();
                                        //$('#myTable tr:last').after('<tr>...</tr><tr>...</tr>');
                                        $('#hover_good_' + itemId + '_' + typeId + ' #good_bad_like_table > tbody:last').append('<tr id="good_bad_list_' + notifierId + '"><td style="width: 20px;">' + listPicture + '</td><td>' + username+ '</td></tr>');
                                        $('#good_link_' + itemId + '_' + typeId).attr('class', 'good_btn_me');
                                        $('#bad_link_' + itemId + '_' + typeId).attr('class', 'bad_btn');
                                        $('#good_link_' + itemId + '_' + typeId).unbind().bind('click', function () { goodRemoveMe($('#good_link_' + itemId + '_' + typeId)); return false; });
                                        $('#bad_link_' + itemId + '_' + typeId).unbind().bind('click', function () { badAddMe($('#bad_link_' + itemId + '_' + typeId)); return false; });
                                        //$('#good_link_' + itemId + '_' + typeId + ' .good_img').attr('src', 'graphics/btn_good_hover.jpg');
                                        //$('#bad_link_' + itemId + '_' + typeId + ' .bad_img').attr('src', 'graphics/btn_bad.jpg');
                                        $('#good_link_' + itemId + '_' + typeId + ' .good_img').attr('class', 'good_img sprite-btn_good_hover');
                                        $('#bad_link_' + itemId + '_' + typeId + ' .bad_img').attr('class', 'bad_img sprite-btn_bad');
                                        
                                        $('#good_link_' + itemId + '_' + typeId).tooltip({
																		        bodyHandler: function () { 
																				        //orgImg = $(this).find('.img_bad').attr('class');
																				        orgImg = this;
																				        $(this).find('.img_good').attr('class', 'img_good sprite-btn_good_hover');
																		            return $('#hover_good_' + $(this).attr('item_id') + '_' + $(this).attr('type_id')).html(); 
																		        }, 
																		        showURL: false,
																		        fade: 500,
																		        opacity: 1.00
																		    });
                                        $('#xgood_link_' + itemId + '_' + typeId).hover(function () {
																			    	$("#tiptip_content").html($('#hover_good_' + $(this).attr('item_id') + '_' + $(this).attr('type_id')).html());
																						$('.good_btn, .good_btn_me').tipTip({'content': false });
                                            //orgImg = $(this).find('.img_good').attr('src');
                                            //$(this).find('.img_good').attr('src', 'graphics/btn_good_hover.jpg');
                                            /*
                                            $('#hover_good_' + $(this).attr('item_id') + '_' + $(this).attr('type_id'))
                                            .css({'position':'absolute', 'z-index':'200',
                                                  'top': ($(this).offset().top+19)+'px',
                                                  'left': ($(this).offset().left)+'px'
                                                }).show();
																						*/
                                          }, function () {
                                            //$(this).find('.img_good').attr('src', orgImg);
                                            $('#hover_good_' + $(this).attr('item_id') + '_' + $(this).attr('type_id'))
                                                .hide();
                                        });
                                        $('#bad_link_' + itemId + '_' + typeId).tooltip({
																			        bodyHandler: function () { 
																					        //orgImg = $(this).find('.img_bad').attr('class');
																					        orgImg = this;
																					        $(this).find('.img_bad').attr('class', 'img_bad sprite-btn_bad_hover');
																			            return $('#hover_bad_' + $(this).attr('item_id') + '_' + $(this).attr('type_id')).html(); 
																			        }, 
																			        showURL: false,
																			        fade: 500,
																			        opacity: 1.00
																			    });
																			    $('#xbad_link_' + itemId + '_' + typeId).hover(function () {
																			    	$("#tiptip_content").html($('#hover_bad_' + $(this).attr('item_id') + '_' + $(this).attr('type_id')).html());
																						$('.bad_btn, .bad_btn_me').tipTip({'content': false });
                                            //orgImg = $(this).find('.img_bad').attr('src');
                                            //$(this).find('.img_bad').attr('src', 'graphics/btn_bad_hover.jpg');
                                            /*
                                            $('#hover_bad_' + $(this).attr('item_id') + '_' + $(this).attr('type_id'))
                                            .css({'position':'absolute', 'z-index':'200',
                                                  'top': ($(this).offset().top+19)+'px',
                                                  'left': ($(this).offset().left)+'px'
                                                }).show();
                                            */
                                          }, function () {
                                            //$(this).find('.img_bad').attr('src', orgImg);
                                            $('#hover_bad_' + $(this).attr('item_id') + '_' + $(this).attr('type_id'))
                                                .hide();
                                        });
                                      }
                                      return false;                                    
                                    });
      //}
      return false;
    };
    goodRemoveMe = function (obj) {
      //if (!goodBadClick) {
      	var notifierId, itemId, typeId, orgImg;
        notifierId = obj.attr('notifier_id');
        itemId = obj.attr('item_id');
        typeId = obj.attr('type_id');
        orgImg = obj.find('.img_good').attr('src');
        //goodBadClick = true;
        $.get("ajax.php?module=warning&view=good_bad_save&user_id=" + obj.attr('user_id') + 
                                    "&item_id=" + obj.attr('item_id') + 
                                    "&type_id=" + obj.attr('type_id') +
                                    "&notifier_id=" + obj.attr('notifier_id') +
                                    "&card=1" + 
                                    "&status=0"
                                    , function (goodBad) {
                                    	var value;
                                      value = parseInt($('#good_' + itemId + '_' + typeId).html(), 10) - 1;
                                      $('#good_' + itemId + '_' + typeId).html(value);
                                      $('#hover_good_' + itemId + '_' + typeId + ' #good_bad_like_table #good_bad_list_' + notifierId).remove();
                                      $('#good_link_' + itemId + '_' + typeId + ' .good_btn_me').attr('class', 'good_btn');
                                      $('#good_link_' + itemId + '_' + typeId + ' .bad_btn_me').attr('class', 'bad_btn');
                                      $('#good_link_' + itemId + '_' + typeId).unbind().bind('click', function () { goodAddMe($('#good_link_' + itemId + '_' + typeId)); return false; });
                                      //$('#good_link_' + itemId + '_' + typeId + ' .good_img').attr('src', 'graphics/btn_good.jpg');
                                      $('#good_link_' + itemId + '_' + typeId + ' .good_img').attr('class', 'good_img sprite-btn_good');
                                        $('#good_link_' + itemId + '_' + typeId).tooltip({
																		        bodyHandler: function () { 
																				        //orgImg = $(this).find('.img_bad').attr('class');
																				        orgImg = this;
																				        $(this).find('.img_good').attr('class', 'img_good sprite-btn_good_hover');
																		            return $('#hover_good_' + $(this).attr('item_id') + '_' + $(this).attr('type_id')).html(); 
																		        }, 
																		        showURL: false,
																		        fade: 500,
																		        opacity: 1.00
																		    });
                                        $('#xgood_link_' + itemId + '_' + typeId).hover(function () {
																			    	$("#tiptip_content").html($('#hover_good_' + $(this).attr('item_id') + '_' + $(this).attr('type_id')).html());
																						$('.good_btn, .good_btn_me').tipTip({'content': false });
                                            //orgImg = $(this).find('.img_good').attr('src');
                                            //$(this).find('.img_good').attr('src', 'graphics/btn_good_hover.jpg');
																						/*
                                            $('#hover_good_' + $(this).attr('item_id') + '_' + $(this).attr('type_id'))
                                            .css({'position':'absolute', 'z-index':'200',
                                                  'top': ($(this).offset().top+19)+'px',
                                                  'left': ($(this).offset().left)+'px'
                                                }).show();
																						*/
                                          }, function () {
                                            //$(this).find('.img_good').attr('src', orgImg);
                                            $('#hover_good_' + $(this).attr('item_id') + '_' + $(this).attr('type_id'))
                                                .hide();
                                        });
                                      
                                      return false;
                                    });
      //}
      return false;
    };
    $('.good_btn_me').click(function () {
      goodRemoveMe($(this));
      return false;
    });
    $('.good_btn').click(function () {
      goodAddMe($(this));
      return false;
    });
            
    $('.bad_btn, .bad_btn_me').tooltip({
        bodyHandler: function () { 
		        //orgImg = $(this).find('.img_bad').attr('class');
		        orgImg = this;
		        $(this).find('.img_bad').attr('class', 'img_bad sprite-btn_bad_hover');
            return $('#hover_bad_' + $(this).attr('item_id') + '_' + $(this).attr('type_id')).html(); 
        }, 
        showURL: false,
        fade: 500,
        opacity: 1.00
    });
    
    /*
    $('.bad_btn, .bad_btn_me').hover(function() {
    	$("#tiptip_content").html($('#hover_bad_' + $(this).attr('item_id') + '_' + $(this).attr('type_id')).html());
    });
		$('.bad_btn, .bad_btn_me').tipTip({'content': false });
		*/
    $('.xbad_btn, .xbad_btn_me').hover(function () {
        orgImg = $(this).find('.img_bad').attr('class');
        orgImg = this; //$(this); //.find('.img_bad').attr('class');
        //$(this).find('.img_bad').attr('src', 'graphics/btn_bad_hover.jpg');
        $(this).find('.img_bad').attr('class', 'img_bad sprite-btn_bad_hover');
        $('#hover_bad_' + $(this).attr('item_id') + '_' + $(this).attr('type_id'))
        .css({'position':'absolute', 
        			'z-index':'200',
              'top': ($(this).offset().top + 29) + 'px',
              'left': ($(this).offset().left) + 'px'
            }).show();
        //console.log(orgImg);
      }, function () {
      	//console.log(orgImg);
        $(this).find('.img_bad').attr('class', orgImg);
        //$(this).find('.img_bad').attr('class', 'img_bad sprite-btn_bad_hover');
        $('#hover_bad_' + $(this).attr('item_id') + '_' + $(this).attr('type_id'))
            .hide();
    });
    badRemoveMe = function (obj) {
      //if (!goodBadClick) {
      	var notifierId, orgImg, itemId, typeId;
        notifierId = obj.attr('notifier_id');
        orgImg = obj.find('.img_bad').attr('src');
        itemId = obj.attr('item_id');
        typeId = obj.attr('type_id');
        //goodBadClick = true;
        $.get("ajax.php?module=warning&view=good_bad_save&user_id=" + obj.attr('user_id') + 
                                    "&item_id=" + obj.attr('item_id') + 
                                    "&type_id=" + obj.attr('type_id') +
                                    "&notifier_id=" + obj.attr('notifier_id') +
                                    "&card=2" + 
                                    "&status=0"
                                    , function (goodBad) {
                                    	var value;
                                      value = parseInt($('#bad_' + obj.attr('item_id') + '_' + obj.attr('type_id')).html(), 10) - 1;
                                      $('#bad_' + itemId + '_' + typeId).html(value);
                                      $('#hover_bad_' + itemId + '_' + typeId + ' #good_bad_unlike_table #good_bad_list_' + notifierId).remove();
                                      $('#bad_link_' + itemId + '_' + typeId).attr('class', 'bad_btn');
                                      $('#bad_link_' + itemId + '_' + typeId).unbind().bind('click', function () { badAddMe($('#bad_link_' + itemId + '_' + typeId)); return false; });
                                      //$('#bad_link_' + itemId + '_' + typeId + ' .bad_img').attr('src', 'graphics/btn_bad.jpg');
                                      $('#bad_link_' + itemId + '_' + typeId + ' .bad_img').attr('class', 'bad_img sprite-btn_bad');
																	    $('#bad_link_' + itemId + '_' + typeId).tooltip({
																	        bodyHandler: function () { 
																			        //orgImg = $(this).find('.img_bad').attr('class');
																			        orgImg = this;
																			        $(this).find('.img_bad').attr('class', 'img_bad sprite-btn_bad_hover');
																	            return $('#hover_bad_' + $(this).attr('item_id') + '_' + $(this).attr('type_id')).html(); 
																	        }, 
																	        showURL: false,
																	        fade: 500,
																	        opacity: 1.00
																	    });
																			$('#xbad_link_' + itemId + '_' + typeId).hover(function () {
																		    	//$("#tiptip_content").html($('#hover_bad_' + $(this).attr('item_id') + '_' + $(this).attr('type_id')).html());
																					//$('.bad_btn, .bad_btn_me').tipTip({'content': false });
																	        //orgImg = $(this).find('.img_bad').attr('src');
																	        //$(this).find('.img_bad').attr('src', 'graphics/btn_bad_hover.jpg');
																					
																	        $('#hover_bad_' + $(this).attr('item_id') + '_' + $(this).attr('type_id'))
																	        .css({'position':'absolute', 'z-index':'200',
																	              'top': ($(this).offset().top + 29) + 'px',
																	              'left': ($(this).offset().left) + 'px'
																	            }).show();
																					
																	    }, function () {
																	        //$(this).find('.img_bad').attr('src', orgImg);
																	        $('#hover_bad_' + $(this).attr('item_id') + '_' + $(this).attr('type_id'))
																	            .hide();
																	    });
                                      return false;
                                    });
      //}
      return false;
    };
    $('.bad_btn_me').click(function () {
      badRemoveMe($(this));
      return false;
    });
    badAddMe = function (obj) {
      //if (!goodBadClick) {
      	var notifierId, orgImg, itemId, typeId, listPicture, username;
        notifierId = obj.attr('notifier_id');
        orgImg = obj.find('.img_bad').attr('src');
        itemId = obj.attr('item_id');
        typeId = obj.attr('type_id');
        listPicture = obj.attr('pic');
        username = obj.attr('notifier');
        //goodBadClick = true;
        $.get("ajax.php?module=warning&view=good_bad_save&user_id=" + obj.attr('user_id') + 
                                    "&item_id=" + obj.attr('item_id') + 
                                    "&type_id=" + obj.attr('type_id') +
                                    "&notifier_id=" + obj.attr('notifier_id') +
                                    "&card=2" + 
                                    "&status=1"
                                    , function (goodBad) {
                                    	var value, remove;
                                      if (!($('#hover_bad_' + itemId + '_' + typeId + ' #good_bad_unlike_table #good_bad_list_' + notifierId).attr('id'))) {
                                        value = parseInt($('#bad_' + obj.attr('item_id') + '_' + obj.attr('type_id')).html(), 10) + 1;
                                        $('#bad_' + itemId + '_' + typeId).html(value);
                                        if ($('#hover_good_' + itemId + '_' + typeId + ' #good_bad_like_table #good_bad_list_' + notifierId).attr('id')) {
                                          //console.log('remove from good');
                                          remove = parseInt($('#good_' + obj.attr('item_id') + '_' + obj.attr('type_id')).html(), 10) - 1;
                                          $('#good_' + itemId + '_' + typeId).html(remove);
                                        }
                                        $('#hover_good_' + itemId + '_' + typeId + ' #good_bad_like_table #good_bad_list_' + notifierId).remove();
                                        $('#hover_bad_' + itemId + '_' + typeId + ' #good_bad_unlike_table #good_bad_list_' + notifierId).remove();
                                        $('#hover_bad_' + itemId + '_' + typeId + ' #good_bad_unlike_table > tbody:last').append('<tr id="good_bad_list_' + notifierId + '"><td style="width: 20px;">' + listPicture + '</td><td>' + username + '</td></tr>');
                                        $('#bad_link_' + itemId + '_' + typeId + ' .bad_btn').attr('class', 'bad_btn_me');
                                        $('#good_link_' + itemId + '_' + typeId + ' .good_btn_me').attr('class', 'good_btn');
                                        $('#bad_link_' + itemId + '_' + typeId).unbind().bind('click', function () { badRemoveMe($('#bad_link_' + itemId + '_' + typeId)); return false; });
                                        $('#good_link_' + itemId + '_' + typeId).unbind().bind('click', function () { goodAddMe($('#good_link_' + itemId + '_' + typeId)); return false; });
                                        //$('#good_link_' + itemId + '_' + typeId + ' .good_img').attr('src', 'graphics/btn_good.jpg');
                                        //$('#bad_link_' + itemId + '_' + typeId + ' .bad_img').attr('src', 'graphics/btn_bad_hover.jpg');
                                        $('#good_link_' + itemId + '_' + typeId + ' .good_img').attr('class', 'good_img sprite-btn_good');
                                        $('#bad_link_' + itemId + '_' + typeId + ' .bad_img').attr('class', 'bad_img sprite-btn_bad_hover');
                                      
                                        $('#bad_link_' + itemId + '_' + typeId).tooltip({
																		        bodyHandler: function () { 
																				        //orgImg = $(this).find('.img_bad').attr('class');
																				        orgImg = this;
																				        $(this).find('.img_bad').attr('class', 'img_bad sprite-btn_bad_hover');
																		            return $('#hover_bad_' + $(this).attr('item_id') + '_' + $(this).attr('type_id')).html(); 
																		        }, 
																		        showURL: false,
																		        fade: 500,
																		        opacity: 1.00
																		    });
																		    $('#xbad_link_' + itemId + '_' + typeId).hover(function () {
																			    	//$("#tiptip_content").html($('#hover_bad_' + $(this).attr('item_id') + '_' + $(this).attr('type_id')).html());
																						//$('.bad_btn, .bad_btn_me').tipTip({'content': false });
																						
                                            orgImg = $(this).find('.img_bad').attr('src');
                                            //$(this).find('.img_bad').attr('src', 'graphics/btn_bad_hover.jpg');
                                            $(this).find('.img_bad').attr('class', 'img_bad sprite-btn_bad_hover');
                                            $('#hover_bad_' + $(this).attr('item_id') + '_' + $(this).attr('type_id'))
                                            .css({'position':'absolute', 'z-index':'200',
                                                  'top': ($(this).offset().top + 29) + 'px',
                                                  'left': ($(this).offset().left)+'px'
                                                }).show();
																						
                                          }, function () {
                                            $(this).find('.img_bad').attr('src', orgImg);
                                            $('#hover_bad_' + $(this).attr('item_id') + '_' + $(this).attr('type_id'))
                                                .hide();
                                        });
                                        $('#good_link_' + itemId + '_' + typeId).tooltip({
																		        bodyHandler: function () { 
																				        //orgImg = $(this).find('.img_bad').attr('class');
																				        orgImg = this;
																				        $(this).find('.img_good').attr('class', 'img_good sprite-btn_good_hover');
																		            return $('#hover_good_' + $(this).attr('item_id') + '_' + $(this).attr('type_id')).html(); 
																		        }, 
																		        showURL: false,
																		        fade: 500,
																		        opacity: 1.00
																		    });
																		    $('#xgood_link_' + itemId + '_' + typeId).hover(function () {
																			    	//$("#tiptip_content").html($('#hover_good_' + $(this).attr('item_id') + '_' + $(this).attr('type_id')).html());
																						//$('.good_btn, .good_btn_me').tipTip({'content': false });
																						
                                            orgImg = $(this).find('.img_good').attr('src');
                                            $(this).find('.img_good').attr('src', 'graphics/btn_good_hover');
                                            $('#hover_good_' + $(this).attr('item_id') + '_' + $(this).attr('type_id'))
                                            .css({'position':'absolute', 'z-index':'200',
                                                  'top': ($(this).offset().top + 29) + 'px',
                                                  'left': ($(this).offset().left)+'px'
                                                }).show();
                                            
                                          }, function () {
                                            $(this).find('.img_good').attr('src', orgImg);
                                            $('#hover_good_' + $(this).attr('item_id') + '_' + $(this).attr('type_id'))
                                                .hide();
                                        });
                                      }
                                      
                                      return false;
                                    });
      //}
      return false;
    };
    $('.bad_btn').click(function () {
      badAddMe($(this));
      return false;
    });
  });

    $(document).ready(function () {
        $('#random_image').updateRandomImage(600000, true);
    });

    $.fn.updateRandomImage = function (interval, first) {
    	var updating, init;
        interval = interval || 1000;
        updating = false;
        init = true;
        //alert($('#random_image').html());
        if ($('#rand_img_front').html() === '') {
          //alert('A empty front');
          //$('#random_image').append('<div id="rand_img_front" style="display: none; position: relative; top: 0; left: 0; overflow: auto; float: left;"></div>');
          $('#rand_img_front').load('ajax/random_image.php');
        }
        if ($('#rand_img_back').html() === '') {
          //alert('A empty back');
          //$('#random_image').append('<div id="rand_img_back" style="position: relative; top: 0; left: 0; overflow: auto; float: left; display: none;"></div>');
          //$('#rand_img_back').fadeOut();
          $('#rand_img_back').load('ajax/random_image.php');
        }
        //return this.each(function () {
            changeImage = function () {
              //console.log('checkForUpdates() ' + updating);
              if (updating === false) {
                updating = true;

                //alert('Change');
                
                $('#rand_img_front').fadeOut(1000, function () {
                  $('#rand_img_back').fadeOut(0, function () {
                    //alert('remove');
                    $('#rand_img_front').remove();
                    //$('#rand_img_front').attr('id', 'rand_img_tmp');
                    //alert('in');
                    $('#rand_img_back').fadeIn(1000, function () {
                      //alert('Load')
                      $('#rand_img_back').attr('id', 'rand_img_front');
                      //$('#rand_img_tmp').attr('id', 'rand_img_back');
                      $('#random_image').append('<div id="rand_img_back" style="position: relative; top: 0; left: 0; overflow: auto; float: left; margin-bottom: 50px;"></div>');
                      //$('#rand_img_back').fadeOut();
                      $('#rand_img_back').load('ajax/random_image.php', function () {
                        $('[tooltip]').tooltip({ 
                            bodyHandler: function () { 
                                return $(this).attr('tooltip'); 
                            }, 
                            showURL: false,
                            fade: 500,
                            opacity: 1.00
                        });
                      });
                    });
                  });
                });

                updating = false;
              }
             setTimeout(changeImage, interval);
            }
            setTimeout(changeImage, interval);
            //changeImage();
        //});
    };


    $(document).ready(function () {
        $('.front_flash_tab, .front_flash_tab_active').click(function () {
          $('.front_flash_tab_active').addClass('front_flash_tab');
          $(this).attr('class', 'front_flash_tab_active');
          $('.front_flash_box').hide();
          $('#front_flash_box_' + $(this).attr('id')).show();
          return false;
        });
    });


    $(document).ready(function () {
        $('#random_image').updateRandomImage(12000, 1);
    });

    $.fn.updateRandomImage = function (interval, cnt) {
      interval = interval || 1000;
      function changeImage() {
        $('#front-image-' + cnt).fadeOut(1000, function () {
          $('.front-image').hide();
          cnt = cnt + 1;
          //alert('#1: ' + cnt);
          if (parseInt(cnt, 10) === 6) {
            cnt = 1;
          }
          $('#front-image-' + cnt).fadeIn(1000, function () {
            //alert(cnt);
          });
        });
        setTimeout(changeImage, interval);
      }
      setTimeout(changeImage, interval);
    };


    $(document).ready(function () {
    	var focusPollAlternative, blurPollAlternative;
        // Menyhantering
        $('.comment_menu_active, .comment_menu').click(function () {
          //alert('klick ' + $(this).attr('id'));
          $('.comment_menu_active').attr('class', 'comment_menu');
          $(this).attr('class', 'comment_menu_active');
          $('.comment_form_active').attr('class', 'comment_form');
          $('#comment_form_' + $(this).attr('id')).attr('class', 'comment_form_active');
        });
        
        focusPollAlternative = function () {
        	//console.log('func');
        	var cnt;
          cnt = $(this).attr('id') + 1;
          $(this).parent().attr('class', 'poll_alternative');
          $(this).unbind('focus', focusPollAlternative);
          $(this).bind('blur', blurPollAlternative);
          //$('<div class="poll_alternative_last"><input type="text" class="textfield" id="' + cnt + '"></div>').appendTo(this);
          $(this).parent().after('<div class="poll_alternative_last"><input type="text" class="textfield" name="arr_poll_alternative[]" id="' + cnt + '"></div>');
          //elem.focus(focusPollAlternative(elem));
          $('.poll_alternative_last .textfield').bind('focus', focusPollAlternative);
        };

        blurPollAlternative = function () {
        	//console.log('blur: ' + $(this).val());
          if ($(this).val() === '') {
          	//console.log('remove ' + $(this));
            $(this).parent().remove();
          }
        };

        // Vad skall hända när man sätter markören i det sista textfältet?
        $('.poll_alternative_last .textfield').bind('focus', focusPollAlternative);

        //$('.poll_alternative_last .textfield').focus(focusPollAlternative());

				$('.questionsPollClickTarget').click(function (){
					//alert('you clicked on ' + $(this).attr('id'));
					$.get("ajax/poll_vote.php?alt=" + $(this).attr('id'),
										function (validation) {
											var pollId;
											if (validation) {
												//alert('Tack för din röst');
												window.location.reload();
												pollId = $(this).attr('poll_id');
												$('.questionsPollClickTarget').each(function () {
													if ($(this).attr('poll_id') === pollId) {
														$(this).remove();
													}
												});
												
											} else {
												alert('Du har redan röstat');
											}
					});
				});
				
				//$('#chatborder').css({
					//'padding-top' : '-23px'
				//});

				$('#chatborder').hover(function () {
					$(this).stop().animate({height:'23px'}, 500);
				}, function () {
					$(this).stop().animate({height:'3px'}, 500);
				});

				function expandButton (me) {
					var id;
					id = $(me).attr('id');
					$('.expand_button .acc_icon').html('+&nbsp;');
					$('.expansion_box').slideUp(500);
					$('#' + id + '_box').stop().slideDown(500);
					$('#' + id + ' .acc_icon').html('-&nbsp;');
				}
				$('.expand_button').click(function () {
					expandButton(this);
				});
				
				//$('#list_new_frame').append('<div style="border: 1px solid #999999; ">test</div>');
		    $('#event_cancel_button').click(function() {
		    	if (!confirm('Är du säker på att du vill avboka dig?')) {
		    		return false;
		    	}
		    });

		    $('.verify_reg_delete').click(function() {
		    	if (!confirm('Är du säker på att du vill ta bort medlemmen från listan?')) {
		    		return false;
		    	}
		    });
    
    		$('.reg_member').hover(function() {
    			$(this).children('.reg_panel').show();
    			$(this).css({
    				'background' : '#fdefdd',
    				'border' : '1px solid #fb7f00'
    			});
    		},
    		function() {
    			$(this).children('.reg_panel').hide();
    			$(this).css({
    				'background' : '#ffffff',
    				'border' : '0px solid #fb7f00'
    			});
    		});
  	});
})(jQuery);

