jQuery(document).ready(function($) {

jQuery.fn.center = function () {
    this.css("position","absolute");
    this.css("top", (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop() + "px");
    this.css("left", (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft() + "px");
    return this;
}


	/* animate slideout navigation upon load */
	$('.slideoutPane').animate({'marginLeft':'-148px'}, 600).animate({'marginLeft':'-158px'}, 1200);

	/* slideout navigation */
	$(function() {
	 $('#slideoutNavigation > li').hover(
	  function () {
	   $('.slideoutPane',$(this)).stop().animate({'marginLeft':'-2px'},200);
	  },
	  function () {
	   $('.slideoutPane',$(this)).stop().animate({'marginLeft':'-158px'},200);
	  }
	 );
	});

	/* job list accordion */
	$("#job-list-accordion").accordion();

	/* float navigation */
	$.waypoints.settings.scrollThrottle = 10;
	$("#floatmenu-grabber").waypoint(function(event, direction) {
		$("#floatmenu").toggleClass('sticky');
		event.stopPropagation();
	}, {
		offset: 'bottom-in-view'
	});

	/* grid navigation */
	$('#tj_container').gridnav({
			rows: 3,
			navL: '#tj_prev',
			navR: '#tj_next',
			type: {
				mode: 'disperse',
				speed: 400,
				easing: '',
				factor: 50,
				referse: false
			}
	});

	/* find store ajax */
	$(".store").click(function() {
        // Clear the navigation
        $(".store_content").removeClass('selected').hide();
        $("#store-content-storepicture").addClass('selected').show();

        // Clear the previous Google map
        //$("#map_canvas").html('');

        // Read new data
		$.post("/_custom/ajax/findstore.php", { id: $(this).attr('id'), get_nav: true },
			function(data) {
				$("#store-content-navigation").html(data);
		});
		$.post("/_custom/ajax/findstore.php", { id: $(this).attr('id'), get_frontpage: true },
				function(data) {
				$("#store-content-storepicture").html(data);
		});
		$.post("/_custom/ajax/findstore.php", { id: $(this).attr('id'), get_coworkers: true },
			function(data) {
				$("#store-content-coworkers").html(data);
		});
		$.post("/_custom/ajax/findstore.php", { id: $(this).attr('id'), get_products: true },
			function(data) {
				$("#store-content-products").html(data);
		});
		$.post("/_custom/ajax/findstore.php", { id: $(this).attr('id'), get_right: true },
			function(data) {
				$("#store-content-right").html(data);
		});
		$.post("/_custom/ajax/findstore.php", { id: $(this).attr('id'), get_coords: true },
			function(data) {
				$("#coords").html(data);
		});
	});

	/* find store overlay */
	$(".store[rel]").overlay({
        mask: {
            color: '#000',
            loadSpeed: 200,
            opacity: 0.95
        },
        fixed: false,
        left: 'center',
        top: 0
	});

		$(".store[rel]").bind('onClose', function(event) {
            /*
			$(this).find('.selected').each(function() {

					alert('test');
			});
            */

		});


		$('.products.NO').hide();
	/* find store overlay navigation */
	$("#store-content-navigation li").live("click", function() {
		$("#store-content-left").find(".selected").hide();
		$("#store-content-left").find(".selected").removeClass('selected');
		$("#store-content-navigation").find(".selected").removeClass('selected');
		var id = $(this).attr('id');

		$("#store-content-left").find("#store-content-"+id).show();
		$("#store-content-left").find("#store-content-"+id).addClass('selected');
		$(this).addClass('selected');

		var coords = $("#coords").html();
		coords = coords.split(', ');
		var x = coords[0];
		var y = coords[1];

		var map = null;
		var markers = [];
		var infowindows = [];
		var initialLocation = new google.maps.LatLng(x, y);
		var useGeolocation = true;

		if (!Array.prototype.forEach) {
			Array.prototype.forEach = function(fun /*, thisp*/)
			{
				var len = this.length;
				if (typeof fun != "function")
					throw new TypeError();

				var thisp = arguments[1];
				for (var i = 0; i < len; i++)
				{
					if (i in this)
						fun.call(thisp, this[i], i, this);
				}
			};
		}

        function get_store_data() {
            var html = "";
            jQuery("#store-content-right-text >div[class]").not('.email').each(function() {
                html += jQuery(this).html();
                html += "<br />";
            });
            return html;
        }

		function setMarkers(map) {

                var location = new google.maps.LatLng(x, y);
                var google_data = get_store_data();
                var infowindow = new google.maps.InfoWindow({
                    content: google_data
                });

                var gimage = new google.maps.MarkerImage(
                  'http://sw2431.smart-web.dk/upload_dir/themes/web/unik/graphics/dmarker.png',
                  new google.maps.Size(28,40),
                  new google.maps.Point(0,0),
                  new google.maps.Point(14,40)
                );

                var gshadow = new google.maps.MarkerImage(
                  'http://sw2431.smart-web.dk/upload_dir/themes/web/unik/graphics/dmarker_shadow.png',
                  new google.maps.Size(52,40),
                  new google.maps.Point(0,0),
                  new google.maps.Point(14,40)
                );

                var gshape = {
                  coord: [0,0, 27,0, 27,27, 19,27, 13,39, 8,27, 0,27],
                  type: 'poly'
                };

                var marker = new google.maps.Marker({
                    position: location,
                    map: map,
                    icon: gimage,
                    shadow: gshadow,
                    shape: gshape,
                    title: "title"
                });

                google.maps.event.addListener(marker, "click", function() {
                    map.panTo(marker.position);
                    //map.setZoom(8);

                    //Close windows
                    infowindows.forEach(function(e) {
                        e.close();
                    });

                    //Open relevant window
                    infowindow.open(map, marker);
                });

                markers.push(marker);
                infowindows.push(infowindow);

        }

        var myOptions = {
            zoom: 12,
            center: initialLocation,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        }
        map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
        setMarkers(map);
	});

	$(".googlemap-side").live("click", function() {
	$("#store-content-left").find(".selected").hide();
	$("#store-content-left").find(".selected").removeClass('selected');
	$("#store-content-navigation").find(".selected").removeClass('selected');

	$("#store-content-left").find("#store-content-googlemap").show();
	$("#store-content-left").find("#store-content-googlemap").addClass('selected');
	$(".googlemap").addClass('selected');

	var coords = $("#coords").html();
	coords = coords.split(', ');
	var x = coords[0];
	var y = coords[1];

    var map = null;
    var markers = [];
    var infowindows = [];
    var initialLocation = new google.maps.LatLng(x, y);
    var useGeolocation = true;

    if (!Array.prototype.forEach) {
        Array.prototype.forEach = function(fun /*, thisp*/)
        {
            var len = this.length;
            if (typeof fun != "function")
                throw new TypeError();

            var thisp = arguments[1];
            for (var i = 0; i < len; i++)
            {
                if (i in this)
                    fun.call(thisp, this[i], i, this);
            }
        };
    }

    function setMarkers(map) {

                var location = new google.maps.LatLng(x, y);

                var infowindow = new google.maps.InfoWindow({
                    content: 'desc'
                });

                var gimage = new google.maps.MarkerImage(
                  'http://sw2431.smart-web.dk/upload_dir/themes/web/unik/graphics/dmarker.png',
                  new google.maps.Size(28,40),
                  new google.maps.Point(0,0),
                  new google.maps.Point(14,40)
                );

                var gshadow = new google.maps.MarkerImage(
                  'http://sw2431.smart-web.dk/upload_dir/themes/web/unik/graphics/dmarker_shadow.png',
                  new google.maps.Size(52,40),
                  new google.maps.Point(0,0),
                  new google.maps.Point(14,40)
                );

                var gshape = {
                  coord: [0,0, 27,0, 27,27, 19,27, 13,39, 8,27, 0,27],
                  type: 'poly'
                };

                var marker = new google.maps.Marker({
                    position: location,
                    map: map,
                    icon: gimage,
                    shadow: gshadow,
                    shape: gshape,
                    title: "title"
                });

                google.maps.event.addListener(marker, "click", function() {
                    map.panTo(marker.position);
                    //map.setZoom(8);

                    //Close windows
                    infowindows.forEach(function(e) {
                        e.close();
                    });

                    //Open relevant window
                    infowindow.open(map, marker);
                });

                markers.push(marker);
                infowindows.push(infowindow);

    }

    var myOptions = {
       zoom: 12,
       center: initialLocation,
       mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    setMarkers(map);




	});

	/*
	$(".gallery-navigation-cat").click(function() {
		$(this).find(".gallery-navigation-choices").toggle();
	});*/
	/*
	$(".gallery-navigation-choice").click(function() {
		$.post("/_custom/ajax/gallery.php", {  gallery: $(this).attr('id') },
		function(data) {
			$("#gallery-pictures").html(data);
		});
		$(this).parent(".gallery-navigation-choices").parent(".gallery-navigation-cat").find(".selected").html($(this).html());
	});
	*/
	/* frontpage slider trickery */
	$(".frontpage-image-1").show();
	$(".frontpage-image-info-1").show();

	$(".frontpage-box").click(function() {
		$(".frontpage-image").hide();
		$(".frontpage-image-info").hide();
		var id = $(this).attr("id");
		$(".frontpage-image-"+id).show();
		$(".frontpage-image-info-"+id).show();
		$(document).stopTime();
	});

	var ii = 1;
	$(document).everyTime(2000, function(i) {
		$(".frontpage-image").fadeOut(500);
		$(".frontpage-image-info").fadeOut(500);
		$(".frontpage-image-"+ii).fadeIn(500);
		$(".frontpage-image-info-"+ii).fadeIn(500);

		ii++;
		if (ii > 3) {
			ii = 1;
		}
	});

	/* newsletter show hide */
	$("#unsubscribe-newsletter").click(function() {
		$("#newsletter-field-signup").hide();
		$("#newsletter-field-signout").show();
		$(this).hide();
		$(".standard-title").html("Frameld nyhedsbrev");
	});


    /* gallery overlay */
    $(".tj_gallery li[rel]").overlay({
        mask: {
            color: '#000',
            loadSpeed: 200,
            opacity: 0.95
        },
        closeOnClick: true,
        fixed: false
    });
  		var current;
    $('.tj_wrapper ul li').click(function() {
		id = '#'+$(this).attr('id');
		$('#gallery-overlay').find(id).show();
		$('#gallery-overlay').find(id).addClass('selected');
		current = id.split('-')[1];
		//console.log(current);
		$('.linger').children('.navi').fadeOut(1200);

	});

		$(".tj_wrapper li[rel]").bind('onClose', function(event) {
			$('#gallery-overlay').find('.selected').hide();
			$('#gallery-overlay').find('.selected').removeClass('selected');

		});

			$('#tj_container .gallery-left').click(function() {
			id = '#image-'+current;
			var next = $('#gallery-overlay').find(id).prev().attr('id');



			if (next != '') {
				$('#gallery-overlay '+id).removeClass('selected');
				$('#gallery-overlay '+id).hide();
				$('#gallery-overlay #'+next).show();
				$('#gallery-overlay #'+next).addClass('selected');
				current = next.split('-')[1];
			}
			//console.log('left');
			$('.linger').children('.navi').fadeOut(1200);
		});

		$('#tj_container .gallery-right').click(function() {
			id = '#image-'+current;
			var next = $('#gallery-overlay').find(id).next().attr('id');
			if (next != null) {
				$('#gallery-overlay '+id).removeClass('selected');
				$('#gallery-overlay '+id).hide();
				$('#gallery-overlay #'+next).show();
				$('#gallery-overlay #'+next).addClass('selected');
				current = next.split('-')[1];
			}
			//console.log('right');
			$('.linger').children('.navi').fadeOut(1200);
		});


    /* identify unknown form elements */
    $("#FormElementCheckbox863Row .FormElementColumn table tr").each(function(index) {
    		$(this).find('td').first().prepend('<div class="off" id="'+$(this).find('input').attr('id')+'"></div>');
    		$(this).find('input').hide();
    		$(this).find("label").addClass('labela-'+index);
    	/*	$(this).find("input").addClass('off');*/

    });
    $("#FormElementCheckbox846Row .FormElementColumn table tr").each(function(index) {
    		$(this).find('td').first().prepend('<div class="off" id="'+$(this).find('input').attr('id')+'"></div>');
    		$(this).find('input').hide();
    		$(this).find("label").addClass('labelb-'+index);
    		/*$(this).find("label").addClass('off');	 */
    });

    $("#FormElementCheckbox948Row .FormElementColumn table tr").each(function(index) {
    		$(this).find('td').first().prepend('<div class="off" id="'+$(this).find('input').attr('id')+'"></div>');
    		$(this).find('input').hide();
    		$(this).find("label").addClass('labelc-'+index);
    		/*$(this).find("label").addClass('off');	 */
    });

    $('.on').live('click', function() {
    		var id = $(this).attr('id');
    		$('input#'+id).attr('checked', false);
    	$(this).removeClass('on');
    	$(this).addClass('off');
    });

    $('.off').live('click', function() {
    	var id = $(this).attr('id');
    	$('input#'+id).attr('checked', true);
    	$(this).removeClass('off');
    	$(this).addClass('on');
    });



    /* Masonry trickery by JO */
    function masonryFilter(selector, instance) {
    if (! instance) instance = $wall;
    //console.log('Filter: ' + selector);
    if(selector == 'all' || selector == '' || !selector) {
        // show all hidden boxes
        instance.children('.invis')
            .toggleClass('invis').fadeIn(500);
    } else {
        newselector = '[data-group~="' + selector + '"]';
        // hide visible boxes
        instance.children().not(newselector).not('.invis')
          .toggleClass('invis').fadeOut(500);
        // show hidden boxes
        instance.children('.invis'+newselector)
        .toggleClass('invis').fadeIn(500);
    }
    instance.masonry('reload');
}

	var masonry = $('#gallery-pictures').masonry({
			itemSelector: '.gallery-picture:not(.invis)',
			isAnimated: true
	});

	$('#gallery-navigation-path span:not(.no)').live('click', function() {
		masonryFilter($(this).find('span').first().attr('data-filter'), masonry);
		$(this).parent().find('span').last().html('Alle');
		$.waypoints('refresh');
	});

	$('.gallery-navigation-choice').click(function() {
		masonryFilter($(this).attr('data-filter'), masonry);
		$('#gallery-navigation-path').html($(this).find('.path').html());
		$.waypoints('refresh');
	});

	$('.gallery-navigation-cat p').click(function() {
		masonryFilter($(this).parent().attr('data-filter'), masonry);
		$('#gallery-navigation-path').html($(this).parent().find('.path').html());
		$.waypoints('refresh');
	});

	$('.gallery-navigation-cat').hover(
		function() {
		$(this).find('.gallery-navigation-choices').show();
				$.waypoints('refresh');
		},
		function() {
		$(this).find('.gallery-navigation-choices').hide();
				$.waypoints('refresh');
	});

	$('#gallery-navigation-path span').live('mouseover mouseout', function(event) {
			if (event.type == 'mouseover') {
			$(this).css('text-decoration', 'underline');
			} else {
			$(this).css('text-decoration', 'none');
			}
	});

	$('#topbarNavigation ul li a').hover(
		function() {
			$(this).addClass('topnav-hover');
		},
		function() {
			$(this).removeClass('topnav-hover');
	});

	$('#new-footer #menu ul li a').hover(
		function() {
			$(this).addClass('hover');
		},
		function() {
			$(this).removeClass('hover');
	});

	/* left menu folding */
	$('#left-navigation ul li:not(.active) ul').toggle();

	$('#left-navigation ul li').hover(function() {
		$(this).find('a').addClass('new-hover');
	}, function() {
		$(this).find('a').removeClass('new-hover');

	});

		$(".gallery-picture[rel]").overlay({
			mask: {
				color: '#000',
				loadSpeed: 200,
				opacity: 0.95
			},
			fixed: false,
			left: 'center',
			top: 0

		});

		$(".gallery-picture[rel]").bind('onClose', function(event) {
			$('#gallery-overlay').find('.selected').hide();
			$('#gallery-overlay').find('.selected').removeClass('selected');

		});

		var current;
		var max;
		$('.gallery-picture').click(function() {
			id = '#'+$(this).attr('id');
			$('#gallery-overlay').find(id).show();
			$('#gallery-overlay').find(id).addClass('selected');
			current = id.split('-')[1];
			//console.log(current);
			/*$('.linger').children('.navi').fadeOut(1200);*/
		});

		$('#standard .gallery-left').click(function() {
			id = '#image-'+current;
			var next = $('#gallery-pictures').find(id).prev(':visible').attr('id');
			//console.log(next);
			if (next != '') {
				$('#gallery-overlay '+id).removeClass('selected');
				$('#gallery-overlay '+id).hide();
				$('#gallery-overlay #'+next).show();
				$('#gallery-overlay #'+next).addClass('selected');
				current = next.split('-')[1];
			}
			//console.log('left');
			/*$('.linger').children('.navi').fadeOut(1200);*/
		});

		$('#standard .gallery-right').click(function() {
			id = '#image-'+current;
			var next = $('#gallery-pictures').find(id).next(':visible').attr('id');
			if (next != null) {
				$('#gallery-overlay '+id).removeClass('selected');
				$('#gallery-overlay '+id).hide();
				$('#gallery-overlay #'+next).show();
				$('#gallery-overlay #'+next).addClass('selected');
				current = next.split('-')[1];
			}
			//console.log('right');
			/*$('.linger').children('.navi').fadeOut(1200);*/
		});


		$('.gagllery-left-linger').hover(function() {
			$(this).find('.gallery-left').fadeIn(200);
		},
		function() {
			/*$(this).find('.gallery-left').fadeOut(1000);*/
		});

		$('.gallery-right-linger').hover(function() {
			$(this).find('.gallery-right').fadeIn(200);
		},
		function() {
			/*$(this).find('.gallery-right').fadeOut(1000);*/
		});


		$('#catalog-right a').attr('target', '_blank');

		/* google maps */
		if ($('#allCoords').length>0) {



			var map = null;
			var markers = [];
			var infowindows = [];
			if ($('body.languageNO').length > 0) {
				var initialLocation = new google.maps.LatLng(65, 10);
			} else {
				var initialLocation = new google.maps.LatLng(56, 10);
			}
			var useGeolocation = true;

			if (!Array.prototype.forEach) {
				Array.prototype.forEach = function(fun /*, thisp*/)
				{
					var len = this.length;
					if (typeof fun != "function")
						throw new TypeError();

					var thisp = arguments[1];
					for (var i = 0; i < len; i++)
					{
						if (i in this)
							fun.call(thisp, this[i], i, this);
					}
				};
			}

			function setMarkers(map, x, y, title, desc) {

					var location = new google.maps.LatLng(x, y);

					var infowindow = new google.maps.InfoWindow({
						content: desc
					});

                var gimage = new google.maps.MarkerImage(
                  'http://sw2431.smart-web.dk/upload_dir/themes/web/unik/graphics/dmarker.png',
                  new google.maps.Size(28,40),
                  new google.maps.Point(0,0),
                  new google.maps.Point(14,40)
                );

                var gshadow = new google.maps.MarkerImage(
                  'http://sw2431.smart-web.dk/upload_dir/themes/web/unik/graphics/dmarker_shadow.png',
                  new google.maps.Size(52,40),
                  new google.maps.Point(0,0),
                  new google.maps.Point(14,40)
                );

                var gshape = {
                  coord: [0,0, 27,0, 27,27, 19,27, 13,39, 8,27, 0,27],
                  type: 'poly'
                };

                var marker = new google.maps.Marker({
                    position: location,
                    map: map,
                    icon: gimage,
                    shadow: gshadow,
                    shape: gshape,
                    title: "title"
                });

					google.maps.event.addListener(marker, "click", function() {
						map.panTo(marker.position);
						//map.setZoom(8);

						//Close windows
						infowindows.forEach(function(e) {
							e.close();
						});

						//Open relevant window
						infowindow.open(map, marker);
					});

					markers.push(marker);
					infowindows.push(infowindow);

			}

			var newZoom;
				if ($('body.languageNO').length > 0) {
					newZoom = 4;
				} else {
					newZoom = 6;
				}

			var myOptions = {
				zoom: newZoom,
				center: initialLocation,
				mapTypeId: google.maps.MapTypeId.ROADMAP
			}
			map = new google.maps.Map(document.getElementById("map_canvas2"), myOptions);
			$('#allCoords .coords').each(function() {
				var coords = $(this).find('.coordinates').html();
				coords = coords.split(', ');
				var x = coords[0];
				var y = coords[1];
				var title = $(this).find('.name').html();
				var desc = $(this).find('.info').html();
				setMarkers(map, x, y, title, desc);
			});

		}

		$('.gallery-picture').hover(function() {
				$(this).find('.gallery-picture-top').css('background', '#eee');
		}, function() {
			$(this).find('.gallery-picture-top').css('background', '#fff');
		});

		$('.gallery-navigation-choices').hover(function() {
				$(this).parent().find('.nav-bullet').addClass('nav-bullet-down');
				$(this).parent().find('.nav-bullet').removeClass('nav-bullet');
		}, function() {
			$(this).parent().find('.nav-bullet-down').addClass('nav-bullet');
			$(this).parent().find('.nav-bullet-down').removeClass('nav-bullet-down');
		});

		$('.gallery-navigation-choice').hover(function() {
				$(this).css('color', '#646464');
				$(this).css('text-decoration', 'underline');
		}, function() {
			$(this).css('color', '#000');
			$(this).css('text-decoration', 'none');

		});

		$('.gallery-navigation-cat').hover(function() {
				$(this).find('p').css('color', '#646464');
				$(this).find('.nav-bullet').addClass('nav-bullet-down');
				$(this).find('.nav-bullet').removeClass('nav-bullet');
		}, function() {
			$(this).find('p').css('color', '#000');
				$(this).find('.nav-bullet-down').addClass('nav-bullet');
				$(this).find('.nav-bullet-down').removeClass('nav-bullet-down');
		});

	$(document).everyTime(400, function(i) {

					$.waypoints('refresh');
	});

var hash = location.hash;

    // Accordion for Category Box
    jQuery("#categorylist-box-content >ul").addClass('MagicWrapper').find('ul').hide();
    // Start up code
    jQuery("#categorylist-box ul a.current").next('ul').slideDown();
    // Init code
    jQuery("#categorylist-box ul a").click(function(e) {
        // Cancel default event
        e.preventDefault();

        // Animate
        var el = jQuery(this);
        var eldrop = jQuery(this).next('ul');
        if (el.hasClass('current')) {
            //el.removeClass('magic').slideUp();
        } else {
            // This category is a valid click

            // Is the click a parent node or a child node?
            if (el.parent().parent().attr('class') == 'MagicWrapper') {
                // Close everything
                jQuery("#categorylist-box ul a.current").next('ul').slideUp().parents('ul').not('ul.MagicWrapper').slideUp();
				$(this).parent().parent().find('.opened').removeClass('opened');
				$(this).parent().addClass('opened');
            }
            // Open new element
            eldrop.slideDown();
        }
        // Remove active marker
        jQuery("#categorylist-box li a.current").removeClass('current');
        // Add active marker
        jQuery(this).addClass('current').parents('li').find('>a').addClass('current');
        // We need to fetch its content with AJAX
        var newUrl = jQuery(this).attr('href');
        loadSite(newUrl);
    });


    loadSite(null, true);
    setInterval(function()
    {
        if (location.hash != hash)
        {
            loadSite();
            hash = location.hash;
        }
    }, 100);


function loadSite(url, activateLink) {
    if (url == null) {
        url = window.location.hash;
        if (url != '') {
            url = url.substring(1);
        }
    }
    if (url.length > 0) {
        jQuery("#webshop-content").load(url + ' #webshop-content', function() {
            window.location.hash = '#' + url;
            hash = '#' + url;
            if (activateLink) {
                jQuery("#categorylist-box ul a").each(function() {
                    if (jQuery(this).attr('href') == url) {
                        jQuery(this).parents('li').find('>a').addClass('current');
                        jQuery(this).next('ul').addClass('magic').slideDown();
                        jQuery(this).parents('ul').not('ul.MagicWrapper').addClass('magic').slideDown();
                    }
                });
            }
            initClickButton();
        });



    }
}

$('#webshop-wrapper li').first().addClass('first');



	$('#designa-bottom .frontpage-box[rel]').overlay({
        mask: {
            color: '#000',
            loadSpeed: 200,
            opacity: 0.95
        },
        closeOnClick: true,
        fixed: true,
        left: 'center',
        top: 'center'

	});

	$('.slideoutPane[rel]').overlay({
        mask: {
            color: '#000',
            loadSpeed: 200,
            opacity: 0.95
        },
        closeOnClick: true,
        fixed: true,
        left: 'center',
        top: 'center'

	});

	$('#gallery-title span').click(function() {
		masonryFilter($(this).attr('data-filter'), masonry);
	});

	$('#gallery-title span').hover(function() {
		$(this).css('text-decoration', 'underline');
	}, function() {
		$(this).css('text-decoration', 'none');
	});

	$('#product-links').find('a').first().hide();

	$('#new-footer-left .left-middle div').hover(function() {
		$(this).addClass('hover');
	}, function() {
		$(this).removeClass('hover');
	});

	$('.store').hover(function() {
		$(this).find('.bullet').addClass('store-hover');

	}, function() {
		$(this).find('.bullet').removeClass('store-hover');

	});

	$('#left-navigation ul li.active a span').css('color', '#313131');

	$('.email-hover a').hover(function() {
		$(this).addClass('email-hover-hover');
	}, function() {
		$(this).removeClass('email-hover-hover');
	});
	/* Gallery deep linking */
	var url = window.location.pathname;
	var parts = url.split('/');
	var name = null;
	//console.log(parts[3]);
	masonryFilter(parts[3], masonry);
	var id = '';
	if (parts[1] == 'koekken' || parts[1] == 'bordplader') {
		if (is_int(parts[2])) {
			id = parts[2];
		} else if (is_int(parts[3])) {
			id = parts[3];
		} else if (is_int(parts[4])) {
			id = parts[4];
		} else {
			name = parts[4];
		}
	if (!is_int(parts[2]) && parts[2] != '' && (parts[3] == '')) {
		var path = '<div class="nav-circle">&#8226;</div><span data-filter="'+parts[2]+'">'+parts[2]+'</span><div class="nav-circle">&#8226;</div><span data-filter="'+parts[2]+'">Alle</span>';
	}
	if (parts[2] != '' && parts[3] != '') {
		var path = '<div class="nav-circle">&#8226;</div><span data-filter="'+parts[2]+'">'+parts[2]+'</span><div class="nav-circle">&#8226;</div><span class="no" data-filter="'+parts[3]+'">'+parts[3]+'</span>';
	}
	} else {
		name = parts[2];
	}

	//console.log(name);


	if (id > 0) {
	$('#gallery-overlay .image-id-'+id).show();
	$('#gallery-overlay .image-id-'+id).addClass('selected');
	$('#gallery-navigation-path').html(path);
	} else if (name != '') {
	$('#gallery-overlay .image-name-'+name).first().show();
	$('#gallery-overlay .image-name-'+name).first().addClass('selected');
	$('#gallery-navigation-path').html(path);
	}

	if (id != '' || name != '' && parts[2] != '') {
	$('#gallery-overlay').overlay({
			mask: {
				color: '#000',
				loadSpeed: 200,
				opacity: 0.95
			},
			fixed: false,
			left: 'center',
			top: 0,
			load: true
	});
	$('.linger').hide();

	}

	$("#gallery-overlay").bind('onClose', function(event) {
		$('#gallery-overlay .image-id-'+id).hide();
		$('#gallery-overlay .image-id-'+id).removeClass('selected');
		$('#gallery-overlay .image-name-'+name).hide();
		$('#gallery-overlay .image-name-'+name).removeClass('selected');

		$('.linger').show();
	});

	function is_int(value){
		if((parseFloat(value) == parseInt(value)) && !isNaN(value)){
			return true;
		} else {
			return false;
		}
	}

});
