﻿/* styleswitch by http://www.dynamicdrive.com */
var manual_or_random = "manual";
var randomsetting = "3 days";
function getCookie(Name) {
    var re = new RegExp(Name + "=[^;]+", "i");
    if (document.cookie.match(re))
        return document.cookie.match(re)[0].split("=")[1];
    return null
}
function setCookie(name, value, days) {
    var expireDate = new Date();
    var expstring = (typeof days != "undefined") ? expireDate.setDate(expireDate.getDate() + parseInt(days)) : expireDate.setDate(expireDate.getDate() - 5);
    document.cookie = name + "=" + value + "; expires=" + expireDate.toGMTString() + "; path=/";
}
function deleteCookie(name) {
    setCookie(name, "moot")
}
function setStylesheet(title, randomize) {
    var i, cacheobj, altsheets = [""];
    for (i = 0; (cacheobj = document.getElementsByTagName("link")[i]); i++) {
        if (cacheobj.getAttribute("rel").toLowerCase() == "alternate stylesheet" && cacheobj.getAttribute("title")) {
            cacheobj.disabled = true;
            altsheets.push(cacheobj);
            if (cacheobj.getAttribute("title") == title) {
                cacheobj.disabled = false
            }
        }
    }
    if (typeof randomize != "undefined") {
        var randomnumber = Math.floor(Math.random() * altsheets.length);
        altsheets[randomnumber].disabled = false
    }
    return (typeof randomize != "undefined" && altsheets[randomnumber] != "") ? altsheets[randomnumber].getAttribute("title") : ""
}
function chooseStyle(styletitle, days) {
    if (document.getElementById) {
        setStylesheet(styletitle);
        setCookie("mysheet", styletitle, days)
    }
}
function indicateSelected(element) {
    if (selectedtitle != null && (element.type == undefined || element.type == "select-one")) {
        var element = (element.type == "select-one") ? element.options : element;
        for (var i = 0; i < element.length; i++) {
            if (element[i].value == selectedtitle) {
                if (element[i].tagName == "OPTION") {
                    element[i].selected = true
                } else {
                    element[i].checked = true
                }
                break
            }
        }
    }
}
if (manual_or_random == "manual") {
    var selectedtitle = getCookie("mysheet");
    if (document.getElementById && selectedtitle != null) {
        setStylesheet(selectedtitle)
    }
} else if (manual_or_random == "random") {
    if (randomsetting == "eachtime") {
        setStylesheet("", "random")
    } else if (randomsetting == "sessiononly") {
        if (getCookie("mysheet_s") == null) {
            document.cookie = "mysheet_s=" + setStylesheet("", "random") + "; path=/"
        } else {
            setStylesheet(getCookie("mysheet_s"))
        }
    } else if (randomsetting.search(/^[1-9]+ days/i) != -1) {
        if (getCookie("mysheet_r") == null || parseInt(getCookie("mysheet_r_days")) != parseInt(randomsetting)) {
            setCookie("mysheet_r", setStylesheet("", "random"), parseInt(randomsetting));
            setCookie("mysheet_r_days", randomsetting, parseInt(randomsetting))
        } else {
            setStylesheet(getCookie("mysheet_r"))
        }
    }
};
/* easing by George McGinley Smith http://gsgd.co.uk/sandbox/jquery/easing/ */
jQuery.easing['jswing'] = jQuery.easing['swing'];
jQuery.extend(jQuery.easing, {def: 'easeOutQuad',swing: function(x, t, b, c, d) {
        return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
    },easeInQuad: function(x, t, b, c, d) {
        return c * (t /= d) * t + b;
    },easeOutQuad: function(x, t, b, c, d) {
        return -c * (t /= d) * (t - 2) + b;
    },easeInOutQuad: function(x, t, b, c, d) {
        if ((t /= d / 2) < 1)
            return c / 2 * t * t + b;
        return -c / 2 * ((--t) * (t - 2) - 1) + b;
    },easeInExpo: function(x, t, b, c, d) {
        return (t == 0) ? b : c * Math.pow(2, 10 * (t / d - 1)) + b;
    },easeOutExpo: function(x, t, b, c, d) {
        return (t == d) ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b;
    },easeInOutExpo: function(x, t, b, c, d) {
        if (t == 0)
            return b;
        if (t == d)
            return b + c;
        if ((t /= d / 2) < 1)
            return c / 2 * Math.pow(2, 10 * (t - 1)) + b;
        return c / 2 * (-Math.pow(2, -10 * --t) + 2) + b;
    },easeInBack: function(x, t, b, c, d, s) {
        if (s == undefined)
            s = 1.70158;
        return c * (t /= d) * t * ((s + 1) * t - s) + b;
    },easeOutBack: function(x, t, b, c, d, s) {
        if (s == undefined)
            s = 1.70158;
        return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
    },easeInOutBack: function(x, t, b, c, d, s) {
        if (s == undefined)
            s = 1.70158;
        if ((t /= d / 2) < 1)
            return c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b;
        return c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b;
    }});
