// JavaScript Document
$(document).ready(function ()
{
    $('a[rel*=facebox]').facebox();
});


	function simple_tooltip(target_items, name)
	{
	    $(target_items).each(findtooltip);
	    function findtooltip(i)
	    {
	        $("body").append("<div class='" + name + "' id='" + name + i + "'><p>" + $(this).attr('title') + "</p></div>");
	        var my_tooltip = $("#" + name + i);

	        $(this).removeAttr("title").mouseover(function ()
	        {
	            my_tooltip.css({ opacity: 0.8, display: "none" }).fadeIn(100);
	        }).mousemove(function (kmouse)
	        {
	            my_tooltip.css({ left: kmouse.pageX + 15, top: kmouse.pageY + 15 });
	        }).mouseout(function ()
	        {
	            my_tooltip.fadeOut(100);
	        });
	    }
	}

	function Infowin(latlng, html)
	{
	    this.latlng_ = latlng;
	    this.html_ = html;
	    this.prototype = new GOverlay();
	    this.initialize = function (map)
	    {
	        var div = $('<div />');
	        div.css({
	            position: 'absolute',
	            width: 200
	        }).appendTo(map.getContainer())
	        this.map_ = map;
	        this.div_ = div;
	        this.update(html);
	    }
this.update = function (html)
	    {
	        this.html_ = html;
	        this.div_.empty();
	        var content = $('<div />').addClass('popup').css({
	            'position': 'relative',
	            //'overflow': 'hidden',
	            'max-height': 120
	        }).html(html).appendTo(this.div_);
	        this.redraw(true);
	    }
	    // Remove the main DIV from the map pane
	    this.remove = function ()
	    {
	        this.div_.remove();
	    }
	    this.copy = function ()
	    {
	        return new Infowin(this.latlng_, this.html_);
	    }
this.redraw = function (force)
	    {
	        if (!force) return;
	        var point = this.map_.fromLatLngToDivPixel(this.latlng_);
	        var leftpoint = point.x + 100;

	        if ((point.x + this.div_.width()+100) > $("#map").width())
	        {
	            leftpoint = point.x - this.div_.width() - 100;
	            this.div_.addClass('right');
	        }
	        else
	        {
	            this.div_.removeClass('right');
	        }

	        this.div_.css({
	            left: leftpoint,
	            top: point.y - 30
	        });
	    }
	}
	function InfowinV3(latlng, html)
	{
	    this.latlng_ = latlng;
	    this.html_ = html;
	    this.overlay_ = null;

	    this.initialize = function (overlay)
	    {
	        this.overlay_ = overlay
	        this.map_ = overlay.getMap();
	        var div = $('<div />');
	        div.css({
	            position: 'absolute',
	            width: 200
	        }).appendTo(this.map_.getDiv())

	        this.div_ = div;
	        this.update(html);

	    }
	    this.update = function (html)
	    {
	        this.html_ = html;
	        this.div_.empty();
	        //$('<div />').addClass('infowin-top').appendTo(this.div_);
	        //var content = $('<div />').addClass('infowin-content').css({
	        //    'position': 'relative',
	        //    'overflow': 'hidden',
	        //    'max-height': 120
	        //}).html(html);
	        //$('<div />').addClass('infowin-bottom').append(content).appendTo(this.div_);

	        $('<div />').addClass('popup').css({
	            'position': 'relative',
	            'overflow': 'hidden'
	            //'max-height': 120
	        }).html(html).appendTo(this.div_);

	        this.redraw(true);
	    }
	    // Remove the main DIV from the map pane
	    this.remove = function ()
	    {
	        this.div_.remove();
	    }
	    this.copy = function ()
	    {
	        return new Infowin(this.latlng_, this.html_);
	    }
	    this.redraw = function (force)
	    {
	        if (!force) return;
	        var point = this.overlay_.getProjection().fromLatLngToDivPixel(this.latlng_);
	        var leftpoint = point.x + 180;
	        var toppoint = point.y - this.div_.height() / 2;
	        if (toppoint < 0) {
	            toppoint = (-toppoint) / 4;
	        }
	        if (toppoint + this.div_.height() > $('#map').height()) {
	            toppoint = $('#map').height() - this.div_.height();
	        }
	        if (leftpoint + this.div_.width() + 30 > $('#map').width()) {
	            leftpoint = point.x - this.div_.width() - 180;	            
	        }
	        this.div_.css({
	            left: leftpoint,
	            top: toppoint
	        });



	    }
	}

	function OpenWindow(url)
	{
	    window.open(url, '', config = 'toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=yes, width=950, height=700, left=' + (screen.width - 950) / 2 + ', top=' + (screen.height - 700) / 2);
	}

	function playSong(file)
	{
	    var song = document.getElementById('song');
	    if (song)
	    {
	        song.innerHTML = "<embed width=\"0px\" autostart=\"true\" height=\"0px\" hidden=\"false\" loop=\"false\" src=\"" + file + "\" type=\"application/x-mplayer2\" >";
	    }
	}
	function start()
	{
	    $("#poll_overlay").show();
	    $(".poll-cont").hide();
	    $(".poll").css({
                top: getPageScroll()[1] + (getPageHeight() / 10),
                left: "50%"
            }).show();
            $(".poll .close").click(function ()
            { $("#poll_overlay").hide(); $(".poll").hide(); return false; });
	    function getPageScroll()
	    {
	        var xScroll, yScroll;
	        if (self.pageYOffset)
	        {
	            yScroll = self.pageYOffset;
	            xScroll = self.pageXOffset;
	        } else if (document.documentElement && document.documentElement.scrollTop)
	        {	 // Explorer 6 Strict
	            yScroll = document.documentElement.scrollTop;
	            xScroll = document.documentElement.scrollLeft;
	        } else if (document.body)
	        {// all other Explorers
	            yScroll = document.body.scrollTop;
	            xScroll = document.body.scrollLeft;
	        }
	        return new Array(xScroll, yScroll)
	    }
	    function getPageHeight()
	    {
	        var windowHeight
	        if (self.innerHeight)
	        {	// all except Explorer
	            windowHeight = self.innerHeight;
	        } else if (document.documentElement && document.documentElement.clientHeight)
	        { // Explorer 6 Strict Mode
	            windowHeight = document.documentElement.clientHeight;
	        } else if (document.body)
	        { // other Explorers
	            windowHeight = document.body.clientHeight;
	        }
	        return windowHeight
	    }
        
	}
