/*****************************************************************************
	Copyright © 2011 Dopeness Galore All rights reserved.

	20110411	Frank Heijkamp
	20110616	Frank Heijkamp
*****************************************************************************/


// Start extending JavaScript

if (typeof Array.indexOf != 'function') {
	Array.prototype.indexOf = function(f, s) {
	if (typeof s == 'undefined') s = 0;
		for (var i = s; i < this.length; i++) {
			if (f === this[i]) return i;
		}
		return -1;
	}
}

// End of JavaScript extensions




var aStack = new Array();




// Start jQuery

$(document).ready(function() {
//	alert('Start of jQuery');


	// huo
	animateSquares();
	animateLinks();
	doGallery();
	anchorsExternBlank();
	eqHeight(1000);
	dojScrollPane();
	doCart();
	sponsorBackground();

	var aBGwidth = new Array(1024,1280,1400,1680,1920,1920,2560);
	var aBGheight = new Array(768,1024,1050,1050,1080,1200,1600);
	var aBGclass = new Array('xga1024x768','sxga1280x1024','sxgap1400x1050','wsxgap1680x1050','hd1920x1080','wuxga1920x1200','wqxga2560x1600');
	scale_background();
	correctTwitter(200);

	handle_mailing_form();
	handle_feedback_form();
	handle_shopping_form();
//	handle_contact_form();
//	handle_excel_table();
//	link_to_sub();
//	hide_write();
	admin_buttons();
	playerMp3(100);


	// Animate the squares
	function animateSquares() {
		// for all .item .container_bg 's's's and .twitter .brood
		$(".item:not(.c_about) .container_bg, .related_press .container_bg, .item.twitter .container .brood, .date").css({ opacity:0.92 });

	//	$(".item .bg").css({ opacity:0.4, background:'#FFF' });
	//dep	$(".item .container_bg").css({ opacity:0.92, background:'#FFF' });

	//dep	$(".full_negative .container_bg").css({ opacity:0.92, background:'#000' });
	//dep	$(".full_negative .brood p, .full_negative .brood h1 a, .full_negative .brood h1").css({ color:'#FFF' });

		// temp
	////	$(".item .container_bg").css({ opacity:0.7, background:'#000' });
	//	$(".item .brood p, .item .brood h1 a, .item .brood h1").css({ color:'#FFF' });
	//	$(".full_negative .brood p, .full_negative .brood h1 a, .full_negative .brood h1").css({ color:'#191C1F' });

		$(".item .brood h1 a, .item .brood h1").css({ 'font-size':'12px' });

	//	$(".item.c_artists .container_bg").css({ opacity:0.92, background:'#F60' });
	//dep	$(".item.c_artists .container_bg").css({ opacity:0.92 }); // , background:'#F60'
	//dep	$(".item.c_records .container_bg").css({ opacity:0.92 }); // , background:'#390'
	//dep	$(".item.c_events .container_bg").css({ opacity:0.92 }); // , background:'#C0C'
	//dep	$(".item.c_recordstore .container_bg, .item.c_merchandisestore .container_bg").css({ opacity:0.92 }); // , background:'#06C'
	//dep	$(".item.c_media .container_bg").css({ opacity:0.92 }); // , background:'#FC0'
	//	$(".item.c_about .container_bg").css({ opacity:0.92, background:'#C03' });

		$(".item.c_about .container_bg").css({ background:'transparent !important' }); // , background:'#06C'
		$(".item.twitter .container_bg").css({ opacity:'0 !important' }); // , background:'#06C'
		$(".item.twitter .container .brood").css({ opacity:0.92, background:'#06C' }); // , background:'#06C'

	//dep	$(".detailpage.artists .related_press .container_bg").css({ opacity:0.92 }); // , background:'#FC0'
		$(".detailpage.artists .related_press .press_container").css({ position:'absolute', top:154 }); // not depricated, check this for taming press_container

	//	$(".square86.pagination").css({ opacity:0.92, background:'#FFF' });

	//dep	$(".item .container").css({ position:'absolute', top:154 }); // 139
		// $(".item:not(.home_quad, .count_p, .twitter, .c_media, .article_item, .c_about)").hover(function() { // not not .sub_records .c_recordstore for a nice bounce
		$(".item:not(.home_quad, .count_p, .twitter, .c_media.count_m, .article_item, .c_about)").hover(function() { // media only .count_m not
			$(this).find(".container").clearQueue();
			$(this).find(".container").animate({ top:86 }, 200);
		}, function() {
			$(this).find(".container").animate({ top:154 }, 200);
		});
	//dep	$(".item.home_quad:not(.c_recordstore, .c_records, .c_merchandisestore) .container").css({ position:'absolute', top:342 }); // 327
		$(".item.home_quad:not(.c_recordstore, .c_records, .c_merchandisestore)").hover(function() {
			$(this).find(".container").clearQueue();
			$(this).find(".container").animate({ top:274 }, 200);
		}, function() {
			$(this).find(".container").animate({ top:342 }, 200);
		});
		$(".home_quad.c_recordstore .container, .item.home_quad.c_records .container, .item.home_quad.c_merchandisestore .container").css({ position:'absolute', top:322 }); // 322
		$(".home_quad.c_recordstore .container, .item.home_quad.c_records .container, .item.home_quad.c_merchandisestore .container").hover(function() {
			$(this).find(".container").clearQueue();
			$(this).find(".container").animate({ top:274 }, 200);
		}, function() {
			$(this).find(".container").animate({ top:322 }, 200);
		});
	//dep	$(".item.count_m .container").css({ position:'absolute', top:0 });
		// $(".item.sub_records .container, .item.c_recordstore .container, .item.c_media:not(.count_m) .container").css({ position:'absolute', top:139 }); // 120
	//dep	$(".item.sub_records:not(.home_quad) .container, .item.c_recordstore:not(.home_quad) .container, .item.c_merchandisestore:not(.home_quad) .container").css({ position:'absolute', top:139 }); // media not anymore
		$(".item.sub_records:not(.article_item, .home_quad), .item.c_recordstore:not(.article_item, .home_quad), .item.c_merchandisestore:not(.article_item, .home_quad)").hover(function() {
			$(this).find(".container").clearQueue();
			$(this).find(".container").animate({ top:86 }, 200);
		}, function() {
			$(this).find(".container").animate({ top:139 }, 200);
		});
		// $(".item:not(.count_0, .twitter, .c_media) .brood, .item.count_m .brood").css({ cursor:'pointer' }); // was .homepage
		$(".item:not(.count_0, .twitter) .brood, .item.count_m .brood, .related_press .brood").css({ cursor:'pointer' }); // was .homepage
		$(".item .container .brood, .item.count_m .brood").click(function() {
		//	alert('ja 1');
			$(this).parent().find("h1 a").each(function(i) {
		//		alert('ja 5');
		//		$(this).html($(this).attr('href'));
				window.location.href = $(this).attr('href');
				return true;
		//		$(this).trigger('click');
		//		$(this).html('clicked');
			});
		});
		$(".item.count_m .brood").hover(function() {
			$(this).find('a').addClass('hover');
		}, function() {
			$(this).find('a').removeClass('hover');
		});

	}


	// Animate the link
	function animateLinks() {
		$("#bottom .copyright ").css({ opacity: 0.4 });
	//	$("#content .homepage .bg div").css({ opacity: 0 });

		// remove double related
		var aRelated = new Array();
		$(".artists_related_records .related86 a").each(function() {
			if (aRelated.indexOf($(this).attr('class'))==-1) {
				aRelated[aRelated.length] = $(this).attr('class');
			} else {
				$(this).parent().remove();
			//	alert($(this).attr('class') + ' removed');
			}
		});

		// artists twitter box from selector to article
		//$(".article .article_twitter").html($(".item.twitter .article_twitter").html());
		//$(".article .article_twitter").append($(".item.twitter .container").html());
		//$(".detailpage .item.twitter").hide();

		$(".article .storebuttons .add_to_cart_off").text(function() { // switched off
			return ($(this).text()=='add')?'add to cart':$(this).text();
		});

	}


	// do Gallery
	function doGallery() {
		$('.detailpage .gallery .images a, .detailpage .gallery .view_gallery a').attr('target','_self');
	//	$("#bottom .edit").append(' '+ $(".detailpage .gallery li.images:first a").attr('href'));
		$(".detailpage .gallery .view_gallery a").attr('href', $(".detailpage .gallery li.images:first a").attr('href'));
		if (typeof aGallery!='undefined')
			$('.detailpage .gallery .view_gallery .n').text((aGallery.length-1)/2);

		// open gallery
		$(".detailpage .gallery .images a, .detailpage .gallery .view_gallery a").click(function() {
		//	if ($('#gallery').length==0) {
		//		$('#main').after(function() { // after append
		//			return '<div id="gallery">&nbsp;</div>';
		//		});
		//	}

			$('#main').fadeTo(200, 0.7, function() {
			//	$('#gallery_container').show();
			//	$('#gallery_bg').fadeTo(400, 0.7, function() {
			//	});
			//	$('.player').hide();
				$('.player').css('visibility', 'hidden');
				$('#gallery_bg').css({ opacity:0.8, background:'#000' });
				$('#gallery_container').fadeIn(400);
				$('#gallery_escape').text("esc = exit");
			});
			for (var i=0; i<=aGallery.length-2; i+=2) {
				$("#bottom .edit").append(' '+i);
				if (aGallery[i]==$(this).attr('href') )
					break;
			}
			if (i>=aGallery.length-1)
				i=0;
			if ($('#gallery > a').size()==0) {
				$('#gallery').append('<a href="'+aGallery[i+2]+'"><img src="/images/phpthumb/resize.php?param=0800_0500_000_000_080_'+aGallery[i]+'" alt="'+aGallery[i+1]+'" title="'+aGallery[i+1]+'" /></a>');
				$('#gallery_buttons').append('<a href="'+aGallery[(i==0?aGallery.length-3:i-2)]+'" class="prev">&lt;</a> &nbsp;<span class="gallery_pagination">'+(i+1)+' / '+ ((aGallery.length-1)/2) +'</span>&nbsp; <a href="'+aGallery[i+2]+'" class="next">&gt;</a>');
			}

			$('#gallery_container a').bind('click', function() {
				for (var i=0; i<=aGallery.length-2; i+=2) {
					if (aGallery[i]==$(this).attr('href') )
						break;
				}
				if (i>=aGallery.length-1)
					i=0;
				$('#gallery img').attr('src', '/images/phpthumb/resize.php?param=0800_0500_000_000_080_'+aGallery[i]);
				$('#gallery img').attr('alt', aGallery[i+1]);
				$('#gallery img').attr('title', aGallery[i+1]);
				$('#gallery a').attr('href', aGallery[i+2]);
				$('#gallery_buttons .prev').attr('href', aGallery[(i==0?aGallery.length-3:i-2)]);
				$('#gallery_buttons .next').attr('href', aGallery[i+2]);
				$('#gallery_buttons .gallery_pagination').html( (i/2+1) +' / '+ ((aGallery.length-1)/2) );

				$('#gallery_preload').html( $('<img />').attr('src', '/images/phpthumb/resize.php?param=0800_0500_000_000_080_'+aGallery[i]) );

				return false;
			});

			var KEYCODE_ENTER = 13; // 
			var KEYCODE_ESC = 27;
			var KEYCODE_SPACE = 32;

			$(document).keyup(function(e) {
				//if (e.keyCode==KEYCODE_SPACE) { $('#gallery_container a').click(); } 
				if (e.keyCode==KEYCODE_ESC) { $('#gallery_container').click(); } 
			});

			// close gallery
			$('#gallery_container').click(function() {
				$('#main').fadeTo(200, 1, function() {
				//	$('#gallery_container').show();
				//	$('#gallery_bg').fadeTo(400, 0.7, function() {
				//	});
					$('#gallery_bg').css({ opacity:0, background:'#000' });
					$('#gallery_container').fadeOut(400);
					$('#gallery_buttons').empty();
					$('#gallery').empty();
				//	$('.player').show();
					$('.player').css('visibility', 'visible');
				});
			});

			return false;
		});

	}


	// Convert anchors linking to external sites into target blank
	// convert anchors of links tot specific content into target blank
	function anchorsExternBlank() {
		$('.form_blank form').attr('target','_blank');
		$('td.trackname a, td.trackplayback a').attr('target','_blank');

		var sDomains = 'dog.alshetgaatom.com,dopenessgalore.com,www.dopenessgalore.com,dopenessgalore.nl,www.dopenessgalore.nl';
		sDomains = sDomains.toLowerCase();
		var aDomains = sDomains.split(',');

		$('a').attr('target', function(i, val) {
			if (val=="_self")
				return val;
			if (aDomains.indexOf(this.hostname.toLowerCase())==-1)
				return '_blank';
			if (this.target)
				return this.target;
			if (this.href.toLowerCase().indexOf(".doc") != -1)
				return '_blank';
			if (this.href.toLowerCase().indexOf(".jpg") != -1)
				return '_blank';
			if (false && this.href.toLowerCase().indexOf(".mp3") != -1)
				return '_blank';
			if (this.href.toLowerCase().indexOf(".pdf") != -1)
				return '_blank';
			return '';
		});

	}


	function dojScrollPane() {
	//	var aItems = $('.homepage #content .item');
	//	aItems.each(function(i, obj) {
	//		if (i < arr.length - 4 - 1)
	//			continue;
	//
	//	});
	////	$('.detailpage #content').jScrollPane({showArrows: true});
		$('#main:not(.press, .feedback) #content').jScrollPane();

		$(".jspTrack").before('<div class="jspTrackBackground"></div>');
		$(".jspTrackBackground").css({ opacity:0.1, background:'#FFF' });

		$(".jspDrag").css({ opacity:0.8 }); //, background:'#FFF' });

	}


	function doCart() {

	//	alert('cart ['+ $.cookie('exp_dog_cart') +']');

		$("#basket .bar").css({ cursor:'pointer' });
		$("#basket .bar").click(function() {
			window.location.href = "/shoppingcart";
		});

		// show_item
		//$(".storebuttons .show_item").click(function() {
		//});

		// add_reload, add to cart and return to item
		$(".storebuttons .add_reload").click(function() {
			var aTemp = $(this).parent().parent().attr('id').split('_'); // get entry id entry_[id]
			var sCart = $.cookie('exp_dog_cart');
			sCart = (sCart==null)?'0x0':sCart; // init dataset or use existing cookie data
			sCart += '_'+aTemp[1]+'x1'; // item x quantity (+1)
			$.cookie('exp_dog_cart', sCart, { expires: 7, path: '/', domain: '.dopenessgalore.com', secure: false }); // set cookie
			window.location.href = $(this).attr('href').replace("/add_to_cart","");
			return false;
		});

		// add_store, add to cart and go to store index
		$(".storebuttons .add_store").click(function() {
			var aTemp = $(this).parent().parent().attr('id').split('_'); // get entry id entry_[id]
			var sCart = $.cookie('exp_dog_cart');
			sCart = (sCart==null)?'0x0':sCart; // init dataset or use existing cookie data
			sCart += '_'+aTemp[1]+'x1'; // item x quantity (+1)
			$.cookie('exp_dog_cart', sCart, { expires: 7, path: '/', domain: '.dopenessgalore.com', secure: false }); // set cookie
			window.location.href = "/store/";
			return false;
		});

		// add_record, add to cart and go to recordstore index
		$(".storebuttons .add_record").click(function() {
			var aTemp = $(this).parent().parent().attr('id').split('_'); // get entry id entry_[id]
			var sCart = $.cookie('exp_dog_cart');
			sCart = (sCart==null)?'0x0':sCart; // init dataset or use existing cookie data
			sCart += '_'+aTemp[1]+'x1'; // item x quantity (+1)
			$.cookie('exp_dog_cart', sCart, { expires: 7, path: '/', domain: '.dopenessgalore.com', secure: false }); // set cookie
			window.location.href = "/recordstore/";
			return false;
		});

		// add_merchand, add to cart and go to merchandisestore index
		$(".storebuttons .add_merchand").click(function() {
			var aTemp = $(this).parent().parent().attr('id').split('_'); // get entry id entry_[id]
			var sCart = $.cookie('exp_dog_cart');
			sCart = (sCart==null)?'0x0':sCart; // init dataset or use existing cookie data
			sCart += '_'+aTemp[1]+'x1'; // item x quantity (+1)
			$.cookie('exp_dog_cart', sCart, { expires: 7, path: '/', domain: '.dopenessgalore.com', secure: false }); // set cookie
			window.location.href = "/merchandisestore/";
			return false;
		});

		// add_cart, add to cart and go to shoppingcart
		$(".storebuttons .add_cart").click(function() {
			var aTemp = $(this).parent().parent().attr('id').split('_'); // get entry id entry_[id]
			var sCart = $.cookie('exp_dog_cart');
			sCart = (sCart==null)?'0x0':sCart; // init dataset or use existing cookie data
			sCart += '_'+aTemp[1]+'x1'; // item x quantity (+1)
			$.cookie('exp_dog_cart', sCart, { expires: 7, path: '/', domain: '.dopenessgalore.com', secure: false }); // set cookie
			window.location.href = "/shoppingcart/";
			return false;
		});

		$('.article .shoppingcart a.add_to_cart').click(function() {
			var aTemp = $(this).parent().parent().attr('id').split('_'); // get entry id entry_[id]
			var sCart = $.cookie('exp_dog_cart');
			sCart = (sCart==null)?'0x0':sCart; // init dataset or use existing cookie data
			sCart += '_'+aTemp[1]+'x1'; // item x quantity (+1)
			$.cookie('exp_dog_cart', sCart, { expires: 7, path: '/', domain: '.dopenessgalore.com', secure: false }); // set cookie
		//	alert('add ['+ $.cookie('exp_dog_cart') +']');
		//	window.location.href = $(this).attr('href').replace("/add_to_cart","");
		//	location.reload();
			window.location.href = "/shoppingcart/";
			return false;
		});
		$('.article .shoppingcart a.rem_from_cart').click(function() {
			var aTemp = $(this).parent().parent().attr('id').split('_'); // get entry id entry_[id]
			var sCart = $.cookie('exp_dog_cart');
			sCart = (sCart==null)?'0x1':sCart; // init dataset or use existing cookie data
			sCart += '_'+aTemp[1]+'x0'; // item x quantity (-1)
			$.cookie('exp_dog_cart', sCart, { expires: 7, path: '/', domain: '.dopenessgalore.com', secure: false }); // set cookie
		//	location.reload();
			window.location.href = "/shoppingcart/";
			return false;
		});

	}


	function sponsorBackground() {
		$("#sponsor .bar.small a").click(function() {
			$(this).parent().removeClass("small");
			$(this).parent().addClass("large");
			$(this).unbind('click'); // next click will execute a href
			// fade out content, make background viewable
			$("#content .item, #content .article_box, #content .jspVerticalBar, #basket").fadeOut("slow");

			$("#sponsor .bar.large a, #main").click(function() {
				$(this).parent().removeClass("large");
				$(this).parent().addClass("small");
				$(this).unbind('click'); // next click will execute a href
				//alert("nu een fade out");
				// fade content back in
				$("#content .item, #content .article_box, #content .jspVerticalBar, #basket").fadeIn("slow");

				return true; // execute click event a href
			});

			return false; // do not prolongate click event
		});
	}


	// scale_background
	function scale_background() {

		$(window).resize(function() {
		//	alert( $(document).width() +' x '+ $(document).height() );

			for (var i = 0; i < aBGclass.length; i++) {
				if ( $(document).width()<=aBGwidth[i] && $(document).height()<=aBGheight[i] || i >= aBGclass.length-1 ) {
					$('body').removeClass(aBGclass.join(' ')).addClass(aBGclass[i]);

					$(".jspDrag").css({ opacity:0.8 }); //, background:'#FFF' });

					// admin buttons
					$('#bottom .edit .aBGclass').removeClass('active').addClass(function() {
						if ($(this).attr('text')==aBGclass[i])
							return 'active';
					});

					break;
				}
			}
		});
		$(window).resize(); // trigger

	}


	// Correct Twitter
	function correctTwitter(prevInterval) {
		$(".tweets .tweetzzLI").each(function(i) {
			if (i>=3)
				$(this).hide();
		});
		$("#bottom .edit").append(' ,');
		setTimeout("correctTwitter("+Math.floor(prevInterval*1.5)+");", prevInterval*1.5);
	}


	// Handle mailing_form, validate and send
	function handle_mailing_form() {
		$(".mailingbox form .email").focus(function() {
			if (this.value=="your email")
				this.value="";
		//	if (typeof this.done=="undefined") {
		//		this.done=true;
		//		this.value="";
		//	}
		});
		$("input.ie7fix").attr('value', ''); // IE7 does not do text-indent on input element
		$("a.ie7fix").text(''); // so whatever
		$(".mailingbox form .join").hover(function() {
			$(this).addClass('red');
		}, function() {
			$(this).removeClass('red');
		});

	}


	// Handle feedback_form, validate and send
	function handle_feedback_form() {
		$(".feedback #comment_form").submit(function() {
			var aValidate = new Array();
			var aMandatory = new Array('name','email','comment');
			var sPrevName = '';
			var sData = '';

			$(".feedback #comment_form [name='message']").attr("value", "");
			$(".feedback #comment_form input, .feedback #comment_form select").each(function() {
				$(".feedback #comment_form label[for='"+$(this).attr("name")+"']").css('color','');
			});

			$(".feedback #comment_form input, .feedback #comment_form select, .feedback #comment_form textarea").each(function() {
			//	alert('a1 '+$(this).get(0).tagName);
			//	alert('a4 ['+$(this).attr("name")+']');

				if (sPrevName==$(this).attr("name"))
					return; // naam al gehad
				sPrevName = $(this).attr("name");

				if (aMandatory.indexOf($(this).attr("name"))==-1)
					return; // niet valideren

			//	alert('a3 '+$(this).attr("name"));

				if ($(".feedback #comment_form [name='"+$(this).attr("name")+"']").attr("type")=="radio") {
					if ($(".feedback #comment_form [name='"+$(this).attr("name")+"']:checked").val()==undefined) {
					//	alert('radio="undefined"');
						aValidate[aValidate.length] = $(this).attr("name");
						$(".feedback #comment_form label[for='"+$(this).attr("name")+"']").css('color','red');
					}
				} else if ($(".feedback #comment_form [name='"+$(this).attr("name")+"']").val()=="") {
				//	alert('empty');
					aValidate[aValidate.length] = $(this).attr("name");
					$(".feedback #comment_form label[for='"+$(this).attr("name")+"']").css('color','red');
				} else {
					// ok
				}

			});

		//	alert( "message="+ $("#contact_form [name='message']").val() );

			if (aValidate.length>0) {
				alert("Please fill in the required fields");
				return false;
			//} elseif (aValidate.length==1) {
			//	alert("Please fill in the required field");
			//	return false;
			}

			return true;
		});

		$(".feedback #comment_form input.submit").hover(function() {
			$(this).addClass('red');
		}, function() {
			$(this).removeClass('red');
		});
		$(".feedback a.hide_download").click(function() {
			return false;
		});

	}


	// Handle shopping_form, validate and send
	function handle_shopping_form() {
		$(".shoppingcart #country_select").change(function() {
			// set cookie on country change
			var sCountry = $(this).find("option:selected").val(); // +'_'+ $(this).find("option:selected").text();
			$.cookie('exp_dog_country', sCountry, { expires: 30, path: '/', domain: '.dopenessgalore.com', secure: false }); // set cookie
			location.reload();
		//	window.location.href = "/shoppingcart/";
			return true;
		});

		$(".shoppingcart #insured").change(function() {
			// set cookie on country change
			var sInsured = $(this).find("option:selected").val();
			$.cookie('exp_dog_insured', sInsured, { expires: 30, path: '/', domain: '.dopenessgalore.com', secure: false }); // set cookie
		//	location.reload();
			window.location.href = "/shoppingcart/";
			return true;
		});

		$('.shoppingcart .cart_empty').click(function() {
			if (confirm("Do you really want to empty the cart?")) {
				$.cookie('exp_dog_cart', null, { path: '/', domain: '.dopenessgalore.com' }); // clear cookie
			//	location.reload();
				window.location.href = "/shoppingcart/";
			}
			return false;
		});

		$('.shoppingcart .cart_edit').click(function() {
			history.back(1);
			return false;
		});

		$('.shoppingcart .cart_okay').click(function() {
			$.cookie('exp_dog_cart', null, { path: '/', domain: '.dopenessgalore.com' }); // clear cookie
		});

		$(".shoppingcart .cart_checkout").hover(function() {
			$(this).addClass('hover');
		}, function() {
			$(this).removeClass('hover');
		});

		//$('.shoppingcart #cart_checkout').click(function() {
		//	window.open('http://www.technischcreatief.nl','_blank');
		//	return false;
		//});

		$('#cart_paypal, #cart_banktransfer').click(function() {
			$("#paymentmethode").val($(this).attr('id'));
			return true;
		});

		$(".shoppingcart.thanks").each(function() {
			$.cookie('exp_dog_cart', null, { path: '/', domain: '.dopenessgalore.com' }); // clear cookie
			$("#basket").hide();
		});

		$(".shoppingcart #cart_form").submit(function() {
		//	alert('Yo 1');

			var aValidate = new Array();
			var aMandatory = $("#validate").val().split(',');
			var aFields = $("#fields").val().split(',');
			var sPrevName = '';
			var sData = '';

			$("#cart_form [name='message']").attr("value", "");

			$("#cart_form input, #cart_form select").each(function() {
				$("#cart_form label[for='"+$(this).attr("name")+"']").css('color','');
			});

			$("#cart_form input, #cart_form select").each(function() {
			//	alert('a1 '+$(this).get(0).tagName);
			//	alert('a4 ['+$(this).attr("name")+']');

				if (sPrevName==$(this).attr("name"))
					return; // naam al gehad
				sPrevName = $(this).attr("name");

				if (aFields.indexOf($(this).attr("name"))!=-1) {
					if ($("#cart_form [name='"+$(this).attr("name")+"']").attr("type")=="radio")
						sData = $("#cart_form [name='"+$(this).attr("name")+"']:checked").val();
					else
						sData = $("#cart_form [name='"+$(this).attr("name")+"']").val();
				///	$("#cart_form [name='message']").val( $("#cart_form [name='message']").val() + $(this).attr("name") + ":\n"+ sData +"\n\n" );
				}

				if (aMandatory.indexOf($(this).attr("name"))==-1)
					return; // niet valideren

			//	alert('a3 '+$(this).attr("name"));

				if ($("#cart_form [name='"+$(this).attr("name")+"']").attr("type")=="radio") {
					if ($("#cart_form [name='"+$(this).attr("name")+"']:checked").val()==undefined) {
					//	alert('radio="undefined"');
						aValidate[aValidate.length] = $(this).attr("name");
						$("#cart_form label[for='"+$(this).attr("name")+"']").css('color','red');
					}
				} else if ($("#cart_form [name='"+$(this).attr("name")+"']").val()=="") {
				//	alert('empty');
					aValidate[aValidate.length] = $(this).attr("name");
					$("#cart_form label[for='"+$(this).attr("name")+"']").css('color','red');
				} else {
					// ok
				}

			});

		//	alert( "message="+ $("#cart_form [name='message']").val() );

			if (aValidate.length>0) {
				alert("Please fill in the required fields"); //"aValidate "+aValidate.join(' '));
				return false;
			}

			return true;
		});

		$(".shoppingcart #checkout_form").submit(function() {
		//	alert('Yo 1');

			var aValidate = new Array();
			var aMandatory = $("#validate").val().split(',');
			var aFields = $("#fields").val().split(',');
			var sPrevName = '';
			var sData = '';

			//$("#checkout_form [name='message']").attr("value", "");
			$("#checkout_form input, #checkout_form select").each(function() {
				$("#checkout_form label[for='"+$(this).attr("name")+"']").css('color','');
			});

			$("#checkout_form input, #checkout_form select").each(function() {
			//	alert('a1 '+$(this).get(0).tagName);
			//	alert('a4 ['+$(this).attr("name")+']');

				if (sPrevName==$(this).attr("name"))
					return; // naam al gehad
				sPrevName = $(this).attr("name");

				if (aFields.indexOf($(this).attr("name"))!=-1) {
					if ($("#checkout_form [name='"+$(this).attr("name")+"']").attr("type")=="radio")
						sData = $("#checkout_form [name='"+$(this).attr("name")+"']:checked").val();
					else
						sData = $("#checkout_form [name='"+$(this).attr("name")+"']").val();
					$("#checkout_form [name='message']").val( $("#checkout_form [name='message']").val() + $(this).attr("name") + ":\n"+ sData +"\n\n" );
				}

				if (aMandatory.indexOf($(this).attr("name"))==-1)
					return; // niet valideren

			//	alert('a3 '+$(this).attr("name"));

				if ($("#checkout_form [name='"+$(this).attr("name")+"']").attr("type")=="radio") {
					if ($("#checkout_form [name='"+$(this).attr("name")+"']:checked").val()==undefined) {
					//	alert('radio="undefined"');
						aValidate[aValidate.length] = $(this).attr("name");
						$("#checkout_form label[for='"+$(this).attr("name")+"']").css('color','red');
					}
				} else if ($("#checkout_form [name='"+$(this).attr("name")+"']").val()=="") {
				//	alert('empty');
					aValidate[aValidate.length] = $(this).attr("name");
					$("#checkout_form label[for='"+$(this).attr("name")+"']").css('color','red');
				} else {
					// ok
				}

			});

			//alert( "message 3 = "+ $("#checkout_form [name='message']").val() );

			if (aValidate.length>0) {
				alert("Please fill in the required fields"); //"aValidate "+aValidate.join(' '));
				return false;
			}

			return true;
		});

	}


	// Handle contact_form, validate and send
	function handle_contact_form() {
		$("#contact_form").submit(function() {
		//	alert('Yo 1');

			var aValidate = new Array();
			var aMandatory = $("#validate").val().split(',');
			var aFields = $("#fields").val().split(',');
			var sPrevName = '';
			var sData = '';

			$("#contact_form [name='message']").attr("value", "");
			$("#contact_form input, #contact_form select").each(function() {
				$("#contact_form label[for='"+$(this).attr("name")+"']").css('color','');
			});

			$("#contact_form input, #contact_form select").each(function() {
			//	alert('a1 '+$(this).get(0).tagName);
			//	alert('a4 ['+$(this).attr("name")+']');

				if (sPrevName==$(this).attr("name"))
					return; // naam al gehad
				sPrevName = $(this).attr("name");

				if (aFields.indexOf($(this).attr("name"))!=-1) {
					if ($("#contact_form [name='"+$(this).attr("name")+"']").attr("type")=="radio")
						sData = $("#contact_form [name='"+$(this).attr("name")+"']:checked").val();
					else
						sData = $("#contact_form [name='"+$(this).attr("name")+"']").val();
					$("#contact_form [name='message']").val( $("#contact_form [name='message']").val() + $(this).attr("name") + ":\n"+ sData +"\n\n" );
				}

				if (aMandatory.indexOf($(this).attr("name"))==-1)
					return; // niet valideren

			//	alert('a3 '+$(this).attr("name"));

				if ($("#contact_form [name='"+$(this).attr("name")+"']").attr("type")=="radio") {
					if ($("#contact_form [name='"+$(this).attr("name")+"']:checked").val()==undefined) {
					//	alert('radio="undefined"');
						aValidate[aValidate.length] = $(this).attr("name");
						$("#contact_form label[for='"+$(this).attr("name")+"']").css('color','red');
					}
				} else if ($("#contact_form [name='"+$(this).attr("name")+"']").val()=="") {
				//	alert('empty');
					aValidate[aValidate.length] = $(this).attr("name");
					$("#contact_form label[for='"+$(this).attr("name")+"']").css('color','red');
				} else {
					// ok
				}

			});

		//	alert( "message="+ $("#contact_form [name='message']").val() );

			if (aValidate.length>0) {
				alert("Please fill in the required fields"); //"aValidate "+aValidate.join(' '));
				return false;
			}

			return true;
		});

	}


	// Handle excel table, render cells
	function handle_excel_table() {
		$("div.excel").each(function(i) {
			var sData = $(this).html();
			var rTab = /\t/ig;
			sData = sData.replace(rTab,"</td><td>");
			var rNew = /\n/ig;
			sData = sData.replace(rNew,"</td></tr><tr><td>");
			$(this).html("<table>\n<tr>\n\t<td>"+ sData +"</td>\n</tr>\n</table>");
		//	$(this).html('jaja5');
		});

	}


	// link_to_sub()
	function link_to_sub() {

		var aText = new Array();
		var aLink = new Array();

		var sArtists = '{exp:channel:categories channel="artists" category_group="1" status="{statuses}" style="linear" disable="category_fields" show_empty="yes" backspace="1"}{category_name},{category_url_title},{/exp:channel:categories}';
		sArtists = sArtists.toLowerCase();
		var aArtists = sArtists.split(',');

		for (var i = 0; i < aArtists.length; i++) {
			if (i%2==0)
				aText[aText.length] = aArtists[i];
			if (i%2==1)
				aLink[aLink.length] = aArtists[i];
		}

		// alert(aText.join(' | ') + ' ||| ' + aLink.join(' | '));

		// return;

		$(".article .container p, .article .container li").each(function() {
			// replace artist name by link

			var sContent = this.innerHTML.toLowerCase();
/*
			var bContinue = true;
			// check for manual overwrite
			$(this).find("a").attr('href', function(href) {
				if (aLink.indexOf(href.toLowerCase())==-1)
					bContinue = false;
				return false;
			});

			if (bContinue==true)
				return false;
*/
			for (var i = 0; i < aText.length; i++) {
				var iStart = sContent.indexOf(aText[i]);
				if (iStart==-1) {
				} else {
					alert('yes 3 '+ aText[i] +' = '+ iStart +'~'+ aText[i].length);
				}
			}

			return true;

/*
			var aMatch = new Array();
			for (var i = 0; i < aText.length; i++) {
				aMatch = sContent.match(aText[i]);
				if (aMatch==-1) {
					alert('no 4');
				} else {
					alert('yes 4 ' + aText[i]);
				}
			}

			return true;

/*

			var bContinue = true;
			// check for manual overwrite
			$(this).find("a").attr('href', function(href) {
				if (aArtists.indexOf(href.toLowerCase())==-1)
					bContinue = false;
				return false;
			});

			if (bContinue==true)
				return false;

			$(this).val(sContent.replace(aArtists));

			//	if (aArtists.indexOf(sVal.toLowerCase())==-1) {
			//		// no replacement
			//	} else {
			//		$(this).val(sVal.replace(aArtists));
			//	}
			}
*/
			alert('ok 1');
		});

	}


	// hide_write
	function hide_write() {
		for (var sKey in aStack) {
			alert(sKey);
		//	$("#"+sKey).after(aStack[sKey]);
		}

	}


	// Egg Basket
	function egg_basket() {
		var iEgg0 = new Array(0);
		$("#header .logo a").hover(function() {
			iEgg0[0]++;
			if (iEgg0[0]>8) {
				$(this).removeClass('red');
				$(this).unbind('mouseenter mouseleave');
			} else if (iEgg0[0]>4) {
			//	alert('RED2');
				$(this).addClass('red');
			//	$(this).delay(100).removeClass('red');
			}
		//	alert('red1');
		});
/*
		// april fools names
		var aNames = new Array('Kid Sublime','Dik Sublime','olddd','newww');
		var aFind = new Array();
		var aReplace = new Array();
		for (var i = 0; i < aNames.length; i++) {
			if (i%2==0)
				aFind[aFind.length] = aNames[i];
			if (i%2==1)
				aReplace[aReplace.length] = aNames[i];
		}

		$("h1").val(function(i, str) {
			for (var i = 0; i < aFind.length; i++)
				str = str.replace(new RegExp(aFind[I], 'g'), aReplace[i]);
			return str;
		});
*/
	}

	egg_basket();


	// admin_buttons
	function admin_buttons() {

		$("#content .edit").css({ opacity: 0 });
	/*	$("#monitor").click(function() {
			$(".item").mouseenter(); // trigger
			$("#content .edit").fadeTo(500,1.0);
			$(".item .brood").css({ cursor:'default' }); // was .homepage
			$(".item .container .brood").unbind('click');
			$(".item").unbind('mouseleave'); // was .homepage
			return false;
		}); */
		$("#monitor").click(function() {
			$("#content .edit").fadeTo(500,1.0);
			$(".item .container .brood").unbind('click');
			$(".item").unbind('mouseleave'); // was .homepage
			$(".item").trigger('mouseenter'); // was .homepage
			$(".item .brood").css({ cursor:'default' }); // was .homepage
			return false;
		});

		$("#bottom .edit").css({ opacity: 0 });
		$("#bottom .edit").hover(function() {
			$(this).clearQueue();
			$(this).fadeTo(500,1.0);
			$(this).css({ background:'#FFF' });
		}, function() {
			$(this).fadeTo(500,0.4);
		});

		$("#bottom .edit").append('<a class="aBGclass" href="#">'+ aBGclass.join('</a> <a class="aBGclass" href="#">') +'</a>');

		$("#bottom .edit a.aBGclass").click(function () {
			$('body').removeClass(function () { return aBGclass.join(' ') });
			$('body').addClass($(this).text());
			$('#bottom .edit .aBGclass').removeClass('active');
			var sClass = $(this).text();
			$('#bottom .edit .aBGclass').addClass(function() {
				if ($(this).attr('text')==sClass)
					return 'active';
			});
			return false;
		});

	}


//	alert('End of jQuery');
});