/* mousewheel by Brandon Aaron http://brandonaaron.net */
(function($) {
    $.event.special.mousewheel = {setup: function() {
            var handler = $.event.special.mousewheel.handler;
            if ($.browser.mozilla)
                $(this).bind('mousemove.mousewheel', function(event) {
                    $.data(this, 'mwcursorposdata', {pageX: event.pageX, pageY: event.pageY, clientX: event.clientX, clientY: event.clientY});
                });
            if (this.addEventListener)
                this.addEventListener(($.browser.mozilla ? 'DOMMouseScroll' : 'mousewheel'), handler, false);
            else
                this.onmousewheel = handler;
        },teardown: function() {
            var handler = $.event.special.mousewheel.handler;
            $(this).unbind('mousemove.mousewheel');
            if (this.removeEventListener)
                this.removeEventListener(($.browser.mozilla ? 'DOMMouseScroll' : 'mousewheel'), handler, false);
            else
                this.onmousewheel = function() {
                };
            $.removeData(this, 'mwcursorposdata');
        },handler: function(event) {
            var args = Array.prototype.slice.call(arguments, 1);
            event = $.event.fix(event || window.event);
            $.extend(event, $.data(this, 'mwcursorposdata') || {});
            var delta = 0, returnValue = true;
            if (event.wheelDelta)
                delta = event.wheelDelta / 120;
            if (event.detail)
                delta = -event.detail / 3;
            event.data = event.data || {};
            event.type = "mousewheel";
            args.unshift(delta);
            args.unshift(event);
            return $.event.handle.apply(this, args);
        }};
    $.fn.extend({mousewheel: function(fn) {
            return fn ? this.bind("mousewheel", fn) : this.trigger("mousewheel");
        },unmousewheel: function(fn) {
            return this.unbind("mousewheel", fn);
        }});
})(jQuery);
/* context menu by Jonas Arnklint http://github.com/arnklint/jquery-contextMenu */
(function($) {
    jQuery.fn.contextMenu = function(name, actions, options) {
        var me = this, win = $(window), menu = $('<ul id="' + name + '" class="context-menu"></ul>').hide().appendTo('body'), activeElement = null, hideMenu = function() {
            $('.context-menu:visible').each(function() {
                $(this).trigger("closed");
                $(this).hide();
                $('body').unbind('click', hideMenu);
            });
        }, default_options = {disable_native_context_menu: false,leftClick: false}, options = $.extend(default_options, options);
        $(document).bind('contextmenu', function(e) {
            if (options.disable_native_context_menu) {
                e.preventDefault();
            }
            hideMenu();
        });
        $.each(actions, function(me, itemOptions) {
            if (itemOptions.link) {
                var link = itemOptions.link;
            } else {
                var link = '<a class="tooltip" target="">' + me + '</a>';
            }
            var menuItem = $('<li>' + link + '</li>');
            if (itemOptions.klass) {
                menuItem.attr("class", itemOptions.klass);
            }
            menuItem.appendTo(menu).bind('click', function(e) {
                itemOptions.click(activeElement);
                e.preventDefault();
            });
        });
        var mouseEvent = 'contextmenu click';
        if ($.browser.msie && options.leftClick) {
            mouseEvent = 'click';
        } else if ($.browser.msie && !options.leftClick) {
            mouseEvent = 'contextmenu';
        }
        return me.bind(mouseEvent, function(e) {
            hideMenu();
            var correctButton = ((options.leftClick && e.button == 0) || (options.leftClick == false && e.button == 2));
            if ($.browser.msie)
                correctButton = true;
            if (correctButton) {
                activeElement = $(this);
                if (options.showMenu) {
                    options.showMenu.call(menu, activeElement);
                }
                if (options.hideMenu) {
                    menu.bind("closed", function() {
                        options.hideMenu.call(menu, activeElement);
                    });
                }
                menu.css({visibility: 'hidden',position: 'absolute',zIndex: 1000});
                var mWidth = menu.outerWidth(true), mHeight = menu.outerHeight(true), 
                xPos = ((e.pageX - win.scrollLeft()) + mWidth < win.width()) ? e.pageX : e.pageX - mWidth, 
                yPos = ((e.pageY - win.scrollTop()) + mHeight < win.height()) ? e.pageY : e.pageY - mHeight;
                menu.show(0, function() {
                    hideTooltip();
                    $('body').bind('click', hideMenu);
                }).css({visibility: 'visible',top: yPos + 'px',left: xPos + 'px',zIndex: 1000});
                return false;
            }
        });
    }
})(jQuery); 

 /* fully justify http://davidvandusen.com/fullyjustify/ */
