jQuery(document).ready(function(){
	jQuery("a[rel^='prettyPhoto']").prettyPhoto({
		allowresize:false,
		theme:'light_rounded' 
		// theme:'light_rounded'
		// theme:'dark_rounded'
		// theme:'light_square'
		// theme:'dark_square'
	});

	// Individuals Behaviours For Main Sections Titles
	$jq('#accordion .mainHead').click(function() {
		if( $jq(this).next().css( 'display' ) != 'block' ) {
			$jq(this).next().slideDown();
			$jq(this).toggleClass('iconDown');
			$jq(this).toggleClass('iconUp');
			return false;				
		}
		else{
			$jq(this).next().slideUp();
			$jq(this).next().children('div.secondChild').slideUp();
			$jq(this).toggleClass('iconDown');
			$jq(this).toggleClass('iconUp');
			return false;
		}
	}).next().hide('normal');
	
	// Individuals Behaviours For Questions Titles
	$jq('#accordion .secondHead').click(function() {
		$jq(this).parent().children("div.secondChild").slideUp();
		if( $jq(this).next().css('display') != 'block' ) 
			$jq(this).next().slideDown();
		return false;
	}).next().hide('normal');
												  
	// Show All Answers
	$jq("#showAll").click(function () { 
		$jq("#accordion .mainHead").removeClass("iconUp").removeClass("iconDown").addClass("iconUp");
		$jq(".mainChild").slideDown(500);
		$jq("#hideAll").toggle();
		$jq("#showAll").toggle();
		return false;
	});
	
	// Hide All Answers
	$jq("#hideAll").click(function () { 
		$jq("#accordion .mainHead").removeClass("iconUp").removeClass("iconDown").addClass("iconDown");
		$jq(".mainChild").slideUp(500);
		$jq(".mainChild").children("div.secondChild").slideUp();
		$jq("#showAll").toggle();
		$jq("#hideAll").toggle();
		return false;
	});
	
	$jq("#hideAll").hide();
});

/***********************************************************************/
// videos overlay code begin here
/* component Upload Photo Tips javascript */
function loaderClose( div ){
	var movie = div;
	if (movie.PercentLoaded() == 100) { $jq(".loaderIcon").hide(); clearTimeout(videotime);}
}
var currDiv;
var currLink;

function swapimageclose_pt( img ){ 
	$jq('.swap_img_pt').attr('src',img);
}

function Init_faq1( div, divLink ) { 
	currDiv=div; 
	currLink=divLink; 
	Jabo_FAQ1.init(640,480);
}

