<?php require_once(dirname(__FILE__).'/../config.php'); ?>
<?php header("Content-type: text/javascript"); ?>

(function(){
if(!window.alreadyIncluded) {/** Check if file is already loaded **/
var t = 0;
/******** Main Function That Will Generate All Ads *********/
function main() {
var g = $(".<?php echo ADS_CLASS_NAME;?>").map(function () {

t++;
	/*** GET TAGS ***/
if ( $(document).find("title").text() ) {
	var title = $(document).find("title").text().replace(/ /g, ',');
} else {
	var title = "";
}

if ( $(document).find('meta[name=description]').attr("content") ) {
	var description = $(document).find('meta[name=description]').attr("content").replace(/ /g, ',');
} else {
	var description = "";
}

if ( $(document).find('meta[name=keywords]').attr("content") ) {
	var keywords = $(document).find('meta[name=keywords]').attr("content").replace(/ /g, ',');
} else {
	var keywords = "";
}
    var rf		=	document.referrer;
    var lh		=	window.location.host;
	var st		=	title + "," + description + "," + keywords;
	var st		=	st.replace("(", "").replace(")", "");
	var slot	=	$( this ).data("ad-slot");
	var client	=	$( this ).data("ad-client");
	var width	=	$( this ).width();
	var height	=	$( this ).height();

	$( this ).html( '<iframe id="ad_iframe_' + t + '" name="ad_iframe_' + t + '" width="'+ width +'" height="'+ height +'" frameborder="0" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no" src="<?php echo HTTP_SERVER_WEBSITE ?>pagead/generate?s=' + slot + '&c=' + client + '&st=' + st + '&rf=' + rf + '&lh=' + lh + '&ct=' + t + '"></iframe>' );

}).get();
}
/******** End Main Function That Will Generate All Ads *********/

/******** Load jQuery if not present *********/
if ( typeof jQuery === "undefined" ) {
	var script_tag = document.createElement('script');
	script_tag.setAttribute("type","text/javascript");
	script_tag.setAttribute("src", "//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js")
	script_tag.onload = main; //Run main() once jQuery has loaded
	script_tag.onreadystatechange = function () { //Same thing but for IE
		if (this.readyState == 'complete' || this.readyState == 'loaded') main();
	} //onreadystatechange.function
	document.getElementsByTagName("head")[0].appendChild(script_tag);
	} else {
		main();
} //if.jQuery
/******** END Load jQuery if not present *********/

window.alreadyIncluded = true;
} /*** End check if file is already loaded ***/
})()