(function($) {
    $.fn.fullyJustify = function(opts) {
        var options = $.extend({}, $.fn.fullyJustify.defaults, opts);
        return this.each(function() {
            $this = $(this);
            dummy = jQuery('<div></div>');
            dummy.html($this.html()).appendTo('body').css({
            	'font-size': (options.properties[0] === 'font-size') ? 1 : $this.css('font-size'),
            	'letter-spacing': (options.properties[0] === 'letter-spacing') ? 0 : $this.css('letter-spacing'),
            	'word-spacing': (options.properties[0] === 'word-spacing') ? 0 : $this.css('word-spacing'),
            	'font-family': $this.css('font-family'),
            	'font-style': $this.css('font-style'),
            	'font-variant': $this.css('font-variant'),
            	'font-weight': $this.css('font-weight'),
            	'text-indent': $this.css('text-indent'),
            	'text-transform': $this.css('text-transform'),
            	'white-space': 'nowrap',
            	'position': 'absolute',
            	'top': 0,
            	'left': -9999});
            for (var i = 0; i < options.properties.length; i++) {
                callback(options.properties[i], dummy, $this.width());
            }
            $this.css({
//            	'letter-spacing': dummy.css('letter-spacing'),
            	'font-size': dummy.css('font-size')
            	});
            dummy.remove();
        });
    };
    function callback(property, dummy, maxWidth) {
        if (property === 'word-spacing' && dummy.text().indexOf(' ') === -1) {
            return true;
        } else if (dummy.width() < maxWidth) {
            oldValue = parseInt(dummy.css(property));
            if (isNaN(oldValue))
                oldValue = 0;
            newValue = oldValue + 1;
            dummy.css(property, newValue);
            if (dummy.width() > maxWidth) {
                dummy.css(property, oldValue);
                return true;
            } else {
                return callback(property, dummy, maxWidth);
            }
        } else {
            return true;
        }
    }
    ;
    $.fn.fullyJustify.defaults = {properties: ['font-size', 'letter-spacing', 'word-spacing']};
})(jQuery); 

