/*	$Id: jQ.GBFunctions-1.0.js,v 1.0 2009/09/29 11:53:23 roy.biswajit Exp $ */
//--- Tabs Switching ---

(function($) {			
	$.tools = $.tools || {version: {}};	
	$.tools.version.tabs = '1.0';	
	$.tools.addTabEffect = function(name, fn) {
		effects[name] = fn;
	};
	
	var effects = { 
		'default': function(i) { 
			this.getPanes().hide().eq(i).show(); 
		}, 				
		fade: function(i) {
			this.getPanes().hide().eq(i).fadeIn(this.getConf().fadeInSpeed);	
		}		
	};   	
	 
	function Tabs(tabs, panes, opts) { 		
		var self = this;
		var current;		
		function bind(name, fn) {
			$(self).bind(name, function(e, args)  {
				if (fn && fn.call(this, args.index) === false && args) {
					args.proceed = false;	
				}	
			});
			return self;
		}				
		$.each(opts, function(name, fn) {
			if ($.isFunction(fn)) { bind(name, fn); }
		});
						
		$.extend(this, {				
			click: function(i) {				
				if (i === current) { return self; }				
				var pane = self.getCurrentPane();				
				var tab = tabs.eq(i);
				if (typeof i == 'string') {
					tab = tabs.filter("[id=" +i+ "]");
					i = tabs.index(tab);
				}				
				if (!tab.length) { 
					if (current >= 0) { return self; }
					i = opts.initialIndex;
					tab = tabs.eq(i);
				}				
				// possibility to cancel click action
				var args = {index: i, proceed: true};
				$(self).triggerHandler("onBeforeClick", args);				
				if (!args.proceed) { return self; }				
				
				tab.addClass(opts.current);
				
				// call the effect
				effects[opts.effect].call(self, i);
				
				// onClick callback
				$(self).triggerHandler("onClick", args);	
				
				tabs.removeClass(opts.current);	
				tab.addClass(opts.current);											
				current = i;
				return self;
			},			
			getConf: function() {
				return opts;	
			},
			getTabs: function() {
				return tabs;	
			},			
			getPanes: function() {
				return panes;	
			},			
			getCurrentPane: function() {
				return panes.eq(current);	
			},			
			getCurrentTab: function() {
				return tabs.eq(current);	
			},			
			getIndex: function() {
				return current;	
			},			
			next: function() {
				return self.click(current + 1);
			},			
			prev: function() {
				return self.click(current - 1);	
			},			
			onBeforeClick: function(fn) {
				return bind("onBeforeClick", fn);	
			},			
			onClick: function(fn) {
				return bind("onClick", fn);	
			}		
		});
				
		// setup click actions for each tab
		tabs.each(function(i) { 
			$(this).bind(opts.event, function(e) {
				self.click(i);				
			});			
		});
		
		// if no pane is visible --> click on the first tab
		if (location.hash) {
			self.click(location.hash);	
		} else {
			self.click(opts.initialIndex);	
		}
	}
		
	// jQuery plugin implementation
	$.fn.tabs = function(query, arg) {		
		// return existing instance
		var el = this.eq(typeof conf == 'number' ? conf : 0).data("tabs");
		if (el) { return el; }
		
		// setup options
		var opts = {
			tabs: 'li',
			current: 'ibm-highlight-tab',
			onBeforeClick: null,
			onClick: null, 
			effect: 'default',			
			initialIndex: 0,			
			event: 'click',
			api:false
		};
		
		if ($.isFunction(arg)) {
			arg = {onBeforeClick: arg};
		}
		
		$.extend(opts, arg);
		
		// install tabs for each items in jQuery		
		this.each(function() {				
			var els = $(this).find(opts.tabs);			
			if (!els.length) {
				els = $(this).children();	
			}			
			var panes = query.jquery ? query : $(query);
			el = new Tabs(els, panes, opts);
			$(this).data("tabs", el);	 
		});		
		return opts.api ? el: this;		
	};		
}) (jQuery);

$=jQuery;

var api;
$(function() {
	api = $("ul.ibm-tabs").tabs("div.ibm-panes > div",{effect:'fade',api: 'true'});
});

function openAllRes(id){	
	api.click(id);
}

$(document).ready(function(){
	$(".expbody").each(function(){
		var expose = $(this).attr("expose");
		if(expose=='true'){
			$(this).show();
			$(this).nextAll(".collapse").eq(0).show();
			$(this).next(".expand").hide();
		}else{
			$(this).hide();
			$(this).nextAll(".collapse").eq(0).hide();
			$(this).next(".expand").show();
		}	
	});
	
	$(".expand").click(function(){
	    	$(this).prev(".expbody").slideDown(300);
	    	$(this).hide();
	    	$(this).next(".collapse").show();
  	});
  	
  	$(".collapse").click(function(){
	    	$(this).prevAll(".expbody").eq(0).slideUp(300);
	    	$(this).hide();
	    	$(this).prev(".expand").show();
  	});	
});


