/*
 * $Id: common.js 216 2009-10-16 14:17:34Z joris $
 */
function newWindow(mypage,myname,w,h,features) {
	if(screen.width){
		var winl = (screen.width-w)/2;
		var wint = (screen.height-h)/2;
	}
	else{winl = 0;wint =0;}
	if (winl < 0) winl = 0;
	if (wint < 0) wint = 0;

	var settings = 'height=' + h + ',';
	settings += 'width=' + w + ',';
	settings += 'top=' + wint + ',';
	settings += 'left=' + winl + ',';
	settings += features;
	win = window.open(mypage,myname,settings);
	win.window.focus();
}

$(function() {
//	Custom.init();
	var searchField = $('input#headerSearch');

	if (searchField.length > 0) {
		wipeTextOnFocus(searchField, 'Zoek in de website');
	}

	var ss = new SlideShow();
	ss.addSlides($('div.bannerContainer div.banner'));
	ss.start();

	$('div.processedContent div.block div.contentHomeText').each(function() {
		addLink(this);
	});

	$('div.processedContent div.block div.contentHomeTextText').each(function() {
		addLink(this);
	});

	$('div.processedContent div.block').each(function() {
		addLinkImageText(this);
	});

	$('div.section div.block div.contentHomeText').each(function() {
		addLink(this);
	});

	$('div.section div.block div.contentHomeTextText').each(function() {
		addLink(this);
	});

	$('div.section div.block').each(function() {
		addLinkImageText(this);
	});

	$('.preOther').each(function(){
		var toSize = $(this).parent().children('.fullWidth');
		var width = $(this).parents('.option').innerWidth() - $(this).outerWidth(true);
		toSize.width(width - 21);
//		$(this).parent().css('padding-left', $(this).outerWidth(true) + 5);
//		$(this).css('margin-left', -$(this).outerWidth(true) - 5);
	});

	if (typeof addthis == 'object') {
		addthis.addEventListener('addthis.menu.share', function(evt){
			window.printedElement.toggleClass("noPrint");
			$('.block').toggleClass("noPrint");
		});
		addthis.addEventListener(
			'addthis.ready',
			function(evt){
				$('.at15t_print').click(function(e){
					$('.block').toggleClass("noPrint");
					window.printedElement = $(e.target).closest('.block');
					window.printedElement.toggleClass("noPrint");
				});
			}
		);
	}
});

function wipeTextOnFocus(input, defaultValue) {
	var clone = input.clone();

	clone.attr('name', '');
	clone.attr('id', '');
	clone.attr('value', defaultValue);
	clone.css('display', 'none');

	var blur = function(e) {
		if (input.val() == '') {
			clone.css('display', '');
			input.css('display', 'none');
		}
	};
	blur();

	var focus = function(e) {
		clone.css('display', 'none');
		input.css('display', '');
		input.focus();
	};


   input.blur(blur);
   clone.focus(focus);

   clone.insertBefore(input);
}

function addLink(elem) {
	if ($(elem).find('a.blockLink').length > 0) {
		var link = $(elem).find('a.blockLink');

		$(elem).css('cursor', 'pointer');
		$(elem).attr('title', link.attr('title'));

		$(elem).mouseover(function() {
			window.status = window.location + $(link).attr('href');
		});

		$(elem).mouseout(function() {
			window.status = '';
		});

		$(elem).click(function() {
			window.location = $(link).attr('href');
		});
	}
}

function addLinkImageText(elem) {
	if ($(elem).find('a.blockLink').length > 0) {
		var link = $(elem).find('a.blockLink');

		if ($(elem).find('div.contentTextTwoColumns').length > 0) {
			$(elem).css('cursor', 'pointer');
			$(elem).attr('title', link.attr('title'));

			$(elem).mouseover(function() {
				window.status = window.location + $(link).attr('href');
			});

			$(elem).mouseout(function() {
				window.status = '';
			});

			$(elem).click(function() {
				window.location = $(link).attr('href');
			});
		}

	}
}

function copyAddress(frm) {
	var elems = new Array('adres', 'huisnummer', 'postcode', 'plaats', 'land');
	while (elem = elems.pop()) {
		var element  = 'shop[' + elem + ']';
		var element2 = 'shop[' + elem + '2]';
		frm.elements[element2].value = frm.elements[element].value;
	}
}