/* F U N C T I O N S */
function reLoad() {
    setTimeout(function() {
        location.reload()
    }, 600)
}
function hideTooltip() {
    $('#unitip').hide()
}
function nextPage() { /* N E X T    P A G E */
    showLoad(), hidePreview(), hidePage();
    $('#about').stop().animate({marginLeft: $(window).width()}, 900, 'easeInExpo');
    $('#main').delay(4200).animate({left: 0}, 1200, 'easeOutExpo');
    $('#popup').animate({bottom: -89}, 900, 'easeInBack').delay(4200).animate({bottom: 30}, 900, 'easeInBack');
    $('.navigation').animate({top: -90}, 300, 'easeInExpo').delay(4200).animate({top: -36}, 900, 'easeInBack');
    $('#topshadow').animate({top: -6}, 300, 'easeInExpo')
}
function showAbout() { /* S H O W   A B O U T */
	if ($('#backpage').is(':hidden')) {
		showLoad();
	}	
    $('#scrollabout').animate({top: 0}, 900, 'easeInOutExpo');
    if ($('#closepreview').is(':visible')) { /* B U B B L E   R I G H T C L I C K */
	    hidePreview()
	    }
    $('#main').animate({left: -($(window).width())}, 900, 'easeInExpo', function() {
        $('#aboutContext li a:first span').remove();
        $('#aboutContext li a:first').append('<span class="right">&lt;</span>').removeClass('current');
        $('#aboutContext li a:eq(1)').addClass('current');
        $('.pageicon, #pageinfo, #backup, #backtop').hide();
        $('#backpage').show();
        $('#about').stop().animate({top: 0, marginLeft: 0}, 900, 'easeOutExpo', function() {
        	hideLoad();
        });
    })
}
function hideAbout() { /* H I D E   A B O U T */
    moveTop();
    $('#aboutContext li a:first span').remove();
    $('#aboutContext li a:first').append('<span class="right">^</span>');
    $('#aboutContext li a:eq(1)').removeClass('current');
    $('#about').stop().animate({marginLeft: $(window).width()}, 900, 'easeInExpo', function() {
        $('#main').animate({left: 0}, 900, 'easeInOutExpo');
        $(this).css({top: 0});
        if ($('#header').is(':hidden')) {
            $('.menuicon, #menuinfo').show();
            $('.pageicon, #pageinfo, #backup').hide()
        } else {
            $('.pageicon, #pageinfo, #backup').show()
        }
        $('#backpage, #aboutinfo').hide();
    })
}
function showCard() { /* S H O W   C A R D */
    showModal(), hideKeys();
    $('#hidemodal').show();
    $('#aboutContext li a:eq(2)').addClass('current');
    $('#aboutContext li a:eq(3)').removeClass('current');
    $('#postcard').animate({left: 0, top: 0}, 900, 'easeOutExpo');
    $('input.user-name').focus();
    var theTitle = document.getElementById('dragcard');
    var theCard = document.getElementById('postcard');
    Drag.init(theTitle, theCard)
}
function hideCard() { /* H I D E   C A R D */
    $('#aboutContext li a:eq(2)').removeClass('current');
    $('#postcard').animate({left: - ($(window).width() + 600)}, 900, 'easeInBack');
}
function hideFeedB() { /* H I D E   F E E D B A C K */
    $('#feedback').animate({left: - ($(window).width() + 600)}, 900, 'easeInBack');
}
function editFeedB() {
	hideModal(), hideFeedB(); 
	$('#quicktext').focus();
}
function showPage() {
    $('#pageinfo, #share').show();
    $('#previewinfo, #save').hide();
    $('.preview-title, .preview-description').text('');
    hideLoad();
    $('#main').animate({left: 0}, 900, 'easeOutExpo', function() {
    	$('#topshadow').animate({top: 0}, 300, 'easeInExpo');
        $('#popup').delay(600).animate({bottom: 30}, 900, 'easeOutBack');
        $('#backup').animate({top: - 36}, 900, 'easeOutBack');
    });
}
function hidePage() { /* H I D E   P A G E */
    hideModal(), hideCard(), hideKeys();
    $('#main').animate({left: - ($(window).width())}, 1200, 'easeInExpo');
}
function showMenu() { /* S H O W   M E N U */
    $('#header').stop().animate({marginTop: - ($(window).height())}, 900, 'easeInOutExpo', function() {
        $('#aboutContext li a:first span,#pageContext li a:first span').remove();
        $('#aboutContext li a:first,#pageContext li a:first').addClass('current');
        $('#backup, #backtop, #backpage, #pageinfo, .pageicon').hide();
        $('#backdown, #read, #menuinfo').show();
        moveTop();
    })
}
function hideMenu() { /* H I D E   M E N U */
    $('#header').stop().animate({marginTop: - ($(window).height() * 2)}, 900, 'easeInOutExpo', function() {
        $('#aboutContext li a:first span, #pageContext li a:first span').remove();
        $('#aboutContext li a:first, #pageContext li a:first').removeClass('current').append('<span class="right">^</span>');
        $('#backup, #pageinfo, .pageicon').show();
        $('#backdown, #read, #menuinfo').hide()
    })
}
function showModal() {
    $('#mymodal').fadeIn(600)
}
function hideModal() {
    $('#mymodal').fadeOut(600);
    $('#hidemodal').hide()
}
function showLoad() {
    $('#loading').fadeIn(300)
}
function hideLoad() {
    $('#loading').fadeOut(300)
}
function hideOverlay() {
    if ($('#mymodal').is(':visible')) {
        hideModal(), hideCard(), hideKeys();
        $('#aboutContext li a:eq(2), #aboutContext li a:eq(3)').removeClass('current');
    } else {
        hideAbout();
    }
}
function moveTop() {
    $('.scrollable').animate({top: 0}, 900, 'easeInOutExpo');
    $('#backtop').hide()
}
function hidePreview() { /* H I D E   P R E V I E W */
    var $largeImg = $('#fp_preview');
    var imgW = $largeImg.width();
    $('#fp_preview, #pixelpage').stop().animate({left: - imgW - 18}, 900, 'easeInOutExpo', function() {
        $('#fp_preview, #pixelpage').remove();
        $('#fp_next').stop().animate({right: -150}, 900, 'easeInOutBack');
        $('#fp_prev').stop().animate({left: -150}, 900, 'easeInOutBack');
        $('#fp_overlay').fadeOut(300);
        $('#fp_loading').removeClass('visible').fadeOut(150);
        $('.preview-title, .preview-description').text('');
        $('img.preview-thumb').removeAttr('src').hide();
        $('#closepreview, #save').hide();
		if ($('#header').is(':visible')) {
		    $('#backup, .pageicon').show()
		    } else {
	    	$('#pageinfo, #backup').hide()
		    }
    })
}
function showKeys() { /* S H O W   K E Y S */
    showModal(), hideCard();
    $('#hidemodal').show();
    $('#keyboard').animate({top: 0,left: 0}, 900, 'easeInOutExpo');
    $('#aboutContext li a:eq(3)').addClass('current');
    $('#aboutContext li a:eq(2)').removeClass('current');
    var theMargin = document.getElementById('dragkeyboard');
    var theKeys = document.getElementById('keyboard');
    Drag.init(theMargin, theKeys)
}
function hideKeys() {
    $('#keyboard').stop().animate({top: $(window).height() + 600}, 900, 'easeInExpo');
    $('#aboutContext li a:eq(3)').removeClass('current')
}
function getTitles() {
    $('img.thumb').each(function() {
        var $thumbImg = $(this);
        var $thumbName = $(this).parents('a').attr('title');
        var $nextTitle = $thumbImg.parents('.content').nextAll().find('a').attr('title');
        var $prevTitle = $thumbImg.parents('.content').prevAll().find('a').attr('title');
        $thumbImg.attr('name', $thumbName);
        $thumbImg.attr('livesrc', $nextTitle);
        $thumbImg.attr('usemap', $prevTitle)
    })
}

