function createRequestObject() {
    var tmpXmlHttpObject;
    
    //depending on what the browser supports, use the right way to create the XMLHttpRequest object
    if (window.XMLHttpRequest) { 
        // Mozilla, Safari would use this method ...
        tmpXmlHttpObject = new XMLHttpRequest();
	
    } else if (window.ActiveXObject) { 
        // IE would use this method ...
        tmpXmlHttpObject = new ActiveXObject("Microsoft.XMLHTTP");
    }
    
    return tmpXmlHttpObject;
}

//call the above function to create the XMLHttpRequest object
var http = createRequestObject();

function req() {
    //make a connection to the server ... specifying that you intend to make a GET request 
    //to the server. Specifiy the page name and the URL parameters to send
    http.open('get', './count/counter.php');
	
    //assign a handler for the response
    http.onreadystatechange = processResponse;
	
    //actually send the request to the server
    http.send(null);
}

function processResponse() {
    //check if the response has been received from the server

    if(http.readyState == 4){
	
        //read and assign the response from the server
        var response = http.responseText;

        if(response == "1") {
			play();
		}
    }
}

function play() {
	setTimeout(function () {
		var ytId = GetYTID();
		var div = document.getElementById('video'); 
		var yt = '<object width="320" height="265">';
			yt = '<param name="movie" value="http://www.youtube.com/v/'+ytId+'&hl=de&fs=1&rel=0&autoplay=1"></param>';
			yt+= '<param name="allowFullScreen" value="false"></param>';
			yt+= '<param name="allowscriptaccess" value="always"></param>';
			yt+= '<embed src="http://www.youtube.com/v/'+ytId+'&hl=de&fs=1&rel=0=&autoplay=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="320" height="265"></embed>';
			yt+= '</object>';
		div.innerHTML = yt;  
	}, 10000); // 10 sek
}

function GetYTID() {
	var currentTime = new Date();
	var hour = currentTime.getHours();
	
	if(hour > 4 && hour < 10) {
		return 'c4aE7E8bzd0'
	}
	else {
		return 'Owq1adHHXoQ'
	}
}

req();