if (top.location != self.location) top.location.replace(self.location);

var content = $('<style type="text/css">.tabpane .tabMain {display:none;} .tabpane .tabMain.standard {display:block;} .gallery .main .image {display:none;} .gallery .main .image.current {display:block;} .gallery .main .heading {top:-2.75em; position:absolute; right:0;}</style>');
$("head script:first").before(content);

function deleteComment(cid, container) {
	$.get("/blog/deleteComment", {id: cid}, function(data) {
		if (container != "") {
			$("#"+container).remove();
		}
	});
}

/* plugin section ........................................................

/**
 * jQuery.Preload - Multifunctional preloader
 * Copyright (c) 2008 Ariel Flesler - aflesler(at)gmail(dot)com
 * Dual licensed under MIT and GPL.
 * Date: 3/12/2008
 * @author Ariel Flesler
 * @version 1.0.7
 */
;(function($){var n=$.preload=function(c,d){if(c.split)c=$(c);d=$.extend({},n.defaults,d);var f=$.map(c,function(a){if(!a)return;if(a.split)return d.base+a+d.ext;var b=a.src||a.href;if(typeof d.placeholder=='string'&&a.src)a.src=d.placeholder;if(b&&d.find)b=b.replace(d.find,d.replace);return b||null}),g={loaded:0,failed:0,next:0,done:0,total:f.length};if(!g.total)return m();var h='<img/>',j=d.threshold;while(--j>0)h+='<img/>';h=$(h).load(k).error(k).bind('abort',k).each(l);function k(e){g.found=e.type=='load';g.image=this.src;var a=g.original=c[this.index];g[g.found?'loaded':'failed']++;g.done++;if(d.placeholder&&a.src)a.src=g.found?g.image:d.notFound||a.src;if(d.onComplete)d.onComplete(g);if(g.done<g.total)l(0,this);else{if(h.unbind)h.unbind('load').unbind('error').unbind('abort');h=null;m()}};function l(i,a,b){if($.browser.msie&&g.next&&g.next%n.gap==0&&!b){setTimeout(function(){l(i,a,1)},0);return!1}if(g.next==g.total)return!1;a.index=g.next;a.src=f[g.next++];if(d.onRequest){g.image=a.src;g.original=c[g.next-1];d.onRequest(g)}};function m(){if(d.onFinish)d.onFinish(g)}};n.gap=14;n.defaults={threshold:2,base:'',ext:'',replace:''};$.fn.preload=function(a){n(this,a);return this}})(jQuery);

/**
 * 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
 *
 */

jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') {
        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();
        }
        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 {
        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]);
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

$(document).ready(function(){
	$(".html5Overlay").remove();

	/*$(".gallery .main .current .graphic img").each(function() {
		console.log("http://www.onderhond.com"+$(this).attr("src"));
		jQuery("<img>").attr("src", $(this).attr("src"));
	});*/
	jQuery("<img>").attr("src", $(this).attr("http://gallery.onderhond.com/style/img/preload-type1.jpg"));
	jQuery("<img>").attr("src", $(this).attr("http://gallery.onderhond.com/style/img/preload-type2.jpg"));

	$.preload( '.gallery .main .current.type1 .graphic img', {
    	placeholder:'http://gallery.onderhond.com/style/img/preload-type1.jpg'
	});

	$.preload( '.gallery .main .current.type2 .graphic img', {
    	placeholder:'http://gallery.onderhond.com/style/img/preload-type2.jpg'
	});
		
	$.preload( '.gallery .main .type1:not(.current) .graphic img', {
    	placeholder:'http://gallery.onderhond.com/style/img/preload-type1.jpg'
	});

	$.preload( '.gallery .main .type2:not(.current) .graphic img', {
    	placeholder:'http://gallery.onderhond.com/style/img/preload-type2.jpg'
	});

	// tab pane standards ........................................................
	$(".tabMain").hide();
	$("#gallery .tabMain .head").hide();
	$(".tabMain.standard").show();
	$(".standard .tabHandler").addClass("active");


	// tab pane events
	$(".tabHandler").click(function () {

				$(".tabHandler").removeClass("active");
				$(".tabMain").hide();

	      var id = $(this).attr("href");
				$(id + ".tabMain").show();
				$(this).addClass("active");
        $.cookie('homeTab', $(this).closest("li").attr("class"));

				return false;
	});

	// subordinates ..............................................................
	//$(".subordinate").hide();
	$(".input .subControl").click(function () {
			$(".subordinate").hide();
			$(this).nextAll(".subordinate").toggle();
			
	});


	$(".subbed input[type=radio]").each(function(){
			$(this).click(setSubbed);
	});

	function setSubbed(){
		$(".subordinate").hide();
		$(".subbed input[type=radio]").each(function() {
			
			if ($(this).is(":checked")){
				$(this).nextAll(".subordinate").toggle();
			}
		});
	};

	setSubbed();


	// gallery image..............................................................
	$(".gallerypage .content .image").hide();
	$(".gallerypage .content .image.current").show();

	//$(".gallerypage .content .image:first-child").show();

	// gallery summary events
	$(".gallerypage .context .compact a").click(function () {
				$(".gallerypage .context .compact a").removeClass("active");
				$(".gallerypage .content .image").hide();

	      var id = $(this).attr("href");
				$(".gallerypage .content " + id).show();
				$(this).addClass("active");

				return false;
	});

	// search field ..............................................................
	$(".context .search .textfield").focus(function () {
		if ($(".context .search .textfield").attr("value") == "Search..."){
			$(".context .search .textfield").attr("value", "");
		}
	});
	$(".context .search .textfield").blur(function () {
		if ($(".context .search .textfield").attr("value") == ""){
			$(".context .search .textfield").attr("value", "Search...");
		}
	});

	// legend link ..............................................................
	$(".legend").hide();

	var legendLink = $('<div class="legendHandler">legend</div>');

	$(legendLink).insertBefore(".legend");
	$(legendLink).click(function () {
			$(this).toggleClass("toggle");
			$(".legend").slideToggle("fast");
	});

	// preview link ..............................................................
	var prevLink = $('<a href="#commentsForm" class="action preview" id="previewLink">preview</a>');

	$(prevLink).appendTo("#blogCommentForm .buttonGroup");
	$(prevLink).click(function () {

		var commentValue = $("#fieldComment").val();
		var nameValue = $("#fieldName").val();
		var emailValue = $("#fieldEmail").val();
		var siteValue = $("#fieldSite").val();
		var commentNumber = $("#comments>div.comment:not(.heading):not(.preview)").length;


		$.post("/blog/getPreview",
				{commentCount: commentNumber, name: nameValue, mail: emailValue, site: siteValue, comment: commentValue},
				function(data) {
					if ($("#comments .comment.preview").length > 0) {
						$("#comments .comment.preview").replaceWith(data);
					} else {
						$(data).insertBefore("#commentsForm");
					}

					var target = $("body").find('#commentsForm');
					$.scrollTo( target , 1 );
				}
		);

		return false;

	});
});