var initial_video_id = '13Y8IQPs6QA';
var player_id        = 'myytplayer';
var player           = false;
var width = "731";
var height = "437";
var my_hash = window.location.hash;

if (my_hash != '') {
    initial_video_id = my_hash.replace(/#/, '');
}

google.load("swfobject", "2.2");
google.load("jquery", "1.3.2");

google.setOnLoadCallback(function() {
    
    //alert(initial_video_id);
    var params = { allowScriptAccess: "always" };
    var atts = { id: player_id };
    
    swfobject.embedSWF("http://www.youtube.com/v/" + initial_video_id + "&enablejsapi=1&playerapiid=ytplayer&rel=0&color1=0xEC8711&color2=0xEC8711", 
               "ytapiplayer", width, height, "8", null, null, params, atts);    
    
    jQuery("div.video_wrapper").hover(
    	function(){
    		jQuery(this).addClass('hoverbox');
    	},
    	function(){
		    jQuery(this).removeClass('hoverbox');
    	}
    );
    
    youtube_highlight(initial_video_id);
           
    
	jQuery("div.normal").toggle(function(){
		jQuery(this).addClass("act");
		}, function () {
		jQuery(this).removeClass("act");
	});
           
           
	jQuery("div.normal").click(function(){
		jQuery(this).next(".b_content").slideToggle("fast");
	});     
         
    // divs für die Rundungen derBoxen erstellen         
    jQuery('<div class="tr"></div><div class="tl"></div><div class="br"></div><div class="bl"></div>').appendTo("div.k_bild");

	jQuery("a[rel]").overlay({
			effect: 'apple',
			speed: 'fast',
			expose: '#292929'
	}); 
 

        
    if ( jQuery("#braintools_gallery a").length){    
        // select the thumbnails and make them trigger our overlay 
        jQuery("#braintools_gallery a").overlay({ 
         
            // each trigger uses the same overlay with the id "gallery" 
            target: '#gallery', 
         
            // optional exposing effect 
            expose: '#292929' 
         
        // let the gallery plugin do its magic! 
        }).gallery({         
            // the plugin accepts its own set of configuration options 
            speed: 800,
            autohide: false 
        });    
    }    

    jQuery.extend({
      getUrlVars: function(){
        var vars = [], hash;
        var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
        for(var i = 0; i < hashes.length; i++)
        {
          hash = hashes[i].split('=');
          vars.push(hash[0]);
          vars[hash[0]] = hash[1];
        }
        return vars;
      },
      getUrlVar: function(name){
        return jQuery.getUrlVars()[name];
      }
    });  
    
         
     
    /* Kontaktformular */
    /*
    if(jQuery('select#uid29').val() != 10){ 
        jQuery('#powermaildiv_uid30').css({'display': 'none'});
    }
    */
    var sel_grund = jQuery.getUrlVar('sel_grund');    
    
    if(sel_grund > 0){
        jQuery("select#uid29 option:eq("+sel_grund+")").attr("selected", "selected");       
    }
    
     /*              
    jQuery('select#uid29').change(function () {    
        if(jQuery('select#uid29').val() == 10){
            jQuery('#powermaildiv_uid30').css({'display': 'block'});    
        } else {
            jQuery('#powermaildiv_uid30').css({'display': 'none'});    
        }                      
    });
    */        
    /*
    if ( jQuery("#etikett_gallery a").length){
        
        // select the thumbnails and make them trigger our overlay 
        jQuery("#etikett_gallery a").overlay({ 
         
            // each trigger uses the same overlay with the id "gallery" 
            target: '#e_gallery', 
         
            // optional exposing effect 
            expose: '#292929' 
         
        // let the gallery plugin do its magic! 
        }).gallery({         
            // the plugin accepts its own set of configuration options 
            speed: 800,
            autohide: false 
        }); 
    }    
    */

    jQuery('.box th').each(function (i,obj) {
        jQuery(this).prepend('<img src="fileadmin/templates/img/table_icons/tablehead_' + i + '.gif" /><br/>');
    });
    
 
                     	
});


function onYouTubePlayerReady(playerId) {
    player = document.getElementById(player_id);

    if (playstack != '') {
        player.loadVideoById(playstack);
    }
}

var playstack = '';
function youtube_play(vid) {
   currentvideo = window.location.hash;
   newvideo = vid.replace(/^.*#/, '');
   player.loadVideoById(newvideo);
   youtube_highlight(newvideo);
}

function youtube_highlight(newvideo) {
   jQuery('div.video_wrapper').removeClass('actbox');
   jQuery('#' + newvideo).parent().addClass('actbox');
   jQuery('#page_7 .csc-firstHeader').html(jQuery('#' + newvideo + ' h3').text());
}

function youtube_play_frame(vid) {
    playstack = vid;
}


function switchBraintool(bt_id, lang){

    if(bt_id != 0) {
        document.location.href='http://www.schlauschleifen.de/index.php?id=' + bt_id + '&L=' + lang;    
    } else {
            return false;
        }
}