jQuery(document).ready(function(){
	
	if(typeof sIFR == "function"){
		
		sIFR.replaceElement("h1.sifred", named({sFlashSrc: "/extension/ezwebin/design/ezwebin/images/din_medium_28px.swf", sColor: "#427730", sWmode:"opaque", sFlashVars: "offsetLeft=0" }));
		sIFR.replaceElement("h2.sifred", named({sFlashSrc: "/extension/ezwebin/design/ezwebin/images/din_medium_18px.swf", sColor: "#427730", sWmode:"opaque", sFlashVars: "offsetLeft=0" }));
		sIFR.replaceElement("h2.sifred-comment", named({sFlashSrc: "/extension/ezwebin/design/ezwebin/images/din_medium_18px.swf", sColor: "#427730", sBgColor: '#fbfbfb', sFlashVars: "offsetLeft=0" }));
		sIFR.replaceElement("h2.sifred-topnews", named({sFlashSrc: "/extension/ezwebin/design/ezwebin/images/din_medium_18px.swf", sColor: "#ffffff",sWmode:"transparent", sFlashVars: "offsetLeft=0" }));
	}
	
	$('#Search').focus(function(){
		if($('#Search').val() == "Søg efter et videoklip her...")
			$('#Search').val("");
	});
	
	$('#email_input').focus(function(){
		if($('#email_input').val() == "Indtast brugernavn")
			$('#email_input').val("");
	});
	
	$('#password_input').focus(function(){
		$('#password_input').remove();
		$('#loginbox').append('<input id="password_input" type="password" size="30" name="Password" id="id2" value="" tabindex="1" />');
		$('#password_input').focus();
		
	});   
	
	$('div#sortwrapper-top ul li a,div.addfriend a').hover(function(){
		var lefties = Array('tipafriend', 'mp3link', 'addfriend', 'adgangforalle');
		if (jQuery.inArray($(this).attr('id'), lefties)>=0 )
			$('#topbar-title-left').html($(this).attr('title')+ '&nbsp;');
		else
			$('#topbar-title').html($(this).attr('title')+ '&nbsp;');
	},function(){
		$('#topbar-title').html("");
		$('#topbar-title-left').html("");
	});
	
	$('div.recorded').hover(function(){
		$('#topbar-title-left').html($('div.recorded a').attr('title')+ '&nbsp;');
	},function(){
		$('#topbar-title-left').html("");
	});
	
	if ( $('div.recorded,div.addfriend').length > 0 ) {
		$('#topbar-title-left').css("margin-left", "35px");
	}

	
	var closeArray = new Array();
	var openArray = new Array();
    $(".q_answer")
     .click(function(){

  	
		
        var body_id = '#' + $(this).attr('rel');
    	var qbody = document.getElementById($(this).attr('rel'));
    	if(qbody.style.display != 'block')
        	$(body_id).slideDown("fast");
        	else
        	$(body_id).slideUp("fast");
     })
    
    $(function(){
	    $("#password_input").keydown(function(e){
	        if (e.keyCode == 13) {
	            $(this).parents("form").submit();
	            return false;
	        }
	    });
	});


      
     $(".e_answer")
     .click(function(){
		if(typeof sIFR == "function"){
     		sIFR.rollback();
     		sIFR.replaceElement("h1.sifred", named({sFlashSrc: "/extension/ezwebin/design/ezwebin/images/din_medium_28px.swf", sColor: "#427730", sWmode:"opaque", sFlashVars: "offsetLeft=0" }));
     		sIFR.replaceElement("h2.sifred", named({sFlashSrc: "/extension/ezwebin/design/ezwebin/images/din_medium_18px.swf", sColor: "#427730", sWmode:"opaque", sFlashVars: "offsetLeft=0" }));
		}
     	for (var i = 0; i < closeArray.length; i++) {
			$("#"+closeArray[i].id).slideUp("fast");
     	}
     	for (var i = 0; i < openArray.length; i++) {
			$(openArray[i]).show();
     	}
		closeArray = new Array();
		openArray = new Array();
		var top = 	 $(this + ":first-child").children();
		$(this + ":first-child").show();
        var body_id = '#' + $(this).attr('rel');
    	var qbody = document.getElementById($(this).attr('rel'));
    	if(qbody.style.display != 'block'){
    		$(body_id).slideDown("fast", function(){
    			if(typeof sIFR == "function"){
    				sIFR.replaceElement("h2.sifred-event", named({sFlashSrc: "/extension/ezwebin/design/ezwebin/images/din_medium_18px.swf", sColor: "#427730", sWmode:"opaque", sFlashVars: "offsetLeft=-2" }));
    			}
    		});
        	closeArray.push(qbody);
        	openArray.push(this);
    	} else {
        	$(body_id).slideUp("fast");
    	}
     })
     
      $(".q_answer_submit")
     .click(function(){
        var body_id = '#' + $(this).attr('rel');
    	var qbody = document.getElementById($(this).attr('rel'));
    	if(qbody.style.display != 'block')
        	$(body_id).slideDown("fast");
        else
        	$(body_id).slideUp("fast");
     })
     
    
     
     $(".class-poll").each(function() {
		var id = parseInt($(this).attr('id').substring(5));
		showPoll(id);
	});
     
	$("ul#nextmonth").hover( function() {},
	  function() { $("ul#nextmonth").animate({opacity:1.0},100).hide(0); return false;
	});   
  	$("ul#lastmonth").hover( function() {},
	  function() { $("ul#lastmonth").animate({opacity:1.0},100).hide(0); return false;
	}); 
}); 


