var api,srcpath,srchover;
$('document').ready(function(){
 keyboard_arrows();

/*fix for ie6*/
 if($.browser.msie && $.browser.version==6.0){
        $('#logo a img, #search_form input.searchsubmit, #prev, #next, #search_form input.searchsubmit, #footer #footer-menu ul li a').addClass('png-bg-fix');
        $('.container #content .slider-description a, .subnav .headerbar, .slider-description').addClass('png-bg-fix');
        DD_belatedPNG.fix('.png-bg-fix');
        
        //Slider Description on hover functionality for IE6(show/ hide tooltip on hover)
        $('.slider-description .navi ul li').hover(function(){
                $(this).find('.tooltip').show();
        }, function(){
            $(this).find('.tooltip').hide();
        });
        
        $("#sites li").hover(function(){
                $(this).find('ul').show();
        }, function(){
            $(this).find('ul').hide();
        });
        }
		
   $('#search-btn input').focus(function() {
		 $('html').unbind('keydown');
		})
			
		.blur(function() {
			keyboard_arrows();
		});

	if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
	    $('#arrows > a').unwrap();
	    $("#nav li#aboutus a").css({'width':'70px'});
		$(".container #content #scrollable ul li").css({'margin':'0 0 0 54px','width':'3.05%','min-width':'3.12%'}); 
        $(".container #footer").css({'width':'78.2%','min-width':'400px'});	
		$(".container #footer .footer-box").css({'border-width':'10px 9px 0','min-width':'400px'});
		$("#masthead #sites li #search-btn input").css({'margin':'0','padding':'0'});
		$("#footer .footer-box .column-about-us").css({'width':'65%'});
		$("#footer #news-box #footer-menu-content ul li img").css({'width':'31%'});
		$("#footer #news-box #footer-menu-content ul li").css({'width':'390px'});
		$("#footer #about-box a").css({'margin':'0px'}); 
		$(".row").css({'overflow':'none','clear':'both'});
		$(".container #content .slider-description").css({'width':'22%'});
        $(".container #content .navi ul.small li").css({'width':'65px','height':'65px'});		
	} 
	/* Fix for scrollable for Chrome */
    if(navigator.userAgent.indexOf('Win') > 0 && navigator.userAgent.indexOf('Chrome') > 0)
    { 
	  $("#content-wrapper #content #scrollable ul").css({'margin':'0 0 0 11%'});
	  $("#footer .footer-box").css({'width':'97.8%'});
	  $("#footer").css({'margin-right':'11.2%'});
    } 
	
	if(navigator.userAgent.indexOf('Mac') > 0 && navigator.userAgent.indexOf('Safari') > 0)
    { 
	  $("#content-wrapper #content #scrollable ul").css({'margin':'0 0 0 11%'});
	  $("#footer .footer-box").css({'width':'97.76%'});
    }

	if(navigator.userAgent.indexOf('Mac') > 0 && navigator.userAgent.indexOf('Chrome') > 0)
    { 
	   $("#footer").css({'margin-right':'11.2%'});
    } 
	

	/* column-media hover effect */
	$(".column-media li.media").hover(function() {
		/* condition to close footer-menu if mouse is hovered on column-media */
		if ($('#footer-menu ul').is(':visible'))
		{
			$('#footer-menu ul').slideUp('fast');
		}
	
		$(this).children('div').css({'z-index':'1002'});
		$(this).children('div').stop().animate({
			width: '445px', 
			height: '278px'
		}, 500,function(){
			$(this).addClass('shadow',10);
		});
	},function(){
	$(this).children('div').removeClass('shadow');
	$(this).children('div').stop().animate({
			width: '178px', 
			height: '85px'
		}, 200,function(){
			$(this).css({'z-index':'1001'});
		});
	});

	var videopath = "http://172.16.0.100/tibcorevamp/tibco-redesign/";
	var swfplayer = videopath + "flash/flowplayer-3.2.5.swf";
	
	$('a.pdf').click(function(){
		window.open(this.href);  
		return false;
	});
	
	/*$("a[href$=.jpg],a[href$=.png],a[href$=.gif]").fancybox({
	'overlayShow': true,
	'transitionIn'	: 'elastic',
	'transitionOut'	: 'elastic',
	'easingIn'      : 'easeInOutBack',
	'easingOut'     : 'easeInBack',
    'autoscale'  : 'true',
	'onComplete' :function()
	{
		api = $("div.zoom").scrollable({api: false,circular: false});api.stop();
	}
    }); */

	var videoclip='';
	var player='';
	
	$("a.video").hover(function(){
		videoclip=$(this).attr('href');
		$(this).attr({"href":"#video_box"});
	},
	
	function(){
		$(this).attr({"href":""+videoclip+""});
	});
	
	/*$("a.video").fancybox({
		'hideOnContentClick':false,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'easingIn'      : 'easeInOutBack',
		'easingOut'     : 'easeInBack',
		'overlayOpacity' :0.8,
		'type': 'swf',
		'onComplete' :function(){
		     	player = $f("fancy_div",swfplayer,{
				play:{opacity:0},
				clip:{
					autoPlay:false,
					autoBuffering:true,
					url:videopath+videoclip+'',
					   onStart:function(clip){
						var wrap=jQuery(this.getParent());
						var clipwidth = clip.metaData.width;
						var clipheight= clip.metaData.height;
						var pos = $.fn.fancybox.getViewport();
						$("#fancybox-outer").css({width:clipwidth,height:clipheight});
						$("#fancybox-outer").css('left', ((clipwidth + 36) > pos[0] ? pos[2] : pos[2] + Math.round((pos[0] - clipwidth	- 36)	/ 2)));
					    $("#fancybox-outer").css('top',  ((clipheight + 50) > pos[1] ? pos[3] : pos[3] + Math.round((pos[1] - clipheight - 50)	/ 2)));
					}
				},
				onLoad: function () {
				  this.pause();
				}
				
			}).ipad();
			player.load();
				$('#fancybox-close').click(function(){
				$("#fancy_div_api").remove();
			});
		},
		'callbackOnClose':function(){
			$("#fancy_div_api").remove();
		}
	}); */

		$('a#discover').click(function() {
			$('#footer-menu ul').slideToggle();
			return false;
		});

/* temporary condition to avoid scroller function on sceondary page */		
	if($('#scrollable').length)
	{
		scrollcarousel();
	}
	
	/* resize scroller arrows on window resize */
	 $(window).resize(function()
	 {
          var winWidth = $(window).width();
		   if (winWidth > 1140)
		  {
		    $('#arrows').css({'width':1140});
		  }  	
        else if(winWidth < 913)
           {		
            $('#arrows').css({'width':913});
		  }
		  else 
		   {
            $('#arrows').css({'width':winWidth});    		  
           }
    });
	
	
    stopclick();
    footerMenu();

	/*Move footer menu under footer wrapper*/
		$('#footer-menu').clone(true).insertAfter("#footer-links");
		$('#footer-menu').remove();

	$('#footer-menu li a').toggle(function(){
		$footBox = $(this).attr('href');
		$('#footer-menu li.active a').click();
		$sibling = $($footBox).siblings('.footer-box');
		
		if($($sibling).is(':visible'))
		{
			$($sibling).css('display','none');
			$($footBox).removeClass('hidden').show();
		}
		else
		{
			$($footBox).slideDown();
		}
    $(this).parents('li').toggleClass('active');
	}, function(){
	if($($footBox).is(':visible'))
	{
		$($footBox).slideUp();
	}
    $(this).parents('li').toggleClass('active');
  });
	
	 
		$("#footer-menu-content").scrollable({keyboard:false,circular: true,speed:1000}).autoscroll(6000).navigator();	
		//$("#footer-menu-content").scrollable();
		
		
		
		/* To stop footer scrollable when manually clicked on Navi*/
		$('#footer .navi a').click(function()
	 {
		 api = $("#footer-menu-content").scrollable({api: false,circular: false});api.stop();
   });	
		
	$('#footer .close').click(function() {
		$('#footer-menu li.active a').click();
	});	
	
});	/* end of document.get ready */

	
  /* footer menu code*/
 /* function footerMenu(){
		$('#news-box').slideDown('slow',function(){
			setTimeout(function(){
				$('#news-box').slideUp('fast');
			},1000);
			
			setTimeout(function(){
			    $('#about-box').slideDown('slow',function(){
			        setTimeout(function(){
			    	$('#about-box').slideUp('fast');
			        },1000);
			    });
			},2000);
			 		
		}); 

  } */
  
  function footerMenu(){
		
			setTimeout(function(){
				//$('#news-box').slideUp('fast');
				$('#news a').trigger("click");
			},0);
			
			setTimeout(function(){
			     setTimeout(function(){
			    	$('#news a').trigger("click");
			        },500);
			},1000);
			$('html').focus();
	}
  
 
  /* Carousel scroll main function */  
  function scrollcarousel()
 {
       $('#scrollable').scrollable({ keyboard:false,circular:true,speed:700}).navigator({
        navi:'.navi ul'
	});
  
	var api = $("#scrollable").data("scrollable");
	 api.move(0);
	  api.getConf().keyboard = true;
	 /* setTimeout( function() {
		 api.move(0);
	},0);*/ 

	api.onSeek(function()  
		{   
		    var i = this.getIndex();
			$('.slider-description .desc').html($('#scrollable ul li:eq('+(i+1)+') .desc').html());
			$('.slider-description .navi ul li').removeClass('navi-selected navi-default');
			$('.slider-description .navi ul li').addClass('navi-selected');
			$('.slider-description .navi ul li:eq('+(i)+')').addClass('navi-default');
           		   
          /*  if ($('.slider-description .navi ul li:eq('+(i)+')').hasClass("active"))  
			{
			
				var tstsrc =  $('.slider-description .navi ul li:eq('+(i)+') img').attr('src').replace('.png','-hover.png');
		   $('.slider-description .navi ul li:eq('+(i)+') img').attr('src',tstsrc);
			 
			}
            else
			{ 
			  $('.slider-description .navi ul li:eq('+(i)+') img').attr('src').replace('-hover.png','.png');
			}	

			
			    $(".slider-description .navi ul li").not(".active").each(function() {
			          
			          $(this).css({'background':'red'});  
			    }); */
					
			
			/*var tstsrc =  $('.slider-description .navi ul li:eq('+(i)+') img').attr('src').replace('.png','-hover.png');
		   $('.slider-description .navi ul li:eq('+(i)+') img').attr('src',tstsrc);
			*/
			
			 
		        $('.slider-description .navi ul li').each(function(index) {

			       if ($(this).is('.navi-default')) { 
			        //$(this).css({'background':'red'});
					var source = $('img', $(this)).attr('src');
					if(source.indexOf('hover') == -1)
					{
						var tstrc = $('img', $(this)).attr('src').replace('.png','-hover.png');
						$('img', $(this)).attr('src',tstrc);   
						$('.pre-no', $(this)).addClass('toolip-no');
			      }
               } 
				  else {
				    //$(this).css({'background':'#fff'});
				    var tstrc1 = $('img', $(this)).attr('src').replace('-hover.png','.png');
				    $('img', $(this)).attr('src',tstrc1).css({'background':'none'});
					$('.pre-no', $(this)).removeClass('toolip-no');
				  }
			
			});
			
			
			
			
			
	  });
	
 }

 
 /* function to prevent click of scrollable */
	function stopclick()
  {
    $('#scrollable ul li > div, #scrollable ul > li, #scrollable ul li img').click(function(e) {
			e.stopPropagation();
			e.preventDefault();
		});
  }
  
  /* function to click boxes inside scrollable */
  function navi_scroll()
  {
		$('.navi ul li').click(function()
		{ 
			var tmp = $(this).attr('id');
			var tmp1 = tmp.replace('nav',"");
			api.seekTo(tmp1);
		});
  }
  

 	
	function BlankWin(url)
	{
    blankWin=window.open(url,'_blank');
	}
	
	
	function keyboard_arrows()
	{
		$('html').bind('keydown', function(event) {
		   if(event.keyCode ==39)
		   {
			 $('#next').trigger('click');
			 
		   }
		   else if(event.keyCode ==37)
		   {
			 $('#prev').trigger('click');
		   }
		});
	}
	