var InnerCode_faq1;
Jabo_FAQ1={
	options:{'animationSpeed':'fast', 'padding':40, 'opacity':0.60},
	init:function(){Jabo_FAQ1.open();$jq(window).scroll(function(){Jabo_FAQ1.centerPicture();});$jq(window).resize(function(){Jabo_FAQ1.centerPicture();})},
	open:function(caller){Jabo_FAQ1.buildOverlay(Jabo_FAQ1.isSet);Jabo_FAQ1.centerPicture();objectCreate();checkLoader();},
	centerPicture:function(){if($jq('div.pictureHolder_tips_'+currDiv).size()>0){var scrollPos=Jabo_FAQ1.getScroll();if($jq.browser.opera){windowHeight=window.innerHeight;windowWidth=window.innerWidth;}else{windowHeight=$jq(window).height();windowWidth=$jq(window).width();};$jq('div.pictureHolder_tips_'+currDiv).css({'top':(windowHeight/2)+scrollPos['scrollTop']-($jq('div.pictureHolder_tips_'+currDiv).height()/2),'left':(windowWidth/2)+scrollPos['scrollLeft']-($jq('div.pictureHolder_tips_'+currDiv).width()/2)});};},
	buildOverlay:function(){
		
		backgroundDiv = "<div class='prettyPhotoOverlay_tips'></div>";
		$jq('body').append(backgroundDiv);
		$jq('div.prettyPhotoOverlay_tips').css('height',$jq(document).height());
		$jq('.prettyPhotoOverlay_tips').bind('click',function(){Jabo_FAQ1.close();});
		
		InnerCode_faq1 = $jq('#'+currDiv).html();
		$jq('#'+currDiv).empty();
		
		// Basic HTML for the picture holder
		pictureHolder_tips = '<div class="pictureHolder_tips_'+currDiv+'"><div class="loaderIcon" id="loaderBg_'+currDiv+'"></div><div class="content_tips">'+InnerCode_faq1+'</div></div>';
		
		$jq('body').append(pictureHolder_tips);
		// Then fade it in
		$jq('div.prettyPhotoOverlay_tips').css('opacity',0);
		$jq('div.prettyPhotoOverlay_tips').fadeTo(Jabo_FAQ1.options['animationSpeed'],Jabo_FAQ1.options['opacity'], function(){
			$jq('div.pictureHolder_tips_'+currDiv).fadeTo(Jabo_FAQ1.options['animationSpeed'],1,function(){
				// To fix an IE bug
				$jq('div.pictureHolder_tips_'+currDiv).attr('style','left:'+$jq('div.pictureHolder_tips_'+currDiv).css('left')+';top:'+$jq('div.pictureHolder_tips_'+currDiv).css('top')+';');
			});
		});
		$jq('.loaderIcon').show();
	},
	getScroll : function(){
		scrollTop = window.pageYOffset || document.documentElement.scrollTop || 0;
		scrollLeft = window.pageXOffset || document.documentElement.scrollLeft || 0;
		return {scrollTop:scrollTop,scrollLeft:scrollLeft};
	},
	resize : function(width,height){
			
			contentHeight = parseFloat($jq('div.pictureHolder_tips_'+currDiv+' .details').height()) + parseFloat($jq('div.pictureHolder_tips_'+currDiv+' .details').css('margin-top')) + parseFloat($jq('div.pictureHolder_tips_'+currDiv+' .details').css('margin-bottom'));
			containerHeight = contentHeight + parseFloat($jq('div.pictureHolder_tips_'+currDiv+' .top').height()) + parseFloat($jq('div.pictureHolder_tips_'+currDiv+' .bottom').height());
			containerWidth = parseFloat($jq('div.pictureHolder_tips_'+currDiv+' .content_tips').css("padding-left")) + parseFloat($jq('div.pictureHolder_tips_'+currDiv+' .content_tips').css("padding-right")) + Jabo_FAQ1.options['padding'];
			
			var newWidth = width;
			var newHeight = height;
			if($jq.browser.opera) {
				windowHeight = window.innerHeight;
				windowWidth = window.innerWidth;
			}else{
				windowHeight = $jq(window).height();
				windowWidth = $jq(window).width();
			};
			
			if((containerWidth + width) > windowWidth || (containerHeight + height) > windowHeight) {
				// Get the original geometry and calculate scales
				var xscale=(width+containerWidth + 100)/windowWidth;
				var yscale=(height+containerHeight + 100)/windowHeight;
			
				// Recalculate new size with default ratio
				if (yscale>xscale){
					newWidth = Math.round(width * (1/yscale));
					newHeight = Math.round(height * (1/yscale));
				} else {
					newWidth = Math.round(width * (1/xscale));
					newHeight = Math.round(height * (1/xscale));
				};
			};
			// Get the container size, to resize the holder to the right dimensions
			containerHeight += newHeight;
			contentHeight += newHeight;
			containerWidth += newWidth;
			return {
				width:newWidth,
				height:newHeight,
				containerHeight:containerHeight,
				containerWidth:containerWidth,
				contentHeight:contentHeight
			};
		},
	close : function()
	{
		swapimageclose_pt('layouts/ng/img/prettyPhoto/btnClose.gif');
		$jq('div.pictureHolder_tips_'+currDiv).fadeTo(Jabo_FAQ1.options['animationSpeed'],0,function(){
			$jq('div.prettyPhotoOverlay_tips').fadeTo(Jabo_FAQ1.options['animationSpeed'],0,function(){
				$jq('div.prettyPhotoOverlay_tips').remove();
				$jq('div.pictureHolder_tips_'+currDiv).remove();
				
				$jq('#'+currDiv).html(InnerCode_faq1);
				
				// To fix the bug with IE select boxes
				if($jq.browser.msie && $jq.browser.version == 6){
					$jq('select').css('visibility','visible');
				};
			});
		});
		swfobject.removeSWF(currDiv+"Video");
	}
}

function swapimageTut(img,imgId) 
{  
	document.getElementById(imgId).src = img; 
}

function objectCreate () 
{
	var req = swfobject.hasFlashPlayerVersion("9.0.115");

	if( req )
	{	
		if( (currDiv=='faq1') || (currDiv=='faq3') || (currDiv=='faq4') || (currDiv=='faq6') || (currDiv=='faq9') )
		{
			var flashvars  = {};
			var params     = { menu:'false', quality:'best', wmode:'transparent', scale:'noorder', salign:'transparent' };
			var attributes = {};
		
			swfobject.embedSWF( currLink+'/'+currDiv+'.swf', currDiv+'Video', '390', '228', '6.0.0', '',flashvars, params, attributes );
		}
		else
		{
			var flashvars  = {};
			var params     = { quality:'best', allowfullscreen:'true', scale:'showall', allowscriptaccess:'always', salign:'transparent', wmode:'transparent' };
			var attributes = {};
			
			swfobject.embedSWF( currLink+'/'+currDiv+'.swf', currDiv+'Video', '640', '505', '9.0.115', currLink+'/expressInstall.swf', flashvars, params, attributes );
		}
	}
}

function checkLoader () 
{
	var movie = $jq('#faq'+currDiv+'Video');
	var iconVar;
	try
	{
		if (movie.PercentLoaded() == 100) 
		{
			clearTimeout(iconVar);
			$jq('.loaderIcon').css('display','none');
		}
		else
		{
			iconVar=setTimeout("checkLoader()",1000);
		}
	}
	catch(err)
	{
		iconVar=setTimeout("checkLoader()",100);
	}
}

function checkFaqVideo( faqNum, faqLink )
{
	var faqVar;
	try
	{
		if($jq('#'+faqNum).css('display') != undefined )
		{
			clearTimeout(faqVar);
			Init_faq1( faqNum, faqLink );
		}
		else
		{
			faqVar = setTimeout( "checkFaqVideo( '"+faqNum+"','"+faqLink+"')",1000);
		}
	}
	catch(err)
	{
		faqVar = setTimeout( "checkFaqVideo( faqNum,faqLink )", 100 );
	}
}
