/**
 * common.js
 * 
 * coder: 		Bartosz Stankiewicz, MSc
 * company: 	TOTALdeluxe | www.totaldeluxe.com
 * contact:		bartosz.stankiewicz@totaldeluxe.com
 * date:		2009/10/08
 * description:	Initializing the jQuery plugin "Superfish" for menu.
 */

var prefixLength = 'menu_'.length;
var HOME_WIDTH = 73;
var PRODUCTS_WIDTH = 108;
var COMPANY_WIDTH = 103;
var CUSTOMERS_WIDTH = 120;
var NEWS_AND_EVENTS_WIDTH = 165;
var CONTACT_WIDTH = 97;
 
var flashvars = {
	line1 : "Measurable better radio networks",
  	line2 : "Higher engineering productivity",
  	line3 : "Best performance against cost",
  	link1 : "index.php?id=11",
  	link2 : "index.php?id=10",
 	link3 : "index.php?id=9",
 	link4 : "index.php?id=8"
};

var params = {
	wmode : "opaque"
};

var attributes = {};
swfobject.embedSWF("fileadmin/flash/header_symena_02.swf", "flashemoticon", "952", "222", "9.0.0", "fileadmin/flash/expressInstall.swf", flashvars, params, attributes);
	 
$(document).ready(function() { 
    $('ul.sf-menu').superfish({ 
        speed:       	'fast',                          
        autoArrows:  	false,                          
        dropShadows: 	false,
        onInit:		
        	function() {
        		var currentItem = $('.active_left_bg').parent().attr('id').substring(prefixLength);
        		var width = 0;
        		switch(currentItem)  {
	        		case 'home': width = HOME_WIDTH; break;
	        		case 'products': width = PRODUCTS_WIDTH; break;
	        		case 'company': width = COMPANY_WIDTH; break;
	        		case 'customers': width = CUSTOMERS_WIDTH; break;
	        		case 'news_and_events': width = NEWS_AND_EVENTS_WIDTH; break;
	        		case 'contact': width = CONTACT_WIDTH; break;
	        		default: break;
	    		}
        		$('.active_left_bg').css({'width': width + 'px'});
        		$('.sf-menu li.active').css({'background-color': 'white'});
        	},
        onBeforeShow: 		
	    	function() {
        	
        		if($(this).prev().attr('id') != undefined) 
        		{
        			var currentItem = $(this).prev().attr('id').substring(prefixLength);
        			var width = 0;
        		
	        		switch(currentItem)  {
		        		case 'home': width = HOME_WIDTH; break;
		        		case 'products': width = PRODUCTS_WIDTH; break;
		        		case 'company': width = COMPANY_WIDTH; break;
		        		case 'customers': width = CUSTOMERS_WIDTH; break;
		        		case 'news_and_events': 
		        			width = NEWS_AND_EVENTS_WIDTH; 
		        			$(this).css({'width': '150px'});
		        			break;
		        		case 'contact': width = CONTACT_WIDTH; break;
		        		default: break;
	        		}
	        		
	        		$(this).parent().addClass('current');
		        	$(this).parent().css({'background-color': 'white'});
		        	$(this).prev().append('<div class="left_bg"><div class="right_bg" style="width: ' + width + 'px;"></div></div>');
		        	//$(this).prev().find('right_bg').css({'width': width + 'px'});
        		}
	    	},
	    onShow:
	    	function() {
	    	},
    	onHide: 		
	    	function() {
	    		var active = false;
	    		if($(this).parent().attr('class')  == 'active') {
	    			active = true;
	    		}
	    		
	    		$(this).parent().removeClass('current');
	    		if(active == false) {
	    			$(this).parent().css({'background-color': 'transparent'});
	    		}
	    		//$(this).prev().children().remove();
	    		$(this).prev().children().children().removeClass('right_bg');
	    		$(this).prev().children().removeClass('left_bg');
	    	}
    }); 
});

//Steuerelemente für Superfish

$(document).ready(function() { 
	$('.sf-menu li').hover(
		function() {
			$(this).addClass('sfHover');
			$(this).addClass('active');
		},
		function() {
			$(this).removeClass('active');
			$(this).removeClass('sfHover');
		}
	);
});