// End of jQuery




// Start EQ article height to item height
function eqHeight(prevInterval) {
	$(".article").each(function() {

		$('.article .height548').remove();
		if ($(this).height()<'548')
			$(this).height(548);

		var iMod = ($(this).height()+15)%(188);
	//	$("#bottom .edit").append(' '+iMod);
		iMod = (iMod<188)?(iMod>0)?188-iMod:0:0;
	//	$("#bottom .edit").append('_'+iMod);
		if (iMod>0)
			$(this).height($(this).height()+iMod);
	});
	setTimeout("eqHeight("+Math.floor(prevInterval*1.5)+");", prevInterval*1.5);

}
// End of EQ




// Start Player for mp3
function playerMp3(prevInterval) {
	if (prevInterval>=20000)
		return;

	// hide buttons without url
	//$('.tracklist .trackplayback a').each(function() {
	//	var sHref = $(this).attr('href');
	//	sHref get rid of [\r\n|\n]?
	//});
	$('.tracklist .trackplayback a[href=]').each(function() {
		$(this).hide();
	});

	var bPlayerOnline = false;

	// at first run
	if (prevInterval<=100) {
		$('td.trackname a, td.trackplayback a').attr('target', '_blank'); // make compatible with non Flash devices

		var sFirstMp3 = $('.tracklist .trackplayback a:first').attr('href');
		$('.tracklist .player').append('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="300" height="37" id="niftyPlayer1" align=""><param name="movie" value="/player/niftyplayer/dogplayer.swf?file=' + sFirstMp3 + '&as=0"><param name="quality" value="high"><param name="wmode" value="transparent"><embed src="/player/niftyplayer/dogplayer.swf?file=' + sFirstMp3 + '&as=0" quality="high" wmode="transparent" width="300" height="37" name="niftyPlayer1" align="" type="application/x-shockwave-flash" swLiveConnect="true" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed></object>');
	}

	// check for flash
	try {
		if (niftyplayer('niftyPlayer1').getState()=='empty')
			bPlayerOnline = true;
	} catch(err) {
	}

	// continue to try
	if (bPlayerOnline==false)
		setTimeout("playerMp3("+Math.floor(prevInterval*1.5)+");", prevInterval*1.5);

	if (bPlayerOnline==true) {
		// play-stop button add class for css styling
		$('.tracklist .trackplayback a').addClass('play');

		// trigger button by trackname
		$('.tracklist .trackname a').click(function() {
		//	var sMp3 = $(this).attr('href');
		//	alert('clicktrack 2'+ sMp3);
		//	$('.tracklist .trackplayback a[href='+sMp3+']').trigger('click');
			$(this).parent().siblings().find('a').trigger('click');
			return false;
		});

		// Click action
		$('.tracklist .trackplayback a').click(function() {

			var sCommand = $(this).text();
			var sMp3 = $(this).attr('href');

			if (sCommand=='Stop')
				niftyplayer('niftyPlayer1').stop(); // set button

			setTimeout('checkPlaying("'+sMp3+'");', 250);
		//	alert('ja3 '+sMp3);

			// clear stop button, set to play
			$('.tracklist .trackplayback a').text('Play').removeClass('stop').addClass('play'); // reset buttons

			if (sCommand=='Play') {
				niftyplayer('niftyPlayer1').loadAndPlay(sMp3);
				$(this).text('Stop').removeClass('play').addClass('stop');
			}

			return false; // always
		});
	}

	$("#bottom .edit").append(' +'+prevInterval);

}


function checkPlaying(sMp3) {
	//	alert('ja4 '+sMp3);

	var sCommand = niftyplayer('niftyPlayer1').getState();
	var whatIsPlaying = niftyplayer('niftyPlayer1').whatIsPlaying();

	$("#bottom .edit").append(' .');
	if (whatIsPlaying!=sMp3)
		return; // bailout
	if (sCommand=='stopped' || sCommand=='finished') {
		$('.tracklist .trackplayback a').text('Play').removeClass('stop').addClass('play'); // reset buttons
	} else {
		setTimeout('checkPlaying("'+sMp3+'");', 250);
	}
	return;

}
// End of Player for mp3


/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */

/**
 * Create a cookie with the given name and value and other optional parameters.
 *
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Set the value of a cookie.
 * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
 * @desc Create a cookie with all available options.
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Create a session cookie.
 * @example $.cookie('the_cookie', null);
 * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
 *       used when the cookie was set.
 *
 * @param String name The name of the cookie.
 * @param String value The value of the cookie.
 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
 *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
 *                             If set to null or omitted, the cookie will be a session cookie and will not be retained
 *                             when the the browser exits.
 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
 *                        require a secure protocol (like HTTPS).
 * @type undefined
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */

/**
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

