(function($){
 $.fn.extend({
 
 	customStyle : function(options) {
	  if(!$.browser.msie || ($.browser.msie&&$.browser.version>6)){
	  return this.each(function() {
	  
			var currentSelected = $(this).find(':selected');
			$(this).after('<span class="customStyleSelectBox"><span class="customStyleSelectBoxInner">'+currentSelected.text()+'</span></span>').css({position:'absolute', opacity:0,fontSize:$(this).next().css('font-size')});
			var selectBoxSpan = $(this).next();
			var selectBoxWidth = parseInt($(this).width()) - parseInt(selectBoxSpan.css('padding-left')) -parseInt(selectBoxSpan.css('padding-right'));			
			var selectBoxSpanInner = selectBoxSpan.find(':first-child');
			selectBoxSpan.css({display:'inline-block'});
			selectBoxSpanInner.css({width:selectBoxWidth, display:'inline-block'});
			var selectBoxHeight = parseInt(selectBoxSpan.height()) + parseInt(selectBoxSpan.css('padding-top')) + parseInt(selectBoxSpan.css('padding-bottom'));
			$(this).height(selectBoxHeight).change(function(){
				// selectBoxSpanInner.text($(this).val()).parent().addClass('changed');   This was not ideal
			selectBoxSpanInner.text($(this).find(':selected').text()).parent().addClass('changed');
				// Thanks to Juarez Filho & PaddyMurphy
			});
			
	  });
	  }
	}
 });
})(jQuery);

$(document).ready(function() { 
/**/
$('.sd_select').customStyle();
$('.sd_select').hover(function(){
$(this).next().addClass("hover");
},function(){
$(this).next().removeClass("hover");
});
/**/
  $('input.clear').each(function() {
    $(this)
      .data('default', $(this).val())
      .addClass('inactive')
      .focus(function() {
        $(this).removeClass('inactive');
        $(this).addClass('focus');
        if($(this).val() == $(this).data('default') || '') {
          $(this).val('');
        }
      })
      .blur(function() {
        var default_val = $(this).data('default');
        if($(this).val() == '') {
          $(this).addClass('inactive');
          $(this).val($(this).data('default'));
          $(this).removeClass('focus');
        }
      });
  });
/**/


/* Sliding anchors Start */
$('a[href*=#]').click(function() {
	if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
	&& location.hostname == this.hostname) {
		var $target = $(this.hash);
		$target = $target.length && $target
		|| $('[name=' + this.hash.slice(1) +']');
		if ($target.length) {
			var targetOffset = $target.offset().top;
				$('html,body')
					.animate({scrollTop: targetOffset}, 400);
		return false;
		}
	}
});
/* Sliding anchors End */
$('#toplink a').hide();

/* to the top */
	if($(window).height() < $(document).height()){
		$('#toplink a').show();
		/*$('#toplink').append('<a href="#top">Till toppen</a>');*/
	};
/**/

$('#slide').toggle(function(){
	$(this).stop().animate({
			left: '0' 
		},1500,'easeOutQuint')
	$(this).addClass("active");
},function(){
	$(this).stop().animate({
			left: '656px'
		},1500,'easeOutQuint')	
	$(this).removeClass("active");
})



/* Clickable block Start */
$('.block').click(function(){
	  window.location=$(this).find("a").attr("href"); return false;
});
$('.course').click(function(){
	  window.location=$(this).find(".sd_buy a").attr("href"); return false;
});

$('.course').hover(function(){
	$(this).addClass("hover");
	$(this).find(".sd_buy a").addClass("hover");
},function(){
	$(this).removeClass("hover");
	$(this).find(".sd_buy a").removeClass("hover");
});




/* Clickable block End */
$('a[href*=.pdf]').addClass("pdf");


/* toggle show/hide */
/*
	$('.toggle').hide();
	
	$('.toggleBtn').click(function() {
		$(this).siblings('.toggle').slideToggle('slow');
		$(this).toggleClass('active');	
	});
*/


var pathname = window.location.pathname;
var shareUrl = "http://www.facebook.com/sharer.php?u=http://www.vjs.se"+pathname+"&t=Titel";
$(".share.facebook").attr("href",shareUrl);
    



if($("#contactform").length > 0){
$("#contactform form").validate({
		errorElement: "em",

		rules: {
			firstname: "required",
			lastname: "required",
			tel: "required",
			company: "required",
			address: "required",
			zip: "required",
			state: "required",
			email: {
				required: true,
				email: true
			}
		},
			messages: {
			firstname: "",
			lastname: "",
			tel: "",
			company: "",
			address: "",
			zip: "",
			state: "",
			email: ""
		}
	});
}




}); /* end doc-ready */

Cufon.replace('#bigheader h1, #bigheader h2, h1,h2,h3,h4', {
	hover: true,
	fontFamily: 'gs'
});
Cufon.replace('#readmore,.readmore2', {
	textShadow: '#78702d 0px 1px',
	hover: true,
	fontFamily: 'gs'
});
Cufon.replace('.bll', {
	fontFamily: 'bll'
});
Cufon.now();
