
var serverUrl = '';


function switchAdmin(changeDiv) {

        fadeIn('#' + changeDiv + '',800);

}


function showConditions(LanguageID) {

        var divID = '#conditions';

        $.ajax({
			    type: "POST",
			    url: serverUrl + "/_ajax/ajaxConditions.aspx",
			    data: 	"LanguageID=" + LanguageID ,
    					
		        beforeSend: function() { 

		        },
    					
		        complete: function() { 
		            
		        },
    		    
			    success: function(html){

				    $(divID).html(html);
			    }
		    });

}


function deletePicture(PictureID) {

    if (confirm('Radera denna bild?')) {

        var divID = '#picturedelete' + PictureID;

        $.ajax({
			    type: "POST",
			    url: serverUrl + "/_ajax/ajaxDeletePicture.aspx",
			    data: 	"PictureID=" + PictureID ,
    					
		        beforeSend: function() { 

		        },
    					
		        complete: function() { 
		            
		        },
    		    
			    success: function(html){

				    $(divID).html(html);
			    }
		    });
    }
}



function likeDislike(likeDislikeValue,ObjectSection,ObjectID) {
    
    var divID = '#likedislineMainContainer' + ObjectSection + ObjectID + '';
    
    $(divID).fadeOut("slow", function() {

        $.ajax({
			    type: "POST",
			    url: serverUrl + "/_ajax/ajaxLike.aspx",
			    data: 	"ObjectID=" + ObjectID + 
			            "&likeDislikeValue=" + likeDislikeValue +
					    "&ObjectSectionID=" + ObjectSection,
    					
		        beforeSend: function() { 
    		        
		        },
    					
		        complete: function() { 
		            
		        },
    		    
			    success: function(html){
			        //alert(html);
				    $(divID).html(html);
				    $(divID).fadeIn("fast");
			    }
		    });

    
    });
    
}


function switchRegisterPanel(switchTo) {

    if (switchTo == 'show') {
        fadeIn('#memberRegisterPanel',800);
        setTimeout("scrollWin('#memberRegisterPanel');",500);
    } else {
        scrollWin('#wrapper');
        setTimeout('fadeOut("#memberRegisterPanel",800);',500);
    }
}


function showAddPanel() {

        fadeIn('.displayNone',800);
}



function scrollWin(scrollToDiv){
    $('html, body').animate({
        scrollTop: $("" + scrollToDiv + "").offset().top
    }, 500);
}

function fadeOut(fadeelement, fadeOutTime) {
    $(''+ fadeelement +'').fadeOut(fadeOutTime, function() {
            
    });
}

function fadeIn(fadeelement, fadeInTime) {
    $(''+ fadeelement +'').fadeIn(fadeInTime, function() {
            
    });
}

function closeRegisterPanel() {

  fadeOut('#modal-overlay', 180);
  fadeOut('#memberRegisterPanel', 180);

}


function closeInfoPanel() {

  fadeOut('#modal-overlay', 180);
  fadeOut('#memberInfoPanel', 180);

}




(function($){
	$.fn.extend({
		modalPanel: function() {
		    
		    //Our function for hiding the modalbox
			function modalHide() {
				$(document).unbind("keydown", handleEscape);
				var remove = function() { $(this).remove(); };
				overlay.fadeOut(remove);
				
				if ($('#memberRegisterPanel').length) {
				    fadeOut('#memberRegisterPanel', 180);
				} else {
				    fadeOut('#memberInfoPanel', 180);
				}
				
				modalWindow
					.fadeOut(remove)
					.empty();
			}
			
			//Our function that listens for escape key.
			function handleEscape(e) {
				if (e.keyCode == 27) {
					modalHide();
				}
			}
			
			//Create our overlay object
			var overlay = $("<div id='modal-overlay'></div>");
			//Create our modal window
			var modalWindow = $("<div id='modal-window'></div>");
			
			return this.each(function() {
				//Listen for clicks on objects passed to the plugin
				$(this).click(function(e) {
					
					if (typeof document.body.style.maxHeight === "undefined") { //if IE 6
						$("body","html").css({height: "100%", width: "100%"});
					}
					
					//Append the overlay to the document body
					$("body").append(overlay.click(function() { modalHide(); }));
					//Add a loader to our page
					$("body").append("<div id='modal-load'></div>");
					
					//Set the css and fade in our overlay
					overlay.css("opacity", 0.8);
					overlay.show();
					
					//Prevent the anchor link from loading
					e.preventDefault();
					
					//Activate a listener 
					$(document).keydown(handleEscape);
					
					if ($('#memberRegisterPanel').length) {	
					    fadeIn('#memberRegisterPanel', 180);
					} else {
					    fadeIn('#memberInfoPanel', 180);
					}
					
					//Load the image
					/*
					var img = new Image();
					$(img).load(function () {
						var imageWidth = img.width / 2;
						var imageHeight = img.height / 2;
						modalWindow.css({
							"margin-left": -imageWidth,
							"margin-top": -imageHeight
						});
						$("#modal-load").remove();
						modalWindow.append(img);
						$(this).addClass("modal-image");
						$("body").append(modalWindow);
						modalWindow.fadeIn(50);
					})
					
					
					.attr({ src: this.href }).click(function() {
						modalHide();
					});
					*/
					
					
					
				});
			});
		}
	});
})(jQuery);



 function initiateKeepalive() {

            setTimeout('keepAlive()',1000)

        }
        