$(document).keydown(function(e) {
    if (e.which == 27) { /* E S C A P E */
        e.preventDefault();
        hideModal(), hideCard(), hideKeys(), hidePreview(), hideAbout(), hideMenu()
    }
    if (e.which == 36) { /* H O M E */
        e.preventDefault();
        hideModal(), hideCard(), hideKeys(), hidePreview(), hideAbout(), showMenu();
        $('#main').delay(900).animate({left: 0}, 900, 'easeOutExpo');
        showPage();
    }
    if (e.which == 35) { /* E N D */
        e.preventDefault();
        hideModal(), hidePreview(), hideCard(), hideKeys(), moveTop(), hideMenu()
    }
    if (e.which == 112) { /* F 1 */
        e.stopPropagation();
        e.preventDefault();
        showKeys()
    }
    if (e.which == 113 && $('.showhelp').is(':hidden') && $('.showmouse').is(':visible')) { /* F 2 */
        e.preventDefault();
        chooseStyle('showmouse', 30);
        return true
    }
    if (e.which == 113 && $('.showhelp').is(':hidden') && $('.showmouse').is(':hidden')) {
        e.preventDefault();
        chooseStyle('hidemouse', 30);
        return true
    }
    if (e.which == 113 && $('.showhelp').is(':visible') && $('.showmouse').is(':visible')) {
        e.preventDefault();
        chooseStyle('hidehelp', 30);
        return true
    }
    if (e.which == 113 && $('.showhelp').is(':visible') && $('.showmouse').is(':hidden')) {
        e.preventDefault();
        chooseStyle('hidemousehidehelp', 30);
        return true
    }
});

