// Page Transitions

// Main -> Interior
$(function() {
	$('a#interior').click(function() {
		$('div#main-room').fadeOut(500, function() {
			$('div#interior-room').fadeIn(500);
		});    
		
  	});
});

// Interior -> TV
$(function() {
	$('a#tv').click(function() {
		$('div#interior-room').fadeOut(500, function() {
			$('div#tv-room').fadeIn(500);
		});    
		
  	});
});

//Interior -> TV (second link to TV)
$(function() {
	$('a#tv2').click(function() {
		$('div#interior-room').fadeOut(500, function() {
			$('div#tv-room').fadeIn(500);
		});    
		
  	});
});

// Interior -> Computer
$(function() {
	$('a#computer').click(function() {
		$('div#interior-room').fadeOut(500, function() {
			$('div#computer-room').fadeIn(500);
		});    
		
  	});
});

// Interior -> IPod
$(function() {
	$('a#ipod').click(function() {
		$('div#interior-room').fadeOut(500, function() {
			$('div#ipod-room').fadeIn(500);
		});    
		
  	});
});

// Interior -> Main
$(function() {
	$('a#main').click(function() {
		$('div#interior-room').fadeOut(500, function() {
			$('div#main-room').fadeIn(500);
		});    
		
  	});
});

// TV -> Interior
$(function() {
	$('a#tv2int').click(function() {
		$('div#tv-room').fadeOut(500, function() {
			$('div#interior-room').fadeIn(500);
		});    
		
  	});
});

// Computer -> Interior
$(function() {
	$('a#cpu2int').click(function() {
		$('div#computer-room').fadeOut(500, function() {
			$('div#interior-room').fadeIn(500);
		});    
		
  	});
});

// Ipod -> Interior
$(function() {
	$('a#ipod2int').click(function() {
		$('div#ipod-room').fadeOut(500, function() {
			$('div#interior-room').fadeIn(500);
		});    
		
  	});
});



// Menu Tabs

$(document).ready(function() {
	$("div.panel_button").click(function(){
		$("div#panel").animate({
			height: "350px"
		})
		.animate({
			height: "340px"
		}, "fast");
		$("div.panel_button").toggle();
	
	});	
	
   $("div#hide_button").click(function(){
		$("div#panel").animate({
			height: "0px"
		}, "fast");
		
	
   });	
	
});


$(document).ready(function() {
	$("div.panel_button2").click(function(){
		$("div#panel2").animate({
			height: "210px"
		})
		.animate({
			height: "200px"
		}, "fast");
		$("div.panel_button2").toggle();
	
	});	
	
   $("div#hide_button2").click(function(){
		$("div#panel2").animate({
			height: "0px"
		}, "fast");
		
	
   });	
	
});


// Popup Bubble ======================================================

// Bubble About
$(function () {
    $('.bubbleInfo-about').each(function () {
        var distance = 10;
        var time = 150;
        var hideDelay = 100;

        var hideDelayTimer = null;

        var beingShown = false;
        var shown = false;
        var trigger = $('.trigger', this);
        var info = $('.popup', this).css('opacity', 0);


        $([trigger.get(0), info.get(0)]).mouseover(function () {
            if (hideDelayTimer) clearTimeout(hideDelayTimer);
            if (beingShown || shown) {
                // don't trigger the animation again
                return;
            } else {
                // reset position of info box
                beingShown = true;

                info.css({
                    top: 70,
                    left: 30,
                    display: 'block'
                }).animate({
                    top: '-=' + distance + 'px',
                    opacity: 1
                }, time, 'swing', function() {
                    beingShown = false;
                    shown = true;
                });
            }

            return false;
        }).mouseout(function () {
            if (hideDelayTimer) clearTimeout(hideDelayTimer);
            hideDelayTimer = setTimeout(function () {
                hideDelayTimer = null;
                info.animate({
                    top: '-=' + distance + 'px',
                    opacity: 0
                }, time, 'swing', function () {
                    shown = false;
                    info.css('display', 'none');
                });

            }, hideDelay);

            return false;
        });
    });
});

// Bubble Ethiopia
$(function () {
    $('.bubbleInfo-ethiopia').each(function () {
        var distance = 10;
        var time = 150;
        var hideDelay = 100;
        var hideDelayTimer = null;
        var beingShown = false;
        var shown = false;
        var trigger = $('.trigger', this);
        var info = $('.popup', this).css('opacity', 0);
        $([trigger.get(0), info.get(0)]).mouseover(function () {
            if (hideDelayTimer) clearTimeout(hideDelayTimer);
            if (beingShown || shown) {
                // don't trigger the animation again
                return;
            } else {
                // reset position of info box
                beingShown = true;

                info.css({
                    top: -100,
                    left: -350,
                    display: 'block'
                }).animate({
                    top: '-=' + distance + 'px',
                    opacity: 1
                }, time, 'swing', function() {
                    beingShown = false;
                    shown = true;
                });
            }

            return false;
        }).mouseout(function () {
            if (hideDelayTimer) clearTimeout(hideDelayTimer);
            hideDelayTimer = setTimeout(function () {
                hideDelayTimer = null;
                info.animate({
                    top: '-=' + distance + 'px',
                    opacity: 0
                }, time, 'swing', function () {
                    shown = false;
                    info.css('display', 'none');
                });

            }, hideDelay);

            return false;
        });
    });
});

