// Javascrip Hover Effect
$(document).ready(function(){
    
    hellopage_init();
    
    // preload images
    preload([
        '/wp/wp-content/themes/gabix/hello-page/hellofrog_03.png'
    ]);
    

	$('.portfolio-contenthma img, .portfolio-contenthm img').fadeTo('medium', 1.0);
	$('.portfolio-contenthma img, .portfolio-contenthm img').hover(function(){
			$(this).fadeTo('medium', 0.3);
		}, function(){
			$(this).fadeTo('medium', 1.0);
		});
	$('.port-thumba img, .port-thumb2a img').fadeTo('medium', 1.0);
	$('.port-thumba img, .port-thumb img, .port-thumb2a img, .port-thumb2 img').hover(function(){
			$(this).fadeTo('medium', 0.3);
		}, function(){
			$(this).fadeTo('medium', 1.0);
		});
	
	$('.tumblr_post a').attr('href', 'http://yeahsnos.tumblr.com/');
});

function preload(arrayOfImages) {
    $(arrayOfImages).each(function(){
        $('<img/>')[0].src = this;
    });
}

// Hellopage script for Yasaman's portfolio
function hellopage_init() {
    
    // edit list of names here. last item should NOT have a comma
    var names = ['frog', 'ideo'];
    var name = null;

    // check for hash from list of names
    for (var n = 0; n < names.length; n++) {
        if (location.hash.indexOf(names[n]) != -1) {
            name = names[n];
            break;
        }
    }
        
    if (name) {     
        hellopage_load(name);
        $('#hellopagebutton').click(hellopage_hide);
        $('#hellopagebar').click(hellopage_show).hide();
        $('#hellopage').hide();
        $('a').each(function() {
            if (this.hostname == location.hostname && this.href.indexOf('#' + name) == -1) {
                this.href = this.href + '#' + name;
            }
        });
        if (location.pathname != '/portfolio/') {
            $('body').append('<a href="/portfolio/#' + name + '" id="portfolio-back">Back</a>');
        }
        
    }
    
    if (location.hash == '#' + name + '-hello') {
        hellopage_show();
    }
    
    if (location.hash == '#' + name) {
        $('#hellopage').hide();
        hellopage_hide();
    }
    
}

function hellopage_load(name) {
    $('body').prepend('<div id="hellopage-container"></div>');
    $('#hellopage-container').append(
        '<a href="#' + name + '-hello" id="hellopagebar">Hello ' + name + '.</a><div id="hellopage"><img src="/wp/wp-content/themes/gabix/hello-page/hello' + name + '_01.png"><a href="#' + name + '" id="hellopagebutton"></a></div>'
    ).css('height', 'auto');
}

function hellopage_hide() {
    scrollTo(0, 0);
    $('#hellopage').slideUp('slow', function() {
        $('#hellopagebar').slideDown().css('display', 'block');
    });
    $('#hellopage-container').css('position', 'relative');
}

function hellopage_show() {
    $('#hellopage').slideDown('slow');
    $('#hellopagebar').slideUp();
    $('#hellopage-container').css('position', 'absolute');
}

