$(document).ready(function () {

	$("section.picknmix h3").click(function () {
		if ($(this).hasClass("selected")) {
			$(this).removeClass("selected");
			$(this).next("div.slider").slideUp(function() {
				$(this).parent().parent().find("article").removeClass("open");
			});
		} else {
			$(this).parent().parent().find('h3').removeClass("selected");
			$(this).parent().parent().find("article").removeClass("open");
			$(this).parent().parent().find("div.slider").slideUp();
			$(this).addClass("selected");
			$(this).next("div.slider").slideDown(function() {
				$(this).parent().addClass("open");
			});

		}
	});

	// PrettyPhoto
	//$("a[rel^='window']").prettyPhoto();
	$("a[rel^='prettyPhoto']").prettyPhoto();

	$('.cycle').cycle({
		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		timeout: 8000,
		before: onBefore
	});

	twitter();

	$('.jqanchor').click(function(event){
			$('.jqanchor').removeClass('selected-black');
			$(this).addClass('selected-black');


			//prevent the default action for the click event


			//event.preventDefault();

			//alert(document.location);

			//get the full url - like mysitecom/index.htm#home
			var full_url = this.href;
			var doc_url = $(document).attr("location") + '';
			var docparts = doc_url.split("#");
			var parts = full_url.split("#");

			if(docparts[0] == parts[0]){
				event.preventDefault();
				var trgt = parts[1];
				var target='[name="'+trgt+'"]';
				var target_offset = $('[name="'+trgt+'"]').offset();
				var target_top = target_offset.top;
				$('body, html').animate({scrollTop:target_top}, 500);
			}

    });

    $('.jqanchor').each(function() {
		var myAnchor = '#' + $(this).attr("href").split('#')[1];
		if(myAnchor == document.location.hash){
			$(this).click();
		}
    });

});




function onBefore() {
	//$('cyclemessage_landing').html($(this).find('.cyclemessage').html());
	$('#cyclemessage_landing').html($(this).find('.cyclemessage').html());
	//alert($(this).html());
	//$('#output').html("Scrolling image:<br>" + this.src);
}


function printMe(url) {
	var width = Math.round(770);
	var height = Math.round(screen.availHeight - 40);
	var left = (screen.width - width) / 2;
	var top = 10;
	var params = 'width=' + width + ', height=' + height;
	params += ', top=' + top + ', left=' + left;
	params += ', directories=no';
	params += ', location=no';
	params += ', menubar=no';
	params += ', resizable=no';
	params += ', scrollbars=yes';
	params += ', status=no';
	params += ', toolbar=yes';
	newwin = window.open(url, 'windowname5', params);
	newwin.focus();
	//newwin.print();
	//newwin.close();
	return true;
}
function twitter() {
	var twuery = 'q=from:contactivity' +
						escape(' OR ') +
						'from:duivesteijn' +
						escape(' OR ') +
						'from:rengelhard' +
						escape(' OR ') +
						'from:import_random' +
						escape(' #contactivity');

	if($('#twitterbox').length == 1) {
		$('#twitterbox').html('');
		$('#twitterbox').jTweetsAnywhere({
			searchParams: twuery,
			count: 3,
			showTweetFeed: {
				showProfileImages: false,
				showUserScreenNames: true,
				paging: {
					mode: 'none'
				}
			}
		});

	//	setTimeout('twitter()', 60000);
	}
}
