﻿$(document).ready(function () {
    $(function () {
        $(window).bind('load', function () {
            $('#homeBanner .col2 #playVideo').fadeIn();
        });
    });

    $('#playVideo,#replayVideo').click(function () {

        if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
           
            setYoutubeSource();
        } else if (swfobject.hasFlashPlayerVersion('1')) {
            PlayVideo();
        } else {
            HasNoFlash();
        }
    });


    if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
        $('#index #videoWrap').css('display', 'block');
    } else {
        var flashvars = {
            'wmode': 'transparent',
            'allowfullscreen': 'true'
        };
        var params = {
            'name': 'video',
            'allowscriptaccess': 'always',
            'allowfullscreen': 'true'
        };
        var attributes = false;
        swfobject.embedSWF('/Resources/flash/wca.swf', 'video', '960', '570', '9.0.0', '/Resources/js/swfobject/expressInstall.swf', attributes, flashvars, params);
    }

    $('#contentTop .wrap #packages .dataColumn:nth-child(5)').addClass('bestSeller');
    $('#contentTop .wrap #packages .packageLabels li:nth-child(2n), #contentTop .wrap #packages .dataColumn li:nth-child(2n+1)').css('background', '#ffffff');
});


function getFlashMovie(movieName) {
    if (navigator.appName.indexOf('Microsoft') != -1) {
        return window[movieName];
    } else {
        return document[movieName];
    }
}

function setMovieSource(id) {
    var movie = getFlashMovie(id);
    movie.setMovieSource('wca.f4v');
}

function PlayVideo() {
    $('#contentTop .wrap #homeBanner').animate({
        'opacity': 0
    }, {
        duration: 500,
        easing: 'easeOutExpo'
    });
    $('#drawHeight').animate({
        'height': '250'
    }, {
        duration: 500,
        specialEasing: {
            easing: 'easeOutExpo'
        },
        complete: function () {
            $('#videoWrap').animate({
                'width': '960px'
            }, {
                duration: 1000,
                easing: 'easeOutExpo'
            });
        }
    });

    $('#endScreen').fadeOut(800, 'easeOutExpo');
    $('#contentTop .wrap #endScreen .bottom #replayVideo').delay(500).animate({
        'bottom': '-45px'
    }, {
        duration: 800,
        easing: 'easeOutExpo'
    });
    $('#contentTop .wrap #endScreen .bottom .social').delay(1000).animate({
        'right': '-165px'
    }, {
        duration: 800,
        easing: 'easeOutExpo'
    });
    setMovieSource('video');
}


function HasNoFlash() {
    $('#contentTop .wrap #homeBanner').animate({
        'opacity': 0
    }, {
        duration: 500,
        easing: 'easeOutExpo'
    });
    $('#drawHeight').animate({
        'height': '0'
    }, {
        duration: 500,
        specialEasing: {
            easing: 'easeOutExpo'
        },
        complete: function () {
            $('#videoWrap').animate({
                'width': '960px'
            }, {
                duration: 1000,
                easing: 'easeOutExpo'
            });
        }
    });
    $('#alternateContents').css('display', 'block');
}


function SetScreenToDefault() {
    $('#videoWrap').animate({
        'width': '0'
    }, {
        duration: 500,
        specialEasing: {
            easing: 'easeOutExpo'
        },
        complete: function () {
            $('#drawHeight').animate({
                'height': '0px'
            }, {
                duration: 1000,
                easing: 'easeOutExpo'
            });
            $('#contentTop .wrap #homeBanner').animate({
                'opacity': 1
            }, {
                duration: 500,
                easing: 'easeOutExpo'
            });
        }
    });
}

function ShowEndScreen() {
    $('#videoWrap').animate({
        'width': '0'
    }, {
        duration: 500,
        specialEasing: {
            easing: 'easeInExpo'
        },
        complete: function () {
            $('#endScreen').delay(200).fadeIn(800, 'easeOutExpo');
            $('#contentTop .wrap #endScreen .bottom #replayVideo').delay(500).animate({
                'bottom': '25px'
            }, {
                duration: 800,
                easing: 'easeOutExpo'
            });
            $('#contentTop .wrap #endScreen .bottom .social').delay(1000).animate({
                'right': '55px'
            }, {
                duration: 800,
                easing: 'easeOutExpo'
            });
        }
    });
}


function setYoutubeSource() {
    $('#contentTop .wrap #homeBanner').animate({
        'opacity': 0
    }, {
        duration: 500,
        easing: 'easeOutExpo'
    });
    $('#drawHeight').animate({
        'height': '250'
    }, {
        duration: 500,
        specialEasing: {
            easing: 'easeOutExpo'
        },
        complete: function () {
            $('#videoWrap').animate({
                'width': '960px'
            }, {
                duration: 1000,
                easing: 'easeOutExpo'
            });
        }
    });

    $('#endScreen').fadeOut(800, 'easeOutExpo');
    $('#contentTop .wrap #endScreen .bottom #replayVideo').delay(500).animate({
        'bottom': '-45px'
    }, {
        duration: 800,
        easing: 'easeOutExpo'
    });
    $('#contentTop .wrap #endScreen .bottom .social').delay(1000).animate({
        'right': '-165px'
    }, {
        duration: 800,
        easing: 'easeOutExpo'
    });
    var yTu = '<object width="960" height="570"><param name="movie"value="http://www.youtube.com/v/sbS0drzp5vQ?version=3&amp;hl=en_GB&amp;rel=0&amp;autoplay=1">' +
    '</param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"><param name="wmode" value="opaque">' +
    '</param><embed src="http://www.youtube.com/v/sbS0drzp5vQ?version=3&amp;hl=en_GB&amp;rel=0&amp;autoplay=1" type="application/x-shockwave-flash" allowscriptaccess="always"' +
     ' allowfullscreen="true" width="960" height="570" wmode="opaque"></embed></object>';
    $('#videoWrap #video').html(yTu);
}