function keepAlive() {

    
        var ObjectID = '';
        var likeDislikeValue = '';
        var ObjectSection = '';
    
        $.ajax({
			    type: "POST",
			    url: serverUrl + "/_ajax/ajaxKeepalive.aspx",
			    data: 	"ObjectID=" + ObjectID + 
			            "&likeDislikeValue=" + likeDislikeValue +
					    "&ObjectSectionID=" + ObjectSection,
    					
		        beforeSend: function() { 
    		        
		        },
    					
		        complete: function() { 
		            
		        },
    		    
			    success: function(html){

				    $("#keepalive").html(html);
				    setTimeout('keepAlive()',20000)
			    }
		    });
    

}



function logLinkClick(section,strID) {

    
    
        $.ajax({
			    type: "POST",
			    url: serverUrl + "/_ajax/ajaxLogUrl.aspx",
			    data: 	"section=" + section + 
			            "&url=" + location.href +
					    "&ID=" + strID,
    					
		        beforeSend: function() { 
    		        
		        },
    					
		        complete: function() { 
		            
		        },
    		    
			    success: function(html){

				    /*
                    alert('b');
				    $("#act").html(html);
				    $("#comid").html(html);
				    setTimeout('keepAlive()',20000)
				    */
			    }
		    });
    

}

$(document).ready(function(){	
			$("#slider").easySlider({
				auto: true, 
				continuous: true,
				vertical: false,
				speed: 400,
				pause: 5000,
				numeric: true
			});
			
			$("a[rel^='prettyPhoto']").prettyPhoto({theme:'facebook'});
            $('a[rel*=modalPanel]').modalPanel();		

            $(".companyLink").bind("click", companyLinkClick)
            $(".activitysuggestionLink").bind("click", activitysuggestionLinkClick)

            initiateKeepalive();
            
	    });	
	    
	    
          function companyLinkClick()
          {
                logLinkClick('company',$(this).attr("rel"));
          }

          function activitysuggestionLinkClick()
          {
                logLinkClick('',$(this).attr("rel"));
          }


/*
*/



	function lookup(inputString) {

		if(inputString.length == 0) {
			// Hide the suggestion box.
			$('#suggestions').hide();
		} else {

			/*$.post("/_ajax/ajaxSearch.aspx", {queryString: ""+inputString+""}, function(data){
				if(data.length >0) {
					$('#suggestions').show();
					$('#autoSuggestionsList').html(data);
				}
			});
			
			*/
			
                $.ajax({
			    type: "POST",
			    url: serverUrl + "/_ajax/ajaxSearch.aspx",
			    data: 	"search=" + inputString,
    					
		        beforeSend: function() { 
		            //$('#autoSuggestionsList').html('<div class="searchLoader"><img src="/_gfx/shell/ajaxLoader.gif" width="16" height="11" alt="laddar..." title="laddar..." /></div>');
    		        $('#suggestions').show();
		        },
    					
		        complete: function() { 
		            
		        },
    		    
			    success: function(html){
			    
					
					$('#autoSuggestionsList').html(html);
			    }
		    });
			
		}
	} // lookup
	
	function fill(thisValue) {
		$('#inputString').val(thisValue);
		setTimeout("$('#suggestions').hide();", 200);
	}


