/**
* Copyright (c) 2009, Impact Proximity
* All rights reserved.
*/

$(function(){

 if($('div.Register').find('ul').length == 0) $('div.Register').remove();
  
	//global vars
	var locale = "en_gb";
	if(window.location.href.indexOf("ar_ae") > 0)
	locale = "ar_ae";
	
	var isIE = $.browser.msie;
	var isIE6 = isIE && ($.browser.version == 6.0);
	
	var swfEnabled = false;
	swfEnabled = typeof swfobject == "object" && swfobject.hasFlashPlayerVersion("8.0");
	
	// open link in a new window
	var externalLinks = function(){
 $('a[rel=external],a[rel=External]').bind('click',function(){$(this).attr('target','_blank')});
 }
 externalLinks();
	
	//sucker fish solution for ie6
/*	var sfhover = function(){
		$("ul.Nav2 li").hover(
			function(){$(this).addClass('sfhover')},
			function(){$(this).removeClass('sfhover')}
		)
		;
	}
	var hasChild = function(){
		$("ul.Nav2 li li ul").each(function(){
			$(this).parent().addClass("HasChild");			
		})
		;
	}
	hasChild();*/
	
		//sucker fish solution for ie6
	var sfhover = function(){
		$("ul.Nav2 li").hover(
			function(){$(this).addClass('sfhover')},
			function(){$(this).removeClass('sfhover')}
		)
		;
	}
	
	//IE fix
	var applyBgIframe = function(el){
		$(el).find("> ul").bgiframe();
	}
	var hasChild = function(){
		$("ul.Nav2 li li ul").each(function(){
			var $withChild = $(this).parent();
			$withChild.addClass("HasChild");
		})
		;
		//handle submenus that fall outside the page layout
		var bgIFrameEls = $("select.Nav4,div.SearchBy select,.Form1 select.Textbox");
		$("ul.Nav2 > li").hover(function(){
			var $hasChild = $(this).find(".HasChild");
			//bgiframe 2nd level
			if(isIE6 && bgIFrameEls.length && $(this).find("> ul").length) applyBgIframe(this);
			if(!$hasChild.length) return;
			setTimeout(function(){
				var rightPos = $(".Page").offset().left + $(".Page").width() - $hasChild.width()*2;
				var leftPos = $hasChild.offset().left;
				if(locale == "ar_ae") rightPos = $(".Page").offset().left + $hasChild.width();
				if((locale != "ar_ae") && (leftPos > rightPos)) {
					$hasChild.addClass("ReverseMenu");
				}
				if((locale == "ar_ae") && (leftPos < rightPos)){
					$hasChild.addClass("ReverseMenu");
				}
			},10);
		},function(){});
		//bgiframe 3rd level
		$("ul.Nav2 li li.HasChild").hover(function(){
			if(isIE6 && bgIFrameEls.length && $(this).find("> ul").length) applyBgIframe(this);
		},function(){});
	}
	hasChild();
	
	//swap active image on hover of main menu
	var swapImage = function(){
		$("ul.Nav2 > li").hover(
			function(){
				if($(this).hasClass("Selected")) return;
				var imgPath = $(this).find("img:first").attr("src");
				$(this).find("img:first").attr("src",imgPath.replace(".gif","Active.gif"));
			},
			function(){
				if($(this).hasClass("Selected")) return;
				var imgPath = $(this).find("img:first").attr("src");
				$(this).find("img:first").attr("src",imgPath.replace("Active.gif",".gif"));
			}
		);
		$("ul.MainNav > li.Selected > a:first img").each(function(){
			var imgPath = $(this).attr("src");
			$(this).attr("src",imgPath.replace(".gif","Active.gif"));
			$('ul.MainNav > li').bind('mouseover', MainNav_open);
		});
	}
	swapImage();
	
	//add 'FirstChild' and sfhover class for ie6 */
	var firstChild = function(){
		$("li:first-child, td:first-child, th:first-child").addClass("FirstChild");
	}
	firstChild();
	
	var lastChild = function(){
		$("li:last-child, td:last-child, th:last-child").addClass("LastChild");
		//exception
		$("div.Col1 div.News ul li.LastChild").each(function(){
			var $t = $(this);
			if($t.find("> p > img").length) $t.removeClass("LastChild");
		});
	}
	lastChild();
	
	if($.browser.msie && $.browser.version == "6.0") {
		firstChild();
		sfhover();
		try { document.execCommand("BackgroundImageCache", false, true); } catch(err) {}
	}
	
	//auto text handler
 $("input.Textbox")
  .each(function(){
  var autoText = "";
  var defaultText = $(this).val();
  $(this).bind('focus',function(){
  autoText = $(this).val();
  if(autoText == defaultText) $(this).val("");
  })
  .bind('blur',function(){
  if($(this).val() == "")
  $(this).val(defaultText);
  });
 }); 
	
	//generic function to render swf captions
		var swfCaption = function($x,idPrefix,fontColor2){
			$x.each(function(){
				var $me = $(this);
				var i = $x.index($me);
				var _id = idPrefix + i;
				var _text = escape($me.text());
				var _size = parseInt($me.css("fontSize"));
				var _w = $me.width();
				var _h = $me.height();
				var attrs = {};
				var _params = {wmode:'transparent'};
				var fVars = {
					caption:_text,
					fontcolor:"#5b708c",
					fontcolor2:"#5b708c",
					bgcolor:"transparent",
					letterspacing:-.3,
					xposition:0,
					fontsize:_size,
					width:_w,
					height:_h
				};
				if(fontColor2) fVars.fontcolor2 = fontColor2;

				$me.wrapInner("<span class='AltText' />").find("span").css({display:'none'}).end()
				.append("<div class='SwfHolder' />").find(".SwfHolder").attr("id",_id);
				
				//embed swf caption control
				swfobject.embedSWF(captionControlPath, _id , _w, _h, "8.0","expressInstall.swf", fVars, _params, attrs);
			});
		}
		var headers = "div.Block h3";
		headers += ",div.CopyHeader h2";
		headers += ",div.CopyHeader h3";
		headers += ",div.TVCWrap h2 ";
		headers += ",div.Block1 h4";
		headers += ",div.Network h2";
		//headers += ",div.CopyHeader p";
  if(locale == "en_gb") swfCaption($(headers),"SwfCaption");
  
  
 // Tabs show hide
 var tabsAuto = function(){
  var $tabs = $('div.Welcome ul.Tabs li');
  var $pane = $('div.Welcome div');
  
  $tabs.each(function(i){
   var imgPath = $tabs.eq(i).find('img').attr("src");
   $tabs.eq(i).find('img').attr("src",imgPath.replace("Active.gif",".gif"));
  });
  $tabs.removeClass('Selected');
  $pane.hide();
  
  $tabs.find('li:first').addClass('Selected');
		$("div.Welcome ul.Tabs li > a:first img").each(function(){
			var imgPath = $(this).attr("src");
			$(this).attr("src",imgPath.replace(".gif","Active.gif"));
		});
		var $promo = $tabs.eq(0).find('a').attr("href");
		 $('img.promo').attr('src',$promo);
  $pane.eq(0).show(500);
  
  var tab2 = setTimeout(function(){
   $tabs.each(function(i){
    var imgPath = $tabs.eq(i).find('img').attr("src");
    $tabs.eq(i).find('img').attr("src",imgPath.replace("Active.gif",".gif"));
   });
   $tabs.removeClass('Selected');
   $pane.hide();
   
   $tabs.find('li:eq(1)').addClass('Selected');
		 $("div.Welcome ul.Tabs li > a:eq(1) img").each(function(){
			 var imgPath = $(this).attr("src");
			 $(this).attr("src",imgPath.replace(".gif","Active.gif"));
		 });
		 var $promo = $tabs.eq(1).find('a').attr("href");
		 $('img.promo').attr('src',$promo);
   $pane.eq(1).show(500);
  },10000);
  
  var tab3 = setTimeout(function(){
   $tabs.each(function(i){
    var imgPath = $tabs.eq(i).find('img').attr("src");
    $tabs.eq(i).find('img').attr("src",imgPath.replace("Active.gif",".gif"));
   });
   $tabs.removeClass('Selected');
   $pane.hide();
   
   $tabs.find('li:eq(2)').addClass('Selected');
		 $("div.Welcome ul.Tabs li > a:eq(2) img").each(function(){
			 var imgPath = $(this).attr("src");
			 $(this).attr("src",imgPath.replace(".gif","Active.gif"));
		 });
		 var $promo = $tabs.eq(2).find('a').attr("href");
		 $('img.promo').attr('src',$promo);
   $pane.eq(2).show(500);
   var tab1 = setTimeout(tabsAuto,10000);
  },20000); 
  
  $tabs.each(function(){
   $(this).bind('click',function(){
    //clearTimeout(tab1);
    clearTimeout(tab2);
    clearTimeout(tab3);
    if($(this).hasClass('Selected')) return false;
    var imgPath = $(this).find('img').attr("src");
    var $promo = $(this).find('a').attr("href");
    
    $tabs.each(function(i){
     var imgPath = $tabs.eq(i).find('img').attr("src");
     $tabs.eq(i).find('img').attr("src",imgPath.replace("Active.gif",".gif"));
    });
			 
	   $(this).find('img').attr("src",imgPath.replace(".gif","Active.gif"));
    
    $index = $tabs.index($(this));
    var $cur = $pane.eq($index);
    //var $H = $cur.height();
    
    $tabs.removeClass('Selected');
    $(this).addClass('Selected');
    $pane.hide();
    
    $('img.promo').attr('src',$promo);
    $cur.show('slow');
    //$cur.css({height:0});
    //$cur.animate({height:$H},500,'easeOutQuad');
    
    return false;
   })   
  });
 };
 tabsAuto();
 
 // Why How show hide
 var tabs1 = function(){
 /************
  var $tabs = $('div.WhyHow ul li > a');
  
  $tabs.each(function(){
   $(this).bind('click',function(){
    $tabs.parent().removeClass('Selected');
    $(this).parent().addClass('Selected');
    return false;
   })   
  });
 }
 *********/
 
   var $tabs = $('div.WhyHow ul.xTabs li');
   
   var $pane = $('#LatestNews');
   var $pane2 = $('#Discussion');
  //var tabIndex = parseInt($.qString({id:'tabIndex'},location));
  
   $tabs.find('li:first').addClass('Selected');
  
		$("div.WhyHow ul.xTabs li > a img").each(function(){
			var imgPath = $(this).attr("src");
			
		
			//$(this).attr("src",imgPath.replace(".gif","Active.gif"));
		});
 
 	 
 
  $pane.eq(0).show(500);
  $pane2.eq(0).hide(500);
  
  $tabs.each(function(){
   $(this).bind('click',function(){
    if($(this).hasClass('Selected')) return false;
    var imgPath = $(this).find('img').attr("src");
    var $promo = $(this).find('a').attr("rel");
    
	
	
    $tabs.each(function(i){
     var imgPath = $tabs.eq(i).find('img').attr("src");
	 
     $tabs.eq(i).find('img').attr("src",imgPath.replace("Active.gif",".gif"));
    });
			 
	$(this).find('img').attr("src",imgPath.replace(".gif","Active.gif"));
    
	//$(this).find('img').attr("src",imgPath.replace("ActiveActive.gif","Active.gif"));
	
    $index = $tabs.index($(this));
    var $cur = $pane.eq($index);
	var $cur2 = $pane2.eq($index);

    //var $H = $cur.height();
    
    $tabs.removeClass('Selected');
    $(this).addClass('Selected');
    

	if($promo=="Discussion")
	{
	  $pane2.eq(0).show(500);
	  //$pane.hide();
	 // $cur.show('slow');
	}
	else
	{
		$pane2.hide();
		//$cur2.show('slow');
	}
    
   // $('img.promo').attr('src',$promo);
    $pane.hide();
    $cur.show('slow');
    //$cur.css({height:0});
    //$cur.animate({height:$H},500,'easeOutQuad');
    
    return false;
   })   
  });
 }
 
 
 tabs1();
 
 // allow only numeric key strokes
	var numericFilter = function(e,func){
		//fix single quot bug
		if(e.charCode == 39 && e.keyCode == 0) {return false;}
		if(e.charCode == 39 && e.keyCode == 39 || e.charCode == null && e.keyCode == 39) {return false;}
		code = getCharCode(e);
		if(func && !func(code)) return false;
		var validKey = (code > 47 && code < 58);
		//validKey = validKey || (code > 95 && code < 106);
		validKey = validKey || code == 13 || code == 32 || code == 8 || code == 9 || code == 16 || code == 36 || code == 37 || code == 39 || code == 46;
		return validKey;
	}
	
	//List Action Hint
	$("div.Welcome ul.Tabs li a").each(function(){
		var $me = $(this), txt = $me.attr('rel'), $em = $("<em>"+txt+"</em>").css({display:'none'});
		$me.append($em);
		$me.hover(
			function(){
				$em.fadeIn(100);
			},
			function(){
				$em.fadeOut(300);
			}
		);
	});
	
	// random tabs
	//var randomTabs = function(){
 // var $tabs = $('div.Welcome ul.Tabs li');
 // var $pane = $('div.Welcome div');
 // var $num = Math.floor(Math.random() * $tabs.length);
 // var $promo = $tabs.eq($num).find('a').attr("href");
 // 
 // $tabs.removeClass('Selected');
 // $tabs.eq($num).addClass('Selected');
 // $pane.hide();
 //
 // $('img.promo').attr('src',$promo);
 // $pane.eq($num).show('slow');
 // 
 //}
 //randomTabs();
	
	
	 //Footer Sitemap show hide handler
 var pageScroll = function() {
  window.scrollBy(0,200); // horizontal and vertical scroll increments
 }
 var killScroll = function(){
  clearTimeout(scrolldelay);
 }
 $("div.Footer .Handle").toggle(
  function(){
	

   
   var $sitemap = $(this).parent().find(".FooterSitemap");
   var imgSrc = $(this).attr("src");
   $sitemap.slideDown(200);
   $(this).attr("src",imgSrc.replace("Show","Hide"));
   setTimeout(pageScroll,400);
   return false;
   
  },
  function(){ 
   var $sitemap = $(this).parent().find(".FooterSitemap");
   var imgSrc = $(this).attr("src");
   $(this).attr("src",imgSrc.replace("Hide","Show"));
   $sitemap.slideUp(200);
    
   
   return false;
  }
 )
 ;
 
 
  $("div.Footer .HandleClose").click(
  function(){
	
   var $sitemap = $(this).parent().find(".Bookmarks");
   //var imgSrc = $(this).attr("src");
   $sitemap.slideUp(200);
   //$(this).attr("src",imgSrc.replace("Hide","Show"));
   
    var $pane = $('div.Footer .HandleClose');
  $pane.hide();
   return false;
  }/*,
  function(){ 
  var $pane = $('div.Footer .HandleClose');
  $pane.hide();
   var $sitemap = $(this).parent().find(".Bookmarks");
   var imgSrc = $(this).attr("src");
   
   $sitemap.slideDown(200);
   $(this).attr("src",imgSrc.replace("Show","Hide"));
   
   //setTimeout(pageScroll,400);
   return false;
  }*/
 )
 ;
 
 
  $("div.Footer .HandleBookmark").click(
  function(){
	
   var $pane = $('div.Footer .HandleClose');
   $pane.show();
   var $sitemap = $(this).parent().find(".Bookmarks");
   var imgSrc = $(this).attr("src");
   $sitemap.slideDown(200);
   $(this).attr("src",imgSrc.replace("Show","Hide"));
   return false;
  }
 )
 ;
 

	//Scroll box
  var scrollBox = function(){
		 var $Thumb = $('ul.Thumbnails li');
		 var $rev = $('a.Left');
		 var $fwd = $('a.Right');
		 
		 if($Thumb.length <= 4) $('a.Left,a.Right').hide();		 
		 //initialize width of UL
		 var $UL = $('ul.Thumbnails');
		 var LIs = $UL.find('li').length;
		 var LIwidth = 131;
		 $UL.css({width:LIs * LIwidth});
		 
		 $rev.animate({opacity:'.5'},200);
		 
		 //attach click event to scroll buttons
		 $fwd.bind('click',function(){
		     
		 	//scroll UL to the left
		 	$rev.animate({opacity:1},200);
		 	var currLeft = parseInt($UL.css('left'));
		 	var offset = 3 * 131;
		 	if($UL.width() - currLeft*-1 < 917){
		 	 $(this).animate({opacity:'.5'},200);		 	 
		 	}
		 	if($UL.width() - currLeft*-1 < 655) return false;
		 	//alert(currLeft);
		 	$UL.animate({left:currLeft - offset},500);
		  return false;
		 });
		 $rev.bind('click',function(){
		  $fwd.animate({opacity:1},200);
		 	var currLeft = parseInt($UL.css('left'));
		 	var offset = 3 * 131;
		 	if(currLeft >= -393){
		 	 $(this).animate({opacity:'.5'},200);
		 	}
		 	if(currLeft >= 0) return false;
		 	$UL.animate({left:currLeft + offset},500);
		 	return false;
		 });
  }
  scrollBox();
 
 
 	//Scroll box
  var Events_scrollBox = function(){
		 var $Thumb = $('div.Events ul.Thumbnails li');
		 var $rev = $('a.Left');
		 var $fwd = $('a.Right');
		 
		 if($Thumb.length <= 4) $('a.Left,a.Right').hide();		 
		 //initialize width of UL
		 var $UL = $('div.Events ul.Thumbnails');
		 var LIs = $UL.find('li').length;
		 var LIwidth = 100;
		 $UL.css({width:LIs * LIwidth});
		 
		 $rev.animate({opacity:'.5'},200);
		 
		 //attach click event to scroll buttons
		 $fwd.bind('click',function(){
		     
		 	//scroll UL to the left
		 	$rev.animate({opacity:1},200);
		 	var currLeft = parseInt($UL.css('left'));
		 	var offset = 3 * 131;
		 	if($UL.width() - currLeft*-1 < 917){
		 	 $(this).animate({opacity:'.5'},200);		 	 
		 	}
		 	if($UL.width() - currLeft*-1 < 655) return false;
		 	//alert(currLeft);
		 	$UL.animate({left:currLeft - offset},500);
		  return false;
		 });
		 $rev.bind('click',function(){
		  $fwd.animate({opacity:1},200);
		 	var currLeft = parseInt($UL.css('left'));
		 	var offset = 3 * 131;
		 	if(currLeft >= -393){
		 	 $(this).animate({opacity:'.5'},200);
		 	}
		 	if(currLeft >= 0) return false;
		 	$UL.animate({left:currLeft + offset},500);
		 	return false;
		 });
  }
  Events_scrollBox();
 


	//Carousel handler
	$("div.Carousel").each(function(){
		var $me = $(this), $car = $("ul.Thumbnails",$me), $thumbs = $("li",$car), $canvas = $me.prev('.Canvas');
		var $caption = $me.next('.PictureTitle').css({display:'block'});
		var $left = $("a.Left",$me), $right = $("a.Right",$me);
		//if($thumbs.length <= 4){$left.hide();$right.hide();}
		//var _tLen = 3, _thumbW = 230, _totalW = (Math.ceil($thumbs.length/_tLen)) * _tLen * _thumbW;
		//if($me.hasClass('Carousel_1')){
		//	_tLen = 6; _thumbW = 95; _totalW = (Math.ceil($thumbs.length/_tLen)) * _tLen * _thumbW;
		//}
		//if($me.hasClass('Carousel_2')){
		//	_tLen = 5; _thumbW = 86; _totalW = (Math.ceil($thumbs.length/_tLen)) * _tLen * _thumbW;
		//}
		//if($me.hasClass('MonthPick')){
		//	_tLen = 6; _thumbW = 74; _totalW = (Math.ceil($thumbs.length/_tLen)) * _tLen * _thumbW;
		//}
  //
		////adjust car width
		//$car.css({left:0,width:_totalW});
		//
		////slide handler
		//$left.click(function(){
		//	if(currPos() >= 0 || $car.is(':animated')) return false;
		//	moveCar('+');
		//	return false;
		//});
		//$right.click(function(){
		//	if(currPos()*-1 >= _totalW - (_thumbW*_tLen) || $car.is(':animated')) return false;
		//	moveCar('-');
		//	return false;
		//});
		//
		//var currPos = function(){
		//	return parseInt($car.css('left'));
		//}
		//var moveCar = function(dir){
		//	$car.animate({left:(dir+'='+(_thumbW*_tLen)+'px')},600,function(){
		//		updateButtons();
		//	});
		//}
		//
		//var updateButtons = function(){
		//	if(currPos() >= 0) $left.css({opacity:.3});
		//	else $left.css({opacity:1});
		//	if(currPos()*-1 >= _totalW - (_thumbW*_tLen)) $right.css({opacity:.3});
		//	else $right.css({opacity:1});
		//}
		//updateButtons();
		
		//populate preview images on Canvas
		if(!$me.hasClass('Carousel_1')){
			$canvas.find("img").remove();
			$thumbs.find("> a").each(function(i){
				var $t = $(this), _path = $t.attr('href');
				var $img = $(new Image());
				$img.attr('src',_path).addClass('thumb_'+i);
				$img.appendTo($canvas);
				if(i<1){
					$caption.text($t.find("img").attr("title"));
				}
			}).click(function(){
				var n = $thumbs.find("> a").index(this);
				$("img.thumb_"+n,$canvas).css({opacity:0,zIndex:2}).animate({opacity:1},800,function(){
					$("img.Active",$canvas).css({zIndex:0}).removeClass('Active');
					$(this).css({zIndex:1}).addClass('Active');
				});
				$caption.text($(this).find("img").attr("title"));
				return false;
			});
			$canvas.find("img:first").addClass('Active');
		}
	});



/****************/

//Carousel handler


/***************/


	$(".msg_bodyOF").hide();		   

	$(".msg_headOF").toggle(function(){
		var $tabs = $('.msg_headOF');

		$tabs.each(function(i){
			var imgPath = $tabs.eq(i).find('img').attr("src");
			$tabs.eq(i).find('img').attr("src",imgPath.replace("CloseButton.gif","OpenButton.gif"));
			$(".msg_bodyOF,.GoogleMap").hide();
			});
		
		$(this).next(".msg_bodyOF").slideDown(250,function(){
			$(this).parent().next('.GoogleMap').fadeIn(300);
		});
		$(this).find("img").attr("src",$(this).find("img").attr("src").replace("OpenButton.gif","CloseButton.gif"));
	},
	function(){
		$(this).next(".msg_bodyOF").slideUp(250,function(){
			$(this).parent().next('.GoogleMap').fadeOut(300);
		});
		$(this).find("img").attr("src",$(this).find("img").attr("src").replace("CloseButton.gif","OpenButton.gif"));
	});


	$(".msg_body").hide();		   
	$(".msg_head").toggle(function(){
		$(this).next(".msg_body").slideDown(250);
		$(this).find("img").attr("src",$(this).find("img").attr("src").replace("OpenButton.gif","CloseButton.gif"));
	},function(){
	 $(this).next(".msg_body").slideUp(250);
		$(this).find("img").attr("src",$(this).find("img").attr("src").replace("CloseButton.gif","OpenButton.gif"));
	});


	  $('#Player').hide();
   
   			$('a#click').click(function(){
			
			
   var fVars = {
					bgcolor:"transparent",
					width:340,
					height:280,
					filePath:'/$Common/Media/TV_30s_En512K_Stream512K_Stream.flv'
				};
				
				if(locale == 'ar_ae') var fVars = {filePath:'/$Common/Media/Laptop_30s_Ar_wav512K_Stream512K_Stream.flv'};
				
				var _params = {wmode:'transparent'};
				
				var attrs = {};

				//embed swf caption control
				swfobject.embedSWF('/$Common/Flash/InnerVidPlayer.swf', 'vidPlayer' , 340, 280, "8.0","expressInstall.swf", fVars, _params, attrs);
				$('#Player').fadeIn(200);
   });
   
   $('a#close').click(function(){
   		$('#Player').fadeOut(100);
   		$('#Player embed,#Player object').remove();
   		$('#Player').append('<img src="/$Common/Images/Background/Player.gif" alt="" id="vidPlayer"/>');
		});
   
 var banner = function(){
   var fVars = {
					bgcolor:"transparent",
					width:285,
					height:245
				};
				
				var _params = {wmode:'transparent'};
				
				var attrs = {};

				$("div.SwfBanner").find('img').css({display:'none'}).end()
				.append("<div class='SwfHolder' />").find(".SwfHolder").attr("id","SwfHolder");
				
				//embed swf caption control
				swfobject.embedSWF('Common/Flash/HowTo.swf', 'SwfHolder' , 285, 245, "8.0","expressInstall.swf", fVars, _params, attrs);
  }
 banner();


//faq style
  var FAQs = function()
 {
 	$('ul.List_4 > li div a.close').click(function(){
 		
 		removeSelected(); 
 		return false;
 		});
  $('ul.List_4 > li').click(function(){
   removeSelected();
   $(this).addClass('Active');
   return false;
  });
  function removeSelected()
  {
    $('ul.List_4 > li').each(function(){
    $(this).removeClass('Active');
   });
  }
 }
 FAQs();
 
 if($('img.FaqCloseButton').length > 0) $('img.FaqCloseButton').attr('src', $('img.FaqCloseButton').attr("src").replace("CloseButton.gif","OpenButton.gif")); 
 
 var vidGallery = function(){
  
  //Carousel handler
	$("div.VidCarousel").each(function(){
		var $me = $(this), $car = $("ul.VidThumbnails",$me), $thumbs = $("li",$car), $canvas = $me.prev('.Canvas');
		var $left = $("a.Left",$me), $right = $("a.Right",$me);
		if($thumbs.length <= 4){$left.hide();$right.hide();}
		var _tLen = 3, _thumbW = 230, _totalW = (Math.ceil($thumbs.length/_tLen)) * _tLen * _thumbW;
		if($me.hasClass('Carousel_1')){
			_tLen = 6; _thumbW = 95; _totalW = (Math.ceil($thumbs.length/_tLen)) * _tLen * _thumbW;
		}
		if($me.hasClass('Carousel_2')){
			_tLen = 5; _thumbW = 86; _totalW = (Math.ceil($thumbs.length/_tLen)) * _tLen * _thumbW;
		}
		if($me.hasClass('MonthPick')){
			_tLen = 6; _thumbW = 74; _totalW = (Math.ceil($thumbs.length/_tLen)) * _tLen * _thumbW;
		}

		//adjust car width
		$car.css({left:0,width:_totalW});
		
		//slide handler
		$left.click(function(){
			if(currPos() >= 0 || $car.is(':animated')) return false;
			moveCar('+');
			return false;
		});
		$right.click(function(){
			if(currPos()*-1 >= _totalW - (_thumbW*_tLen) || $car.is(':animated')) return false;
			moveCar('-');
			return false;
		});
		
		var currPos = function(){
			return parseInt($car.css('left'));
		}
		var moveCar = function(dir){
			$car.animate({left:(dir+'='+(_thumbW*_tLen)+'px')},600,'easeOutCubic',function(){
				updateButtons();
			});
		}
		
		var updateButtons = function(){
			if(currPos() >= 0) $left.css({opacity:.3});
			else $left.css({opacity:1});
			if(currPos()*-1 >= _totalW - (_thumbW*_tLen)) $right.css({opacity:.3});
			else $right.css({opacity:1});
		}
		updateButtons();
		
		
	});
  
	var $path = $('div.VideoGallery ul.VidThumbnails a:first').attr('href');
			
	var fVars = {
		bgcolor:"#000000",
		width:575,
		height:340,
		play: 'false',
		filePath:$path
	};
				
	var _params = {wmode:'transparent'};
	var attrs = {};
	swfobject.embedSWF('/$Common/Flash/GalleryVidPlayer.swf', 'video' , 575, 340, "8.0","expressInstall.swf", fVars, _params, attrs);
  
	$('div.VideoGallery ul.VidThumbnails a').click(function(){
		$path = $(this).attr('href');	
		var fVars = {filePath:$path};
		swfobject.embedSWF('/$Common/Flash/GalleryVidPlayer.swf', 'video' , 575, 340, "8.0","expressInstall.swf", fVars, _params, attrs);
		return false;
	});
 }
 vidGallery();

});



//Query String jQuery extension
(function($){$.qString=function(options){defaults={defaultvalue:"null"};options=$.extend(defaults,options);if(options.theURL){qs=options.theURL.split("?")[1];}else{qs=location.search.substring(1,location.search.length);}if(qs.length==0)return options.defaultvalue;qs=qs.replace(/\+/g,' ');var args=qs.split('&');for(var i=0;i<args.length;i++){var value;var pair=args[i].split('=');var name=unescape(pair[0]);if(pair.length==2){value=unescape(pair[1]);}else{value=name;}if(name==options.id||i==options.id-1){return value;}}return options.defaultvalue};})(jQuery);


//global functions
function submitYourTip_en_gb(){
	//window.open('/mynationalbonds/howtosaveonline_en_gb.aspx');
	window.location.href = '/mynationalbonds/howtosaveonline_en_gb.aspx';
}

function submitYourTip_ar_ae(){
	//window.open('/mynationalbonds/howtosaveonline_ar_ae.aspx');
	window.location.href = '/mynationalbonds/howtosaveonline_ar_ae.aspx';
}