$(document).ready(function(){

	if($('#productslider').length>0){

		$('#productslider').cycle({
			fx:			'fade',
			timeout:	8000,
			speed:		1000,
			cleartype:	true,
			pager:		'#indicators',
			pagerAnchorBuilder: function(idx, slide) {
				return '<a href="#"></a>';
			}
		});
	
	}

	if($('#slide').length>0){

		$("#slide").jcarousel({
		    scroll: 1,
		    wrap: 'circular',
		    animation: 500,
		    initCallback: mycarousel_initCallback,
		    // This tells jCarousel NOT to autobuild prev/next buttons
		    buttonNextHTML: null,
		    buttonPrevHTML: null
		});
	
	}

	$(document).find('.scrambleemail').each(function(){
		scrambleEmail($(this));
	});
	
	$(".partners img").hover(
	  function () {
	    $(this).attr("src",$(this).attr("src").replace('off','on'));
	  },
	  function () {
	    $(this).attr("src",$(this).attr("src").replace('on','off'));
	  }
	);

});

function shownewstab(id){

	$('#faner').html( $('#'+id).html() )

	if(id=='newstabon'){
		$('#newscontent').html( $('#news').html() );
	} else {
		$('#newscontent').html( $('#facebook').html() );
	}

}

function checkcontributionform(me){

	var contribution = 0;
	
	if(me.preamount.value!=''){
		contribution = me.preamount.value;
	}

	if(me.amount.value!=''){
		contribution = me.amount.value;
	}
	
	if(contribution>0){
		me.submit();		
	}

}


function mycarousel_initCallback(carousel) {

    jQuery('.jcarousel-control a').bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
        return false;
    });
 
    jQuery('#mycarousel-next').bind('click', function() {
        carousel.next();
        return false;
    });
 
    jQuery('#mycarousel-prev').bind('click', function() {
        carousel.prev();
        return false;
    });

};

function scrambleEmail(string){

	var emailarray = string.html().split('|');
	var account = emailarray[0];
	var domain = emailarray[1];
	var subject = '';
	
	if(emailarray[2]){subject=emailarray[2]};
	
	var email = account + '@' + domain;
	
	string.html('<a href="mailto:'+email+'?subject='+subject+'">'+email+'</a>');

}

function checkmyform(me) {
		
	resetfieldclasses(me);
	
	if (me.navn.value==''){alert('Angiv venligst dit navn.'); redalert(me.navn); return false;}
	if (me.adresse.value==''){alert('Angiv venligst adresse.'); redalert(me.adresse); return false;}
	if (me.postnummer.value==''){alert('Angiv venligst dit postnummer.'); redalert(me.postnummer); return false;}
	if (me.by.value==''){alert('Angiv venligst din by.'); redalert(me.by); return false;}
	if (!emailCheck(me.email.value)){alert('Din mailadresse er ikke gyldig.'); redalert(me.email); return false;}
	if (me.antal.value==''){alert('Angiv venligst et antal.'); redalert(me.antal); return false;}
	
	me.submit();

}

function resetfieldclasses(me){
	for ( var i=0;i<me.elements.length;i++ )
	{
		if(me.elements[i].name != ''){
			if( me.elements[i].type=='text' )
			{
			me.elements[i].style.border='1px solid #cccccc';
			}
		}		
	}
}

function redalert(me){
	me.style.border='1px solid red';
	me.focus();
}

function setSelectedIndex( me, valsearch )
{
  for (i = 0; i< me.options.length; i++)
  {
    if (me.options[i].value == valsearch)
    {
      me.options[i].selected = true;
      me.options[i].style.backgroundColor = '#dddddd';
      break;
    }
  }
  return;
}

