$(document).ready(function () {
		
$('#play,.replay').click(function () {
        if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
			// set content for iphone/ipad
			iphoneIpad();
        }
        else if (swfobject.hasFlashPlayerVersion('1')) {
            // set the video source
			PlayVideo();
        }
        else {
			// when no flash installed.
            HasNoFlash();
        }
    });
	
	
if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
       // Alternate video source for iphone/ipad
        $("#videoWrap #video").css({'display': 'block'});
    }
    else {
        var flashvars = { 'wmode': 'transparent', 'allowfullscreen': 'true' };
        var params = { 'name': 'video', 'allowscriptaccess': 'always', 'allowfullscreen': 'true' };
        var attributes = false;
        swfobject.embedSWF('/wp-content/themes/ignition/media/ignition.swf', 'video', '900', '536', '9.0.0', '/wp-content/themes/ignition/media/expressInstall.swf',
        attributes, flashvars, params);
    }	
});

//calling Flash function with javascript.
function getFlashMovie(movieName) {
    if (navigator.appName.indexOf('Microsoft') != -1) {
        return window[movieName];
    } else {
        return document[movieName];
    }
}

function iphoneIpad() {
    var youTubeURL = '<object width="900" height="536"><param name="movie"value="http://www.youtube.com/watch?v=oeamDNNHZ9M">' +
    '</param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"><param name="wmode" value="opaque">' +
    '</param><embed src="http://www.youtube.com/watch?v=oeamDNNHZ9M" type="application/x-shockwave-flash" allowscriptaccess="always"' +
     ' allowfullscreen="true" width="900" height="536" wmode="opaque"></embed></object>';
	 
	 $('#videoWrap #video').html(youTubeURL);
	 
	 $("#videoWrap").delay(600).animate({ 'height': '536px' }, { duration: 1000, easing: 'easeOutExpo' });
}

// Communicate with ExternalInterface API to set the video source.
function setMovieSource(id) {
    var movie = getFlashMovie(id);
    movie.setMovieSource('/wp-content/themes/ignition/media/home.f4v');
}

// called when "play" button is clicked
function PlayVideo() {	
    setMovieSource('video');	
	$('#videoWrap').delay(600).animate({ 'height': '536px' }, { duration: 1000, easing: 'easeOutExpo' });	
}


// show these contents, when no flash installed
function HasNoFlash() {
    $('#alternateContents').css('display','block');
}

// set the screen to origional state, when someone click close button 
function SetScreenToDefault() {
	$('#videoWrap').animate({ 'height': '0px' }, { duration: 1000, easing: 'easeOutExpo' });
}

//call End screen 
function ShowEndScreen() {
$('#videoWrap').animate({ 'height': '0px' }, { duration: 1000, easing: 'easeOutExpo' });

$('#play').text('replay').addClass('replay');

}