//--- DropMenu ----
 
 $(document).ready(function(){
 	if($("#nav1 li").length>0){
 		$("#nav1 li").dropMenu('nav1');
	}if($("#nav3 li").length>0){
		$("#nav3 li").dropMenu('nav3');
	}
});

jQuery.fn.dropMenu = function(item){	
   	if(item == 'nav1'){
   		$(this).hover(function(){
	   		$(this).find('ul:first').css({visibility: "visible",display: "none"}).show(400);
	   	},function(){
			$(this).find('ul:first').css({visibility: "hidden"});
		});
   	}else{
   		$(this).hover(function(){    	
    		$(this).find('.menu-cont').css({visibility: "visible",display: "none"}).show(400);    	 
    		$(this).find('#dd-img-up').css({display: "none"});
    		$(this).find('#dd-img-down').css({display: "block"});
		},function(){
			$(this).find('.menu-cont').css({visibility: "hidden"});
    		$(this).find('#dd-img-down').css({display: "none"});
    		$(this).find('#dd-img-up').css({display: "block"});
		});
   	}    
};


//----For Tooltip-----

(function($) { 
	
	var effects = { 
		toggle: [
			function() { this.getTip().show(); },  
			function() { this.getTip().hide(); }
		],		
		fade: [
			function() { this.getTip().fadeIn(200); },  
			function() { this.getTip().fadeOut(200); } 
		]		
	};	
		
	$.tools.addTipEffect = function(name, loadFn, hideFn) {
		effects[name] = [loadFn, hideFn];	
	};	

	function Tooltip(trigger, conf) {		
		var self = this;		
		// find the tip
		var tip = trigger.next(); 
		
		if (conf.tip) {			
			// single tip. ie: #tip
			if (conf.tip.indexOf("#") != -1) {
				tip = $(conf.tip);				
			} else {				
				// find sibling
				tip = trigger.nextAll(conf.tip).eq(0);	
				
				// find sibling from the parent element
				if (!tip.length) {
					tip = trigger.parent().nextAll(conf.tip).eq(0);
				}
			} 
		} 
		
		// generic binding function
		function bind(name, fn) {
			$(self).bind(name, function(e, args)  {
				if (fn && fn.call(this) === false && args) {
					args.proceed = false;	
				}	
			});				
			return self;
		}		
		
		// mouse interaction 
		var isInput = trigger.is("input, textarea"); 
		trigger.bind(isInput ? "focus" : "mouseover", function(e) { 	 
			e.target = this;	
			self.show(e);  
			tip.hover(function() { self.show(); }, function() { self.hide(); }); 
		});
		
		trigger.bind(isInput ? "blur" : "mouseout", function() {
			self.hide(); 
		});

		tip.css("opacity", conf.opacity);		
		var timer = 0;
		
		$.extend(self, {				
			show: function(e) {				
				if (e) { trigger = $(e.target); }
				
				clearTimeout(timer);
				
				timer = setTimeout(function(){
					if (tip.is(":animated") || tip.is(":visible")) { return self; } 
								
					/* calculate tip position */ 				 
					// vertical axis
					var top = trigger.position().top - tip.outerHeight();				
					var height = tip.outerHeight() + trigger.outerHeight();				
					var pos = conf.position[0];				
					if (pos == 'center') { top += height / 2; }
					if (pos == 'bottom') { top += height; }
				
					// horizontal axis
					var width = trigger.outerWidth() + tip.outerWidth();
					var left = trigger.position().left + trigger.outerWidth();									
					pos = conf.position[1];
				
					if (pos == 'center') { left -= width / 2; }
					if (pos == 'left')   { left -= width; }	
				
					// offset
					top += conf.offset[0];
					left += conf.offset[1];
				
					// set position
					tip.css({position:'absolute', top: top, left: left});
				
					effects[conf.effect][0].call(self);
					$(self).trigger("onShow");					
				}, conf.predelay || 1);
				
				return self;
			},
			
			hide: function() {  
				clearTimeout(timer); 
				
				timer = setTimeout(function() {
					if (!tip.is(":visible")) { return self; }
					
					effects[conf.effect][1].call(self); 
					$(self).trigger("onHide");
					
				}, conf.delay || 1);
				return self;
			},
			
			isShown: function() {
				return tip.is(":visible, :animated");	
			},
				
			getConf: function() {
				return conf;	
			},
				
			getTip: function() {
				return tip;	
			},
			
			getTrigger: function() {
				return trigger;	
			},
			
			// callback functions			
			onShow: function(fn) {
				return bind("onShow", fn); 		
			},
			
			onHide: function(fn) {
				return bind("onHide", fn); 		
			} 
		});		
	}		
	
	// jQuery plugin implementation
	$.prototype.tooltip = function(conf) {
		
		// return existing instance
		var el = this.eq(typeof conf == 'number' ? conf : 0).data("tooltip");
		if (el) { return el; }
		
		// setup options
		var opts = { 
						
			tip: null,
			effect: 'fade',
			predelay: 0,
			delay: 300,
			opacity: 1, 
			
			// 'top', 'bottom', 'right', 'left', 'center'
			position: ['center', 'right'], 
			offset: [0, 0], 
			api: false 
		};
		
		if ($.isFunction(conf)) {
			conf = {onBeforeShow: conf};
		}
		
		$.extend(opts, conf);
		
		// install tabs for each items in jQuery
		this.each(function() {
			el = new Tooltip($(this), opts);
			$(this).data("tooltip", el);	 
		});
		

		return opts.api ? el: this;		
		
	};
		
}) (jQuery);