function reSize() { /* R E S I Z E */
	var winW = $(window).width();
	var winH = $(window).height();
	var winWS = winW - 40;
	var bodyW = winWS - winWS % 160;
	var leftW = winW / 2 - bodyW / 2;
//	var imgNr = bodyW / 160 - 3;
//	var imgSpace = 320 / imgNr;

var imgNr = (bodyW - 480) / 160 + 1;
var imgSpace = 160 / imgNr;

//	var imgSpace = (bodyW % 24) * (bodyW / 420) + 40;
	
		$('.bodyW').width(bodyW);
		$('.winW').width(winW);
		$('.winH').height(winH).css({minHeight: winH, maxHeight: winH});
		$('.leftW').css({left: leftW});
		$('.rightW').css({right: leftW});
		$('.marginR').css({marginRight: leftW});
		$('.marginL').css({marginLeft: leftW});
		$('#slidemenu').css({marginLeft: - leftW});
		$('.screen').css({paddingLeft: leftW, paddingRight: leftW});
		$('#fp_gallery .content').css({marginRight: imgSpace});
		$('#fp_gallery').width(bodyW + imgSpace * 2);
		if (bodyW < 1120) {
			$('.no960').hide();
			} else {
			$('.no960').show();
			}
		$('.absmiddle').each(function() {
			var $this = $(this);
			var absmidH = $this.height();
			var absmidW = $this.width();
			$this.css({marginTop: winH / 2 - absmidH / 2, marginLeft: winW / 2 - absmidW / 2})
		});
		$('.coda-nav').css({fontSize: bodyW / 8.08, lineHeight: bodyW / 6.77 + 'px', letterSpacing: -bodyW / 266}).height(bodyW / 6.77);
		$('.coda-slider .menu').css({marginTop: winH / 2});
	var menuH = $('.coda-nav').height();
		$('.coda-nav').css({marginTop: winH / 2 - menuH});
		$('.menuinfo').css({top: winH - 40});
		$('h2.title').css({fontSize: bodyW / 16, letterSpacing: - bodyW / 320});

	var sparkSize = winH / 3.88;
		$("a.mysparks").width(sparkSize + 6).css({fontSize: sparkSize * 1.21, marginLeft: bodyW + leftW - winH / 1.77 - sparkSize, top: winH / 1.60});
		$("a.pricetag").css({marginLeft: bodyW + leftW - 180, top: winH / 1.50});

		$('.dummy').css({fontSize: bodyW / 7.11, letterSpacing: -bodyW / 213, marginLeft: - bodyW / 213});
		$('.workshop').css({fontSize: bodyW / 9.88, letterSpacing: -bodyW / 320, marginLeft: - bodyW / 320});
		$('.years').css({fontSize: bodyW / 13.11, letterSpacing: -bodyW / 426, marginLeft: - bodyW / 426});
		$('.experience').css({fontSize: bodyW / 16.99, letterSpacing: -bodyW / 640, marginLeft: - bodyW / 640});
		$('.services').css({fontSize: bodyW / 19.22, letterSpacing: -bodyW / 640, marginLeft: - bodyW / 960});
		$('.more').css({fontSize: bodyW / 12.33, letterSpacing: - bodyW / 240, marginLeft: - bodyW / 213});

	var thirdW = bodyW / 3 - 20;
		$('.group .paragraph').width(thirdW - 2);
		$('.paragraph .textbox').width(thirdW - 18);
		$('.paragraph .textbox textarea').width(thirdW - 28).css({minWidth: thirdW - 28, maxWidth: thirdW - 28});
		$('.feedback li p').width(thirdW - 50);

		$('.group .paragraph:nth-child(1), .group .paragraph:nth-child(3)').width(thirdW);
		$('.sixth').width((bodyW - 155) / 6);
		$('#googlesearch input.text').width(thirdW - 144);

		$('.frame').css({paddingRight: leftW}); // A B O U T   A F T E R   H E A D L I N E   R E S I Z E !
	var frameH = winH - winH % 100;
		$('#frameabout').height(frameH);
	var scrollH = $('#aboutcontent').height();
	var scrollCut = scrollH - scrollH % 100;
		$('#scrollabout').height(scrollCut - frameH + 100);
            
		$('.fullsize').each(function() {
			var $this = $(this);
			var textW = $this.width();
			var charNr = $this.text().length;
			$this.css({letterSpacing: - textW / charNr / 8}).fullyJustify();
		});
	var fbTitle = $('#fbtitle').height();
	var formTitle = $('#fbform h2.fullsize').height();
		$('#quicktext').css({minHeight: fbTitle - formTitle - 120, height: fbTitle - formTitle - 120});
		$('#fblist').height(fbTitle);

	$('#fblist li').each(function() {
		var $this = $(this);
		var listP = $('#fblist').position();
		var liP = $this.position();
		var liH = $this.height();
		if (liP.top + liH - listP.top > fbTitle) {
			$this.hide()
		} else {
			$this.show()
		}
	});

	$('#designmenu').css({marginLeft: ($('.coda-nav ul li.tab2').position()).left + leftW + 18});
	$('#stockmenu').css({marginLeft: ($('.coda-nav ul li.tab3').position()).left + leftW});
}

