jQuery.fn.supersleight = function(settings) {
	settings = jQuery.extend({
		imgs: true,
		backgrounds: true,
		shim: '../images/x.gif',
		apply_positioning: true
	}, settings);
	
	return this.each(function(){
		if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7 && parseInt(jQuery.browser.version, 10) > 4) {
			jQuery(this).find('*').andSelf().each(function(i,obj) {
				var self = jQuery(obj);
				// background pngs
				if (settings.backgrounds && self.css('background-image').match(/\.png/i) !== null) {
					var bg = self.css('background-image');
					var src = bg.substring(5,bg.length-2);
					var mode = (self.css('background-repeat') == 'no-repeat' ? 'crop' : 'scale');
					var styles = {
						'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='" + mode + "')",
						'background-image': 'url('+settings.shim+')'
					};
					self.css(styles);
				};
				// image elements
				if (settings.imgs && self.is('img[src$=png]')){
					var styles = {
						'width': self.width() + 'px',
						'height': self.height() + 'px',
						'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + self.attr('src') + "', sizingMethod='scale')"
					};
					self.css(styles).attr('src', settings.shim);
				};
				// apply position to 'active' elements
				if (settings.apply_positioning && self.is('a, input') && (self.css('position') === '' || self.css('position') == 'static')){
					self.css('position', 'relative');
				};
			});
		};
	});
};

$(document).ready(function(){

	$('.js-png').supersleight();
	
	$('.js-hide').hide();
	
	$('.js-linkblock').click(function(){
    	window.location=$(this).find('a').attr('href');return false;
	});	
	
	$('input:text, textarea, select').focus(function() {
		$(this).addClass('input_active');  
	}).blur(function() {
		$(this).removeClass('input_active');  
	});
	
	$('.js-clearfocus').focus(function() {  
		if (this.value == this.defaultValue){  
			this.value = '';  
		}  
	}).blur(function() {  
		if (!this.value.length){  
			this.value = this.defaultValue;
		}  
	}); 

	$('a.fb').fancybox({
		'padding'	: 0,
		'margin'	: 0,
		'scrolling' : false
	});
	
	$('a.fb-vestiging').fancybox({
		'padding'	: 0,
		'margin'	: 0,
		'width'		: 625,
		'height'	: 631,
		'scrolling' : false,
		'type'		: 'iframe'
	});
	
	$('.js-fb_linkblock').click(function(){
		$('a.fb', this).fancybox().trigger('click');
	});	
	
	$('a.fb_iframe').fancybox({
		'width'				: '75%',
		'height'			: '75%',
        'autoScale'     	: false,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});
	
	$('#container #overlay .content .close').click(function(){
		if(isIE()) {
			$('#container #overlay').hide();
		} else {
			$('#container #overlay').fadeOut(400);
		}
		$('#container #overlay').removeClass('show');
		$('#container #overlay').addClass('hidden');	
	});
	
	$('.contact_vestiging').hide();
	$('#vestiging-emolifestreet').show();
	
	$('.open-vestiging').click(function() {
		var target = $(this).attr('href').replace('#','');
		var current = $('.contact_vestiging:visible').attr('id').replace('vestiging-','');
		if(target != current) {
			$('#vestiging-'+target).show();
			$('#vestiging-'+current).hide();
		}

	});
	
	$('.checkbox').checkbox();
	
	$('#onzeklanten').cycle();
	$('#jecollegas').cycle();
	$('#voordelen_slider').cycle();
	
});

function externalLinks() {
	if (!document.getElementsByTagName) return;
		var anchors = document.getElementsByTagName("a");
		for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") &&
			anchor.getAttribute("rel") == "external")
			anchor.target = "_blank";
		}
	}
window.onload = externalLinks;

function isIE()
{
	return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
}

Cufon.replace('#navigation a', { fontFamily: 'Code Bold', fontSize: '15px' });
Cufon.replace('#content .block.thesalesunitbig .link', { fontFamily: 'Code Bold', fontSize: '26px' });
Cufon.replace('#content .block.emolifestreet .link', { fontFamily: 'Code Bold', fontSize: '18px' });
Cufon.replace('#content .block.sqpeople .link', { fontFamily: 'Code Bold', fontSize: '18px' });
Cufon.replace('#content .block.dotest .title', { fontFamily: 'Code Bold', fontSize: '65px' });
Cufon.replace('#container #content .block.facebook', { fontFamily: 'Code Bold', fontSize: '32px' });
Cufon.replace('#footer a', { fontFamily: 'Code Bold', fontSize: '11px' });
Cufon.replace('#content .block .title.big', { fontFamily: 'Code Bold', fontSize: '48px' });
Cufon.replace('#container #content .block .blocktitle', { fontFamily: 'Code Bold', fontSize: '30px' });
Cufon.replace('#container #content .block.emolifesmall .link', { fontFamily: 'Code Bold', fontSize: '18px' });
Cufon.replace('#container #content .block.sqpeoplesmall .link', { fontFamily: 'Code Bold', fontSize: '18px' });
Cufon.replace('#container #content .block.thesalesunitsmall .link', { fontFamily: 'Code Bold', fontSize: '18px' });
Cufon.replace('#container #content .block.schrijfin', { fontFamily: 'Code Bold', fontSize: '51px' });
Cufon.replace('#overlay .content .more', { fontFamily: 'Code Bold', fontSize: '26px' });
Cufon.replace('#container #content .title.signin', { fontFamily: 'Code Bold', fontSize: '47px' });

Cufon.replace('.code-bold', { fontFamily: 'Code Bold' });