/*$(document).ready(function(){	
	$(".mm-search-button-blue").tooltip({opacity: 1,position: ['bottom', 'right'],effect: 'fade',offset: [-35, -16],delay:200});
	$(".mm-search-button-orange").tooltip({opacity: 1,position: ['center', 'right'],effect: 'fade',offset: [57, -16],delay:200});
	$(".mm-search-button-green").tooltip({opacity: 1,position: ['center', 'right'],effect: 'fade',offset: [12, -16],delay:200});
	$(".mm-search-button-purple").tooltip({opacity: 1,position: ['center', 'right'],effect: 'fade',offset: [-33, -16],delay:200});
	$(".mm-search-button-red").tooltip({opacity: 1,position: ['top', 'right'],effect: 'fade',offset: [68, -16],delay:200});	
	$(".mm-search-content-prod-desc").tooltip({opacity: 1,position: ['bottom', 'right'],effect: 'fade',offset: [-49, -65],delay:500});
});*/


$(document).ready(function(){	
	var url="getSubDimension.wss";	
	if($("#tooltip_hw").length>0){
		jQuery.ajax({
			type: "GET",
			url: url,		
			data: "dimID=hardware",
			success: function(response){
			$("#tooltip_hw").append(response);
			$(".mm-search-button-blue").tooltip({opacity: 1,position: ['bottom', 'right'],effect: 'fade',offset: [-35, -26],delay:300,predelay:300});
			}
		});
	}if($("#tooltip_sw").length>0){	
		jQuery.ajax({
			type: "GET",
			url: url,
			data: "dimID=software",
			success: function(response){		
			$("#tooltip_sw").append(response);
			$(".mm-search-button-orange").tooltip({opacity: 1,position: ['center', 'right'],effect: 'fade',offset: [67, -26],delay:300,predelay:300});
			}
		});
	}if($("#tooltip_ind").length>0){	
		jQuery.ajax({
			type: "GET",
			url: url,
			data: "dimID=industry",
			success: function(response){		
			$("#tooltip_ind").append(response);
			$(".mm-search-button-green").tooltip({opacity: 1,position: ['center', 'right'],effect: 'fade',offset: [22, -26],delay:300,predelay:300});
			}
		});
	}if($("#tooltip_its").length>0){	
		jQuery.ajax({
			type: "GET",
			url: url,
			data: "dimID=itsolutionsandservices",
			success: function(response){		
			$("#tooltip_its").append(response);
			$(".mm-search-button-purple").tooltip({opacity: 1,position: ['center', 'right'],effect: 'fade',offset: [-23, -26],delay:300,predelay:300});
			}
		});
	}if($("#tooltip_bs").length>0){	
		jQuery.ajax({
			type: "GET",
			url: url,
			data: "dimID=businessstrategies",
			success: function(response){		
			$("#tooltip_bs").append(response);
			$(".mm-search-button-red").tooltip({opacity: 1,position: ['top', 'right'],effect: 'fade',offset: [75, -26],delay:300,predelay:300});
			}
		});
	}if($("#mm-tooltip-box").length>0){
		$(".mm-search-content-prod-desc").tooltip({opacity: 1,position: ['bottom', 'right'],effect: 'fade',offset: [-83, -75],delay:300,predelay:300});
		$(".mm-ttip-link").tooltip({opacity: 1,position: ['bottom', 'right'],effect: 'fade',offset: [-62, 5],delay:300,predelay:300});
	}
});



//--- search box values ---

$(document).ready(function(){
	if($("#mm-search-input").length>0){
		if($("#searchedterm").val()==''){
			var default_text='';
			$("#mm-search-input").focus(function(){	
				if(default_text==''){
					default_text=$(this).val();
					$(this).val("");
				}else if($(this).val()==default_text)			
				    $(this).val("");
		  	});
		  	
		  	$("#mm-search-input").blur(function(){
		  		if(jQuery.trim($(this).val())=='')
			    	$(this).val(default_text);
		  	});
		} 
	}
});


function submitSearchForm(){document.search_form.submit();}

function chooseNewTopic(topicSelBox){document.location=topicSelBox.options[topicSelBox.selectedIndex].value}

function openLinkInNewWindow(url){window.open(url);}

