function winopen(site)
{
	win = open(site,"win","width=700,height=480,screenX=0,screenY=0,menubar=no,scrollbars=yes,resizable=no");
	win.focus();
}

function oeffnefenster (url) {   fenster = window.open(url, "fenster1", "width=600,height=600,status=no,scrollbars=no,resizable=no");   fenster.focus();  }



(function($) {
    $.fn.pulsate = function(dat){
        if (this.length == 0){
            return $(this);
        }
        var par = {
            fadeinTime : 100,
            fadeoutTime : 1000
        };
        var pulseCounter = 20; // Anzahl der Pulsierungen
        var par = $.extend(par, dat);
        var $obj = $(this);
        var varCounter = 0;
        var pfn = function(){
                if(varCounter <= pulseCounter) {
                varCounter++;
                $obj.fadeIn(par.fadeinTime, function(){
                    $obj.fadeOut(par.fadeoutTime);

                });
            } else {
              clearInterval(pfn);
            };
        };

        pfn();
        setInterval(pfn, par.fadeinTime + par.fadeoutTime);

        return $obj;
    }
})(jQuery);


$(document).ready(function() {

    $("#flash_box_link").click(function() {
        $('#pulse').pulsate();
        return false;
    });

    $("ul#topten li:nth-child(odd)").addClass("colored");

    $("ul#topten span#one").mouseover(function () {
      $("ul#topten li span.one").pause(slideToggle("slow"));
    });

    $(".sub_header_center .button").click(function() {
      $(this).toggleClass("hover");
      $(this).parents(".sub_header").next(".box").slideToggle("slow");
      $(this).parents(".sub_header").next(".bc_slide").slideToggle("slow", function() {
        $(".bar", this).animate({
          "width":"toggle"
        }, {
          duration: "slow" });
        });
      });

    $("#togglewrite").click(function() {
      $("#bc_review").slideToggle("slow");
      return false;
    });

    $("#togglenmdf").click(function() {
      $("#bc_nmdf_nonmemberform").slideToggle("slow");
      return false;
    });
    $("#togglenmdf").click(function() {
      $("#bc_nmdf_select").slideToggle("slow");
      return false;
    });

    $(".show_preview").hover(function () {
       $(this).children(".spot.info").stop().fadeIn("fast").fadeTo("fast", 1);
       }, function () {
       $(this).children(".spot.info").stop().fadeOut("fast");
    });

    $(".spot.info").click(function () {
        var aktuell = $(this).parent().children(".preview.dn");

        var img_width = $(this).parent().find("img:first").attr("width");
        var img_height = $(this).parent().find("img:first").attr("height");

        $(aktuell).width(img_width-15);

        var info_height = $(aktuell).height();

        $(aktuell).css("top", img_height - info_height - 10);
        $(aktuell).css("left", 3);

        $(".preview").not(aktuell).fadeOut();
        $(aktuell).fadeIn("fast");
        return false;
    });

      $("a.close_description").click(function () {
       $(this).parent().parent().parent().fadeOut("fast");
       return false;
       });

     $(".partner img").fadeTo("fast", 0.33);
     $(".partner img").hover(function() {
        $(this).fadeTo("fast", 1.00);
     }, function () {
        $(this).fadeTo("fast", 0.33);
    });


    $(".show_preview").hover(function ()
        {
            $(this).children(".dn").fadeIn("fast");
        }, function ()
        {
            $(this).children(".dn").fadeOut("fast");
        }
    );

    /*
    // Umfrage
    // Umfrage abgegeben?
    if($.cookie('hide_poll'))
    {
        if($.cookie('hide_poll') == "true")
        {
            $("#show_poll").hide();
        }
        else
        {
            $("#show_poll").show();
        }
    }

    $("#poll_button").click(function(){
        var display = $("#show_poll").css("display");
        if (display == "none" )
        {
            $("#show_poll").show();
            $.cookie('hide_poll', 'false', { expires: 1, path: '/' });
            $(".bar").fadeIn("slow");
        }
        else
        {
            $("#show_poll").hide();
            $(".bar").fadeOut("slow");
        }
        return false;
    });

    $("#close_poll").click(function(){
        $("#show_poll").hide();
        $.cookie('hide_poll', 'true', { expires: 1, path: '/' });
        return false;
    });
    // Umfrage

    // Produktvoting

    $("#productvoting").easySlider({
            orientation:'vertical',
            prevText:         '',
            nextText:         ''
        });

    // Produktvoting */


    // Fancy Zoom
    $('div.photo a').fancyZoom({scaleImg: true, closeOnClick: true});
	$('.thumbborder a.zoom').fancyZoom({scaleImg: true, closeOnClick: true});
    $('#medium_box_link').fancyZoom({width:400, height:300});
    $('#large_box_link').fancyZoom();
    $('#flash_box_link, .flash_box_link').fancyZoom();

	  $("#videos li").hide();
      $("#videos li:first-child").show();
	  $("#videolinks li").fadeTo('fast',0.5, function(){$("#videolinks li:first-child").fadeTo('fast',1)});
    // Fancy Zoom

    $('.flash_box_link[class*=element]').click(function() {
        var classes = $(this).attr('class');
        classes = classes.split(' ');
        for (i=0; i<classes.length; i++)
        {
            var index = classes[i].substr(classes[i].indexOf('_')+1);
            if( ! isNaN(index))
            {
                index = parseInt(index);
                $("#videos li").hide().eq(index).show();
            }
        }
    });

	// Fancy-Zoom Autolaunch
    if(window.location.href.indexOf('#flash_') >= 0)
    {
        id = window.location.href.substr(window.location.href.indexOf('#'));
        index = id.substr(id.lastIndexOf('_')+1);
        if ( ! isNaN(index))
        {
			index = parseInt(index);
            if (index < 0 || $("#videos li").size()-1 < index)
                index = 0;

            id = id.substr(0, id.lastIndexOf('_'));
            $("a[href="+id+"], area[href="+id+"]").click();
            $("#videos li").hide().eq(index).show();
        }
		else
		{
			index = 0;
            $("a[href="+id+"], area[href="+id+"]").click();
		}
    } // Fancy-Zoom Autolaunch

    // Entertainment Offsite Links
    if(window.location.pathname.indexOf('/entertainment/') == 0)
    {
        $('a').each(function() {
            $(this).click(function() {
                var url = $(this).attr('href');
                if(url.indexOf('://') != -1)
                {
                    var offsite_elements = new Array();
                    var offsite_element = this.nodeName.toLowerCase();
                    if($(this).attr('class'))
                    {
                        offsite_element += " class=" + $(this).attr('class') + "";
                    }
                    if($(this).attr('id'))
                    {
                        offsite_element += " id=" + $(this).attr('id') + "";
                    }
                    offsite_elements.push(offsite_element);
                    $(this).parents().each(function() {
                        offsite_element = this.nodeName.toLowerCase();
                        if($(this).attr('class'))
                        {
                            offsite_element += " class=" + $(this).attr('class') + "";
                        }
                        if($(this).attr('id'))
                        {
                            offsite_element += " id=" + $(this).attr('id') + "";
                            var elements_with_id = $("*[id=" + $(this).attr('id') + "]");
                            if(elements_with_id.length > 1)
                            {
                                offsite_element += "(" + elements_with_id.index($(this)) + ")";
                            }
                            offsite_elements.push(offsite_element);
                            return false;
                        }
                        offsite_elements.push(offsite_element);
                    });
                    offsite_elements.reverse();
                    var offsite_domain = url.substring(url.indexOf('://')+3, url.indexOf('/', url.indexOf('://')+3)==-1?url.length:url.indexOf('/', url.indexOf('://')+3));
                    var offsite_path = url.substring(url.indexOf('://')+3+offsite_domain.length);
                    if(offsite_path == '')
                    {
                        offsite_path = '/';
                    }
                    if(offsite_domain.indexOf('.orion.de') == -1)
                    {
                        window.console && console.log("offsite_domain = %s", offsite_domain);
                        window.console && console.log("offsite_path = %s", offsite_path);
                        window.console && console.log("offsite_element = %s", offsite_elements.join(' | '));
                        if(window.location.href.indexOf('test') != -1)
                        {
                            alert('Offsite:' + offsite_domain + " (" + offsite_path + ")\n" + offsite_elements.join(' | '));
                            return false;
                        }
                        dcsMultiTrack('DCS.dcssip', offsite_domain, 'DCS.dcsuri', offsite_path, 'DCS.dcsref', window.location.href, 'WT.es', window.location.href, 'WT.ti', 'Offsite:' + offsite_domain + offsite_path, 'WT.offsite', offsite_domain + offsite_path, 'WT.offsite_element', offsite_elements.join(' | '));
                    }
                }
            });
        });
    }
});