// Bubble China
$(function () {
    $('.bubbleInfo-china').each(function () {
        var distance = 10;
        var time = 150;
        var hideDelay = 100;
        var hideDelayTimer = null;
        var beingShown = false;
        var shown = false;
        var trigger = $('.trigger', this);
        var info = $('.popup', this).css('opacity', 0);
        $([trigger.get(0), info.get(0)]).mouseover(function () {
            if (hideDelayTimer) clearTimeout(hideDelayTimer);
            if (beingShown || shown) {
                // don't trigger the animation again
                return;
            } else {
                // reset position of info box
                beingShown = true;

                info.css({
                    top: -50,
                    left: -350,
                    display: 'block'
                }).animate({
                    top: '-=' + distance + 'px',
                    opacity: 1
                }, time, 'swing', function() {
                    beingShown = false;
                    shown = true;
                });
            }

            return false;
        }).mouseout(function () {
            if (hideDelayTimer) clearTimeout(hideDelayTimer);
            hideDelayTimer = setTimeout(function () {
                hideDelayTimer = null;
                info.animate({
                    top: '-=' + distance + 'px',
                    opacity: 0
                }, time, 'swing', function () {
                    shown = false;
                    info.css('display', 'none');
                });

            }, hideDelay);

            return false;
        });
    });
});

// Bubble Korea
$(function () {
    $('.bubbleInfo-korea').each(function () {
        var distance = 10;
        var time = 150;
        var hideDelay = 100;
        var hideDelayTimer = null;
        var beingShown = false;
        var shown = false;
        var trigger = $('.trigger', this);
        var info = $('.popup', this).css('opacity', 0);
        $([trigger.get(0), info.get(0)]).mouseover(function () {
            if (hideDelayTimer) clearTimeout(hideDelayTimer);
            if (beingShown || shown) {
                // don't trigger the animation again
                return;
            } else {
                // reset position of info box
                beingShown = true;

                info.css({
                    top: -70,
                    left: -350,
                    display: 'block'
                }).animate({
                    top: '-=' + distance + 'px',
                    opacity: 1
                }, time, 'swing', function() {
                    beingShown = false;
                    shown = true;
                });
            }

            return false;
        }).mouseout(function () {
            if (hideDelayTimer) clearTimeout(hideDelayTimer);
            hideDelayTimer = setTimeout(function () {
                hideDelayTimer = null;
                info.animate({
                    top: '-=' + distance + 'px',
                    opacity: 0
                }, time, 'swing', function () {
                    shown = false;
                    info.css('display', 'none');
                });

            }, hideDelay);

            return false;
        });
    });
});

// Bubble Haiti
$(function () {
    $('.bubbleInfo-haiti').each(function () {
        var distance = 10;
        var time = 150;
        var hideDelay = 100;

        var hideDelayTimer = null;

        var beingShown = false;
        var shown = false;
        var trigger = $('.trigger', this);
        var info = $('.popup', this).css('opacity', 0);


        $([trigger.get(0), info.get(0)]).mouseover(function () {
            if (hideDelayTimer) clearTimeout(hideDelayTimer);
            if (beingShown || shown) {
                // don't trigger the animation again
                return;
            } else {
                // reset position of info box
                beingShown = true;

                info.css({
                    top: -20,
                    left: 30,
                    display: 'block'
                }).animate({
                    top: '-=' + distance + 'px',
                    opacity: 1
                }, time, 'swing', function() {
                    beingShown = false;
                    shown = true;
                });
            }

            return false;
        }).mouseout(function () {
            if (hideDelayTimer) clearTimeout(hideDelayTimer);
            hideDelayTimer = setTimeout(function () {
                hideDelayTimer = null;
                info.animate({
                    top: '-=' + distance + 'px',
                    opacity: 0
                }, time, 'swing', function () {
                    shown = false;
                    info.css('display', 'none');
                });

            }, hideDelay);

            return false;
        });
    });
});

// Bubble Nolan
$(function () {
    $('.bubbleInfo-nolan').each(function () {
        var distance = 10;
        var time = 150;
        var hideDelay = 100;
        var hideDelayTimer = null;
        var beingShown = false;
        var shown = false;
        var trigger = $('.trigger', this);
        var info = $('.popup', this).css('opacity', 0);
        $([trigger.get(0), info.get(0)]).mouseover(function () {
            if (hideDelayTimer) clearTimeout(hideDelayTimer);
            if (beingShown || shown) {
                // don't trigger the animation again
                return;
            } else {
                // reset position of info box
                beingShown = true;

                info.css({
                    top: -200,
                    left: -350,
                    display: 'block'
                }).animate({
                    top: '-=' + distance + 'px',
                    opacity: 1
                }, time, 'swing', function() {
                    beingShown = false;
                    shown = true;
                });
            }

            return false;
        }).mouseout(function () {
            if (hideDelayTimer) clearTimeout(hideDelayTimer);
            hideDelayTimer = setTimeout(function () {
                hideDelayTimer = null;
                info.animate({
                    top: '-=' + distance + 'px',
                    opacity: 0
                }, time, 'swing', function () {
                    shown = false;
                    info.css('display', 'none');
                });

            }, hideDelay);

            return false;
        });
    });
});


