/**
 * @copyright 2010 Syzygy
 * @version $Revision: 648 $
 * @author $Author: t.kropf $
 * @package bechstein
 * @namespace bechstein.int
 * $Id: bechstein.int.js 648 2010-11-10 15:38:20Z t.kropf $, $Date: 2010-11-10 16:38:20 +0100 (Wed, 10 Nov 2010) $
 * 
 * bechstein JavaScript: bechstein.int
 */

var BechsteinInt = {

    __version: 1.0, // class version
    __class: '', // class name
    h3Replacement: true,


    cufonReplaceText: function () {
        Cufon.replace('h1');
        Cufon.replace('h2');
        if (this.h3Replacement == true) {
            Cufon.replace('h3');
        }
        Cufon.replace('h4');
        Cufon.replace('h5');
        Cufon.replace('.t1', {});
        Cufon.replace('.t5');
        Cufon.replace('.t6');
        Cufon.replace('.ui-widget');
        Cufon.replace('.image_teaser_headline');
        Cufon.replace('.tx-powermail-pi1 form fieldset legend');
    },


    cufonReplaceCorporateNavigation:  function ()
    {
        Cufon.replace('.nav_item_firstlevel', {
            hover: true
        });
        Cufon.replace('.last_firstlevel', {
            hover: true
        });
        Cufon.replace('.nav_item_firstlevel_active');
        Cufon.replace('.nav_item_firstlevel_active_last');


        Cufon.replace('.content_area h2');
        Cufon.replace('p.intro');
        Cufon.replace('.content_layer_headline h3');
        Cufon.replace('.content_layer_content h3');
        Cufon.replace('.content_layer_link', {
            hover: true
        });
        Cufon.replace('.content_teaser_area_item h4');
        Cufon.replace('.content_footer_3rd', {
            hover: true
        });
    },


    handleMouseOver: function () {
    },


    handleMouseOut: function () {
        setTimeout(closeProductChooser, 250)
    },
    

    externalLinks: function() {
        if (!document.getElementsByTagName) return;
        var anchors = document.getElementsByTagName("a");
        for (var i=0; i<anchors.length; i++) {
            var anchor = anchors[i];
            if (anchor.getAttribute("href") &&
                anchor.getAttribute("rel") == "external")
                anchor.target = "_blank";
        }
    },

    /*
     * opens a page in an external popup window
     * this function is used for terms of use in formelements
     * */
    openPopupLinks: function() 
    {
        jQuery('.openPopup').each(function(index, element) 
        {
        	var id = jQuery(element).attr('rel');
        	if(id.length > 0)
        	{
        		jQuery(element).bind('click', function() 
        		{
        			var lang = jQuery('html').attr('xml:lang');
        			var langCode = 1;
        			switch(lang)
        			{
	        			case 'de':
	        				langCode = 0;
	        				break;
	        			case 'fr':
	        				langCode = 2;
	        				break;
	        			case 'ru':
	        				langCode = 3;
	        				break;
	        			case 'en':
	        			default:
	        				langCode = 1;
	        				break;
        			}
        			var popup = window.open("/index.php?id=" + id + "&L=" + langCode, "Infowindow", "width=1010,height=550");
        			popup.focus();
        			return false;
        		});
        	}
        });
    },

    proofMarginalContentPos: function () {
        if (jQuery('.page_title .t1').html() == "") {
            jQuery('#content_marginal').css("margin","32px 0px 0px 30px");
        }
    },

    setProductContainerHeight: function () {
        jQuery('.productContainer').each(function () {
            var hoehe = Math.ceil (jQuery('.productItem', this).length / 3) * 260 + 40;
            jQuery(this).css('height', hoehe);
        })
        jQuery('.productContainer').css('visibility', 'visible');
        if (this.h3Replacement == false) {
            Cufon.replace('h3');
        }
    },

    setPianistContainerHeight: function () {
        jQuery('.pianistContainer').each(function () {
            var hoehe = Math.ceil(jQuery('.pianistItem', this).length / 4) * 210 + 40;
            jQuery(this).css('height', hoehe);
        })
    },

    setImageContainerHeight: function () {
        jQuery('.imageContainer').each(function () {
            var hoehe = Math.ceil (jQuery('.imageItem', this).length / 4) * 210 + 40;
            jQuery(this).css('height', hoehe);
        })
    },

    setVideoContentPlayer: function () {
        var option = jQuery('.app_003_int_video','#video_content');
        //console.log (option.attr("value"));
        jQuery('#video_alt_content object').remove();
        jQuery('#video_alt_content').append('<object width="660" height="375"><param name="movie" value="http://www.youtube.com/v/'+ option.attr("value") +'"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'+ option.attr("value") +'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="390" wmode="opaque"></embed></object>');

        var attributes = {};
        attributes.id = 'app_003_int_video';
        attributes.name = 'app_003_int_video';

        var flashvars = {};
        flashvars.width = '660';
        flashvars.height = '375';
        flashvars.playAuto = '1';
        flashvars.YT_ID = option.attr("value");
        flashvars.quality = option.attr('quality');
        flashvars.application_mode = 'int';
        flashvars.base = jQuery('base').attr('href');

        var params = {};
        params.menu = "false";
        params.wmode = "transparent";
        params.allowscriptaccess = "always";
        params.allowfullscreen = "true";
        swfobject.embedSWF('fileadmin/templates/applications/APP_003_VIDEO_INT.swf', 'app_003_int_video', '670px', '415px', '9.0.115', 'swf/expressinstall.swf', flashvars, params, attributes);
    },


    /**
     * Contructor
     * @method initialize
     * @return {Void}
     */
    initialize: function()
    {
        this.cufonReplaceCorporateNavigation();
        this.externalLinks();
        this.openPopupLinks();

        if(jQuery('#content_marginal').hasClass('content_marginal'))
        {
            this.proofMarginalContentPos();
        }

        
        if(jQuery('.productContainer').length > 0)
        {
            this.h3Replacement = false;
            this.setProductContainerHeight ();
        }

        if(jQuery('.pianistContainer').length > 0)
        {
            this.setPianistContainerHeight ();
        }

        if(jQuery('.imageContainer').length > 0)
        {
            this.setImageContainerHeight ();
        }

        if(jQuery('#video_content').length > 0)
        {
            //console.log ('video_content vorhanden');
            this.setVideoContentPlayer ();
        }
        this.cufonReplaceText();
    }
};

jQuery(document).ready(jQuery.proxy(BechsteinInt.initialize, BechsteinInt));


