var Site = {
	
	qSlide : true,
	
	onReady : function() {
		
		Site.init();
		
		$('a.lang_swedish').live('click', Site.langSwedish);
		$('a.lang_english').live('click', Site.langEnglish);
		
		$("a.user_message_close").live('click', Site.hideMessages);
		
		$(".header").live('click', Site.headerClick);
	},

	langSwedish : function() {
		$.ajax({
			url: "/user/language/",
			type: "post",
			data: { lang: 1 },
			success: function () {
				window.location.reload();
			},
			error: function() {
				Boxy.alert("theres an error with AJAX");
			}
		});
		
		return false;
	},
	langEnglish : function() {
		$.ajax({
			url: "/user/language/",
			type: "post",
			data: { lang: 2 },
			success: function () {
				window.location.reload();
			},
			error: function() {
				Boxy.alert("theres an error with AJAX");
			}
		});
		
		return false;
	},


	hideMessages : function() {
		$(this).parent().slideUp();
		return false;
	},
	
	headerClick : function() {
		arr = $(this).attr('id').split('_');
		loc = arr[1];
		
		
		if ( loc == 'index' ) {
			loc = "";
		}
		
		//alert(loc);
		
		window.location = '/' + loc;	
	},
	
	init : function() 
	{
		$('.ui_butt').button();
		
		$('.user_message').slideDown();
	/*
		$('a.fancybox').fancybox({
			'transitionIn' : 'none',
			'transitionOut' : 'none',
			'titlePosition' : 'inside',
			'overlayOpacity' : '0.8',
			'overlayColor' : '#000',
			'width' : '300',
			'height' : '300',
			'ajax' : {
				'type' : "POST"
			}
		});
	*/	
	
	jQuery.fn.extend({
	  haccordion: function(params){
	    var jQ = jQuery;
	    var params = jQ.extend({
	      	speed: 300,
	      	headerclass: "header",
	      	contentclass: "content",
	      	contentwidth: 795,
			busy: false,
			currentId: 'foo'
	    },params);

	    return this.each(function(){
	      	jQ("."+params.headerclass,this).click(function(){

				if ( Site.qSlide )
				{
					if ( params.currentId == $(this).attr('id') ) {
						return;
					} else {
						if ( params.busy === true ) {
							return;
						} else {
						params.currentId = $(this).attr('id');
						}
					}

					if ( params.busy === true ) { 
						return; 
					} else {
						params.busy = true;
					}

		        	var p = jQ(this).parent()[0];
		        	if (p.opened != "undefined"){
		          		jQ(p.opened).next("div."+params.contentclass).animate({
		            		width: "0px"
		          		},params.speed, function() {
					    	// Animation complete.
							params.busy = false;
					  	});
		        	}

					p.opened = this;
		        	jQ(this).next("div."+params.contentclass).animate({
		          		width: params.contentwidth + "px"
		        	}, params.speed, function() {
				    	// Animation complete.
						params.busy = false;
					});
				}
	      	});
	    });
	  }
	});
		
		
		$(".haccordion").haccordion();
		
		//$("#accordion_examples").css('width', 764);
		
		$("#accordion_" + $('#accordion').text()).trigger('click');
		
		Site.qSlide = false;
	}
};

$(document).ready(Site.onReady);