$().ready(function() { /* C U S T O M   F O R   http://loremipsum.ro */
    var winW = $(window).width();
    var winH = $(window).height();
    $('.container a').wrap('<div class="content left center"><div>');
    $('#header').css({marginTop: - winH * 2});

    $('#menuContext li a:first').addClass('current');
    $('#menuContext li a:last').append('<span class="right">_</span>');
    $('#pageContext li a:first,#aboutContext li a:first').append('<span class="right">^</span>');
    $('#aboutContext li:last a').append('<span class="right">&#215;</span>');
    $('#previewContext li:first a').addClass('fp_next').append('<span class="right">&gt;</span>');
    $('#previewContext li a:eq(1)').addClass('fp_prev').append('<span class="right">&lt;</span>');
    $('#previewContext li:last a').addClass('fp_close').append('<span class="right">&#215;</span>');
    $('.context-menu').addClass('shadow border big title42');

    $('#fp_thumbContainer img').each(function() {
        var imgNr = $(this).parents('#frame').find('img').index(this) + 1;
        var aTitle = $(this).parent('a').attr('title');
        var imgClass = $(this).attr('class').replace('thumb', '').replace('noprev', '').replace('nonext', '').replace(' ', '');
        var filterThis = "show" + imgClass;
        var newClass = imgClass.replace('sale', 'Sale').replace('sold', 'Sold').replace('mine', 'Personal').replace('ill', 'Work').replace('sketch', 'Sketch').replace('cartoon', 'Cartoon').replace('analog', 'Analog').replace('digital', 'Digital').replace('mixed', 'Mixed').replace('painting', 'Painting').replace('drawing', 'Drawing').replace('collage', 'Collage').replace('analysis', 'Scan').replace('logo', 'Logo').replace('book', 'Book').replace('brand', 'Brand').replace('print', 'Print').replace('web', 'Web').replace('press', 'Press').replace('poster', 'Poster').replace('pack', 'Pack').replace('wordPress', 'CMS').replace('layout', 'Design').replace('html', 'Dev');
        $(this).parents('.content div').after("<div class='limited gray'><span class='imgNr'>" + imgNr + ". </span><span class='thumbtitle'>" + aTitle + "</span></div><a class='gray caps category " + filterThis + "' title='Filter " + newClass + "'><span>" + newClass + "</span></a>");
    });
    $('a, .post img').addClass('tooltip');
    $('.content img').addClass('thumb');
    $('.menu a, h1 a, h3 a').addClass('alpha');

    $('a.blank, .blank a').click(function() {
        var blankLink = $(this).attr('target');
        window.open(blankLink)
    });
    $('a.self').bind('click', function() {
        selfLink = $(this).attr('target');
        $(this).attr('href', selfLink)
    });
    $('.hidemouse').click(function() {
        if ($('.hidehelp').is(':visible')) {
            chooseStyle('hidemouse', 30)
        } else {
            chooseStyle('hidemousehidehelp', 30)
        }
    });
    $('.showmouse').click(function() {
        if ($('.hidehelp').is(':visible')) {
            chooseStyle('none', 30)
        } else {
            chooseStyle('hidehelp', 30)
        }
    });
    $('.hidehelp').click(function() {
        if ($('.hidemouse').is(':visible')) {
            chooseStyle('hidehelp', 30)
        } else {
            chooseStyle('hidemousehidehelp', 30)
        }
    });
    $('.showhelp').click(function() {
        if ($('.hidemouse').is(':visible')) {
            chooseStyle('none', 30)
        } else {
            chooseStyle('hidemouse', 30)
        }
    });
    $('#trash').click(function() {
		chooseStyle('none', 30)
    });
    $('body').bind('mousewheel click rightclick', function() {
        hideTooltip()
    });
    $('img.thumb').click(function() {
        $('#pageinfo').hide();
        $('#previewinfo, #save').show();
        $('#main').animate({left: - winW}, winW / 2, 'easeInExpo', function() {
            $('#fp_loading').fadeIn(300);
            $('.navigation, #share').hide();
            $('#closepreview').show()
        })
    });
    $('.fp_close').click(function() {
        $('img.preview-thumb').removeAttr('src')
    });
    $('.nextpage').click(function(e) {
        e.preventDefault();
        nextPage();
        var destination = $(this).attr('target');
        setTimeout(function() {
            window.location.href = destination
        }, 1200)
    });
    $('.content .category, .content .limited').click(function() {
        hidePreview();
        $('#fp_preview').remove()
    });
    $('.limited').each(function() {
        var limit = 18;
        var chars = $(this).text();
        if (chars.length > limit) {
            var visiblePart = $("<span> " + chars.substr(0, limit - 1) + "</span>");
            var dots = $("<span class='dots'>...</span>");
            $(this).empty().append(visiblePart).append(dots)
        }
    });
    $('#popup').bind('mouseenter', function() {
        var $lastIcon = $('#popup .icon:visible:last');
        var linkNr = $('#popup').find('.icon:visible').size();
        var bubbleW = 140 * linkNr - 20;
        $(this).find('.links, .intro, .preview-title').css({width: bubbleW});
        $('.links').css({width: bubbleW + 20});
        if (linkNr <= 3) {
        	$('.iffouricon').hide();
        } else {
        	$('.iffouricon').show();
        }
    });
    $('#about').bind('mouseenter', function() {
		$('.menuicon, #menuinfo, .pageicon, #pageinfo').hide();
		$('#aboutinfo').show();
    });
    $('#backtop').click(function() {
        moveTop();
        $('#backup').show()
    });
    $('#backpage').click(function() {
        hideAbout(), hideMenu();
        $(this).hide();
        $('#backup').show()
    });
    $labels = $('#postcard, #card, #mycommentform').find('label');
    $labels.find('input.text').each(function(i) {
        var $this = $(this);
        var labelW = $this.parents('label').width();
        var spanW = $this.parents('label').children('span').width();
        $this.css({paddingLeft: spanW + 24, width: labelW - spanW - 34})
    });  

}); /* E N D   R E A D Y */


$(window).load(function() {
	reSize(), showPage();
});

$(window).resize(function() {
    reSize(); 
    var winH = $(window).height();
    var winW = $(window).width();
    var bodyW = $('#main').width();
    var minLeft = bodyW - winW;
    if ($('#backpage').is(':hidden')) {
        $('#about').css({marginLeft: winW})
    } else {
        $('#about').stop().animate({marginLeft: 0}, 900, 'easeInOutExpo')
    }
    if (($('#backpage').is(':visible')) || ($('#closepreview').is(':visible'))) {
    	if (winW < bodyW) {$('#main').css({left: - bodyW - minLeft})
    		} else {$('#main').css({left: - winW})
    		}
    } else {
        $('#main').css({left: 0})
    }
    if ($('#backdown').is(':hidden')) {
        $('#header').css({marginTop: - winH * 2})
    } else {
        $('#header').css({marginTop: - winH})
    }
    
    var fbTitle = $('#fbtitle').height();
	var formTitle = $('#fbform h2.fullsize').height();
	$('#quicktext').css({minHeight: fbTitle - formTitle - 120, height: fbTitle - formTitle - 120});
	$('#fblist').height(fbTitle);
});

