
function changeimg(obj,img){
	obj.src = 'pics/' + img;
}

function setPartnerPic(sid,type){
	if(type==1){
		$('#partner_'+sid).animate({top:-80},0);
	}else{
		$('#partner_'+sid).animate({top:0},0);
	}	
}
function setawardsPic(sid,type){
	if(type==1){
		$('#awards_'+sid).animate({top:-55},0);
	}else{
		$('#awards_'+sid).animate({top:0},0);
	}	
}

function setMenu(sid){
	if(!first){
		if(vid == sid) return;
	}else{
		first = false;
	}
	$("*[rel='menu']").animate({top:0},0);
	$('#menu'+sid).animate({top:-58},0);
	$('#propic').animate({top:-355},0);		
	$('#propic').html('<img src="images/pro'+sid+'.jpg"/><img src="images/pro'+vid+'.jpg"/>');
	$('#propic').animate({top:0},1000);
	$('#menu'+vid).mouseenter(function() {$(this).animate({top:-58},0);});
	$('#menu'+vid).mouseleave(function() {$(this).animate({top:0},0);});
	vid = sid;
	$('#menu'+sid).unbind('mouseenter');
	$('#menu'+sid).unbind('mouseleave');
}

$(function() {
	$("*[rel='awards']").mouseenter(function() {$(this).animate({top:-55},0);});
	$("*[rel='awards']").mouseleave(function() {$(this).animate({top:0},0);});
	$("*[rel='partners']").mouseenter(function() {$(this).animate({top:-80},0);});
	$("*[rel='partners']").mouseleave(function() {$(this).animate({top:0},0);});
	$("*[rel='contact']").mouseenter(function() {$(this).animate({top:-25},0);});
	$("*[rel='contact']").mouseleave(function() {$(this).animate({top:0},0);});

});

var showreel = {
    dur: 800,
    pulse: 10 * 1000,
    easing: 'swing',
    play: true,
    playing: false,
    cur: 0,
    reel: [],
    imgs: [],
    timer: null,
    cb: null,
    init: function() {
        if (showreel.reel.length < 2) return false;
        $.each(showreel.reel,
        function(i, a) {
            i && $('#show-images').append('<a href="' + a.url + '">' + (i == 1 ? '<img src="' + a.image + '" title="' + a.alt + '" />': '') + '</a>')
        });
        showreel.imgs = $('#show-images a');
        $('#show').append('<div id="show-controls"></div>');
		$('#show').addClass('position:relative;');
        showreel.imgs.css({
            top: 0,
            left: $('#show').width() + 2,
            position: 'absolute'
        }).each(function(i) {
            $('#show-controls').append('<a id="dimple-' + i + '" class="dimple" href="#" onclick="showreel.move_to(' + i + ',true);return false;">&nbsp;</a>')
        }).slice(0, 1).css({
            left: 0
        });
        $('#show-controls').width(showreel.imgs.length * 22);
        $('#dimple-0').addClass('dimpleon');
        if (showreel.play) showreel.timer = window.setTimeout(showreel.move_next, showreel.pulse * 1.5)
    },
    move_next: function() {
        showreel.move_to(showreel.cur >= showreel.imgs.length - 1 ? 0 : showreel.cur + 1, false);
        showreel.load_image(showreel.cur + 1)
    },
    move_to: function(n, click) {
        if (showreel.playing || n == showreel.cur) return false;
        showreel.playing = true;
        showreel.load_image(n);
        click && showreel.load_image(n + 1);
        window.clearTimeout(showreel.timer);
        if (showreel.play) showreel.timer = window.setTimeout(showreel.move_next, showreel.pulse);
        $('.dimple', '#show-controls').removeClass('dimpleon').filter('#dimple-' + n).addClass('dimpleon');
        $c = showreel.imgs.slice(showreel.cur, showreel.cur + 1);
        $n = showreel.imgs.slice(n, n + 1);
        if ($c.is(':animated')) {
            $c.stop(false, true);
            showreel.cb.stop(false, true)
        }
        $c.css({
            zIndex: 10
        }).stop().animate({
            opacity: 0.2,
            left: -($('#show').width() / 2)
        },
        showreel.dur, showreel.easing,
        function() {
            $(this).css({
                left: $('#show').width(),
                opacity: 1
            });
            showreel.playing = false
        });
        $n.css({
            zIndex: 100
        }).stop().animate({
            left: 0
        },
        showreel.dur, showreel.easing,
        function() {
            showreel.playing = false
        });
        showreel.cur = n;
        showreel.cb = $c
    },
    toggle_play: function() {
        showreel.play = !showreel.play;
        $('#toggle-play').toggleClass('paused');
        window.clearTimeout(showreel.timer);
        if (showreel.play) showreel.timer = window.setTimeout(showreel.move_next, showreel.pulse)
    },
    load_image: function(n) {
        if (showreel.imgs.slice(n, n + 1).html() == '') {
            showreel.imgs.slice(n, n + 1).html('<img src="" alt="" style="display:none;" />').find('img').load(function() {
                $(this).show()
            }).error(function() {
                $(this).attr('src', showreel.reel[n].image)
            }).attr('src', showreel.reel[n].image)
        }
    }
};
