function addEvent(obj, type, fn, par){    if(obj.addEventListener){        obj.addEventListener(type, function(event){                    return fn.call(obj, event, par);        }, false );    } else if(obj.attachEvent){        obj.attachEvent("on"+type, function(e){            if (!e) var e = window.event;               e.preventDefault ? e.preventDefault() : e.returnValue = false;            return fn.call(obj, e, par);        });    }};
var HDC = {	GMapKey: document.domain == "horaires-de-cinema.com" ?  "ABQIAAAAVBLYoATfPtLKfQMQNa3ZBhS-lYUTDE16-MlcXVMbsT0sqGg-kxSbi73D3T0Jfb4hcDFXkDw43FJMgQ" :             document.domain == "www.horaires-de-cinema.com" ? "ABQIAAAAY4SISZTqHb5k8DEzIf_-LRQZicHdJ_lmwzrKiTWqoO23mHBIpRRHfT3SJnzgyRj6O0_9IFbUPUBMLg" :             document.domain == "horaires-de-cinema.dyndns.org" ? "ABQIAAAAY4SISZTqHb5k8DEzIf_-LRSlLHQwZoROltR72ORlpCK_TmYhFxTAoXJM3DESIZ0arKV3po3bfITWQQ" :             document.domain == "horaires-de-cinema.erreur404.dyndns.org" ? "ABQIAAAAY4SISZTqHb5k8DEzIf_-LRRJSO7SHuLcI2Zls8ZrsphhvITdyBQbhuoVa8rDtzUqHXeev6h1oXVSCA" : ''     ,    init: function() {        HDC.utils.init();        /*if (!HDC.utils.getCookie('cinemas')) {            HDC.openMapPopup();        }*/        var closest_cinemas = document.getElementById("closest-cinemas");        if (closest_cinemas) {            var anchors = closest_cinemas.getElementsByTagName('A');            for (var i = 0;i < anchors.length;++i) {                if (anchors[i].className == "add-cinema")                    anchors[i].onclick = HDC.addCinemaFromNode;                if (anchors[i].className == "remove-cinema")                    anchors[i].onclick = HDC.removeCinemaFromNode;            }        }    },    openMapPopup: function(latitude, longitude) {        HDC.cinema_ids = HDC.utils.getCookie('cinemas');        if (HDC.map) {            if (latitude && longitude)                HDC.map.setCenter(new GLatLng(latitude, longitude), 15);            else                HDC.map.setCenter();            document.getElementById('gmap-frame').style.display = 'block';        } else {            var query_string = (latitude && longitude) ? '?latitude=' + latitude + '&longitude=' + longitude : '';            HDC.utils.loadURL('modules/map.php' + query_string, function(html) {				HDC.utils.loadScripts("static/javascript/map.js",									  "http://www.google.com/jsapi?callback=HDC.loadMap&key=" + HDC.GMapKey);                var frament = document.createElement('DIV');                frament.innerHTML += html;                document.body.appendChild(frament.firstChild);            });        }        scrollTo(0,0);    },	loadMap: function() {		google.load("maps", "2",{callback : "HDC.initializeMap", other_param: "sensor=true"});	},    closeMapPopup: function() {        document.getElementById('gmap-frame').style.display = 'none';        if (HDC.cinema_ids != HDC.utils.getCookie('cinemas'))            document.location.reload();    },    utils: {		init: function() {			String.prototype.trim = function() {				return this.replace(/^\s+|\s+$/g,"");			};			String.prototype.ltrim = function() {				return this.replace(/^\s+/,"");			};			String.prototype.rtrim = function() {				return this.replace(/\s+$/,"");			};            Array.prototype.find = function(searchStr) {              var returnArray = false;              for (i=0; i<this.length; i++) {                if (typeof(searchStr) == 'function') {                  if (searchStr.test(this[i])) {                    if (!returnArray) { returnArray = [] }                    returnArray.push(i);                  }                } else {                  if (this[i]===searchStr) {                    if (!returnArray) { returnArray = [] }                    returnArray.push(i);                  }                }              }              return returnArray;            };            			if( typeof XMLHttpRequest == "undefined" ) XMLHttpRequest = function() {				try { return new ActiveXObject("Msxml2.XMLHTTP.6.0") } catch(e) {}				try { return new ActiveXObject("Msxml2.XMLHTTP.3.0") } catch(e) {}				try { return new ActiveXObject("Msxml2.XMLHTTP") } catch(e) {}				try { return new ActiveXObject("Microsoft.XMLHTTP") } catch(e) {}				throw new Error( "This browser does not support XMLHttpRequest." )			};                        var stripsContainer = document.getElementById("strips-container");            var strips = stripsContainer.getElementsByTagName('DIV')[0];            var width = stripsContainer.offsetWidth;            strips.style.width = stripsContainer.scrollWidth + "px";            stripsContainer.scrollLeft = parseInt(stripsContainer.scrollWidth / 2) - (width / 2);            var scrollLeft = stripsContainer.scrollLeft;            var handle = null;            addEvent(strips, 'mouseover', function(e) {                var e = e || window.event;                var x = e.clientX | e.pageX;                var step = 0;                x -= (stripsContainer.offsetLeft || stripsContainer.parentNode.offsetLeft);                if (x > (width - 300))                    step = 10;                if (x < 300)                    step = -10;                                clearInterval(handle);                handle = setInterval(function() {                    scrollLeft += step;                    stripsContainer.scrollLeft = scrollLeft;                }, 20);            });            addEvent(strips, 'mouseout', function(e) {                var e = e || window.event;                if (e.target == this)                    clearInterval(handle);            });		},        loadURL: function(url, callback) {            var xrq = null;            xrq = new XMLHttpRequest();            xrq.onreadystatechange = function() {                 if (xrq.readyState == 4 && xrq.status == 200) {                    callback(xrq.responseText);                    delete xrq.onreadystatechange;                }            };            xrq.open("GET", url, true);            xrq.send(null);        },		loadScripts: function(src1, src2) {			for(var i = 0;i < arguments.length;++i) {				var script = document.createElement("script");				script.src = arguments[i];				script.type = "text/javascript";				document.getElementsByTagName("head")[0].appendChild(script);			}		},        getCookie: function(name) {            var cookie = document.cookie.toString();            var pairs = cookie.split(';');            for (var i = 0;i < pairs.length;++i) {                var pair = pairs[i].split('=');                if (pair.length == 2 && pair[0].trim() == name)                    return unescape(pair[1]);            }            return '';        },        setCookie: function(name, value) {            var argv = arguments;            var argc = arguments.length;            var expires = (argc > 2) ? argv[2] : null;            var path    = (argc > 3) ? argv[3] : null;            var domain  = (argc > 4) ? argv[4] : null;            var secure  = (argc > 5) ? argv[5] : false;            document.cookie = name + "=" + escape (value) +                    ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +                    ((path == null) ? "" : ("; path=" + path)) +                    ((domain == null) ? "" : ("; domain=" + domain)) +                    ((secure == true) ? "; secure" : "");        }    }};HDC.getCinemaFromNode = function(node) {    var container = node.parentNode;    var input = container.getElementsByTagName('INPUT')[0];    return input.value;};HDC.addCinema = function(cinema_id) {    var cinemas = HDC.removeCinema(cinema_id);    cinemas.push(cinema_id);    var expires = new Date( (new Date()).getTime() + 31536000000);    HDC.utils.setCookie('cinemas', cinemas.join(','), expires, '/');    var container = document.getElementById('cinema-list');    if (HDC.cinemas && HDC.cinemas[cinema_id]) {        HDC.toggleCinemaList();        var cinema = HDC.cinemas[cinema_id];        cinema.listItem.className = 'selected';        container.appendChild(cinema.listItem);        window.setTimeout(function() {            HDC.toggleCinemaList();            cinema.listItem.className = '';        }, 1500);        var infoWindow = cinema.infoWindow;        infoWindow.className = infoWindow.className.replace('not-favorite', 'favorite');                cinema.marker.setImage("http://www.google.com/intl/en_us/mapfiles/ms/micons/yellow-dot.png");        }};HDC.addCinemaFromNode = function(e) {    var node = this;    var cinema_id = HDC.getCinemaFromNode(node);    HDC.addCinema(cinema_id);    node.parentNode.className = node.parentNode.className.replace('not-favorite', 'favorite');    if (HDC.cinemas && HDC.cinemas[cinema_id]) {        var cinema = HDC.cinemas[cinema_id];        cinema.marker.closeInfoWindow();    }    return false;        };    HDC.removeCinema = function(cinema_id) {        var cinemas_ids = HDC.utils.getCookie('cinemas');    var cinemas = cinemas_ids ? cinemas_ids.split(',') : [];    for (var i = 0;i < cinemas.length;++i)        if (cinemas[i] == cinema_id)            cinemas.splice(i, 1);    var cinema_inputs = document.forms['selected-cinemas'];    if (cinema_inputs) {        for (var i = 0;i < cinema_inputs.length;++i) {            var input = cinema_inputs[i];            if (input.value == cinema_id)                input.parentNode.parentNode.removeChild(input.parentNode);        }    }    var expires = new Date( (new Date()).getTime() + 31536000000);    HDC.utils.setCookie('cinemas', cinemas.join(','), expires, '/');    if (HDC.cinemas && HDC.cinemas[cinema_id]) {        var cinema = HDC.cinemas[cinema_id];        var infoWindow = cinema.infoWindow;        infoWindow.className = infoWindow.className.replace('favorite', 'not-favorite');        cinema.marker.setImage("http://www.google.com/intl/en_us/mapfiles/ms/micons/red-dot.png");    }    return cinemas;};HDC.removeCinemaFromNode = function(e) {    var node = this;    var cinema_id = HDC.getCinemaFromNode(node);    HDC.removeCinema(cinema_id);    node.parentNode.className = node.parentNode.className.replace('favorite', 'not-favorite');    return false;};window.onload = HDC.init;