function showEcard(id, first){

  		var body_id = '#' + 'image-' + id;
        $('#showcase').slideUp("fast");
    	$('#showcase').html($(body_id).html());
    	$('#showcase').slideDown("fast", function(){
    		var cardheight = $(body_id).height();
    		var offset = jQuery("#showcase").offset(); 
    		if (first)
    			window.scroll(0,offset.top - 35);
    	});
    	$('#cardID').attr("value" , id);
    	
    }
    
function ajaxSubmitForm(form, target){

		$('#' + form).ajaxSubmit('#' + target);
		
		$('#' + target).slideDown("fast");
		
}
	
function Toggle(obj)
{
	$("#"+obj).toggleClass("hidden");
}
function UpdateSorts(){
	var neworder = order == '0' ? '1' : '0';
	var navn = document.getElementById('sort-navn');
	var medlem = document.getElementById('sort-medlem');
	var dato = document.getElementById('sort-dato');
	navn.href = path + '(sortby)/navn/(order)/' + neworder;
	medlem.href = path + '(sortby)/medlem/(order)/' + neworder;
	dato.href = path + '(sortby)/dato/(order)/' + neworder;
	
	switch (sortby){
	case 'navn':
		navn.style.backgroundImage = 'url(/extension/ezwebin/design/ezwebin/images/hjaelpdanmark/arrow_' + order + '.png)';
	break;
	case 'medlem':
		medlem.style.backgroundImage = 'url(/extension/ezwebin/design/ezwebin/images/hjaelpdanmark/arrow_' + order + '.png)';
	break;
	case 'dato':
		dato.style.backgroundImage = 'url(/extension/ezwebin/design/ezwebin/images/hjaelpdanmark/arrow_' + order + '.png)';
	break;
	
	}
	
	
}


function down(id)
{
	$("ul#" + id).animate({height:"show",opacity:"show"},"fast");
}

function showPoll(id){
	
		$.get("/ezfusedajax/poll/"+id+"/",
	 	 function(data){
	 	 	$('#votecontent-'+id).html(data);
	 	 	var count = parseInt($("#voteresults-"+id).html());
	 	 	
			 $('#votecontent-'+id).slideDown('normal', function(){
			 	if(count > 0)
				 $('#result1-'+id).show('normal', function(){
				 		if(count >= 1)
						$('#result2-'+id).show('normal', function(){
							if(count >= 2)
							$('#result3-'+id).show('normal', function(){
								if(count >= 4)
								$('#result4-'+id).show('normal', function(){
									if(count >= 5)
									$('#result5-'+id).show('normal', function(){
										if(count >= 6)
										$('#result6-'+id).show('normal', function(){
											if(count >= 7)
											$('#result7-'+id).show('normal', function(){
												if(count >= 8)
												$('#result8-'+id).show('normal');
											});
										});
									});
								});
							});
						});
				});
			});
	 	 	
	 	 });
		
}

function confirmation() {
	var answer = confirm("Er du sikker på at du ønsker at opsige din profil? (din blog og indlæg vil stadig blive på hopskud)")
	if (answer){
		window.location = "/unsubscribe/user";
	}
}


function submitVote(id){
	var data = '';
	$(':input', $("#pollform-"+id)).each(function() {
    	if (this.type == 'radio'){
    		if(this.checked == true){
    			data +=this.name + "=" + this.value + "&";
    		}
    	}else{
    		data +=this.name + "=" + this.value + "&";
    	}
    			
    	
	});

	$.ajax({
	   type: "POST",
	   url: "/content/action",
	   data: data,
	   success: function(msg){
		 $('#pollsubmit').fadeOut("fast", function(){
   	 			$('#votecontent-'+id).slideUp('normal', function(){ 
					 showPoll(id);
				});
			});
	   }
	 });
}	 

/**
 * AjaxSubmit 1.0
 *
 * Submits a form using XHR. Grabs all form-controls
 * with name-attributes and submits to form's action
 * using form's method or custom action/method set in conf
 *
 * @class ajaxSubmit
 * @param {String|Function} foo, CSS-selector to element to be updated with XHR-response or callback function for XHR-call (data is passed to function)
 * @param {Object} conf, custom config-object
 * 
 * Copyright (c) 2008 Andreas Lagerkvist (andreaslagerkvist.com)
 * Released under a GNU General Public License v3 (http://creativecommons.org/licenses/by/3.0/)
 */
jQuery.fn.ajaxSubmit = function(foo, conf) {
	var config = {
		method: false,	// request method (get/post) defaults to form's
		action: false,	// action (url) defaults to form's
		loading: 'Loading...'
	};
	config = jQuery.extend(config, conf);

	var callback = (typeof(foo) === 'string') ? function(data) {jQuery(foo).html(data);} : (typeof(foo) === 'function') ? foo : false;

	return this.each(function() {
		var form = jQuery(this);

		if(form.is('form')) {
			var method = config.method || form.attr('method');
			var action = config.action || form.attr('action');
			var submit = jQuery('input[type="submit"]', form);
			var data = {};

			//form.submit(function() {
				jQuery('*[name]', form).each(function() {
					var t = jQuery(this);
					var val = (t.attr('type') == 'checkbox') ? (t.attr('checked') == true) ? 1 : 0 : t.val();
					data[t.attr('name')] = val;
				});
				submit.val(config.loading);
				jQuery[method](action, data, function(data) {
					callback(data);
				});

				return false;
			//});
		}
	});
};
