// JavaScript Document

$(document).ready(function() {
						   
	//Sidepanel Hide/Show
	$("#updateButton").click(function(){
		$("#updateButton").hide("fast");
		$("#updateText").show("slow");
		return false
	});
	
	// FAQ Hide/Show
	$('.faqBody').hide();
	$('.faqTitle').hover(function(){
		$(this).addClass('faqTitleHover');
	},function(){
		$(this).removeClass('faqTitleHover');
	});
	$("div.faqTitle").click(function(){
		$(this).next(".faqBody").toggle().siblings(".faqBody:visible").hide();
		$(this).toggleClass("faqTitleHide");
		$(this).siblings(".faqTitle").removeClass("faqTitleHide");
		return false
	});
	
	// Support Hide/Show
	$("div#supportContent").children("div.supportBox:hidden").children("div.tab").removeClass("tabInactive,tabActive");
	$("#supportFiles").click(function() {
		$('#downloads,#upgrades').hide();
		$('#supportDownloads,#supportUpgrades').addClass("tabInactive").css({WebkitBorderBottomRightRadius:0,MozBorderRadiusBottomright:0});
		$('#supportFiles').removeClass("tabInactive").css({WebkitBorderBottomLeftRadius:0,MozBorderRadiusBottomLeft:0});
		$('#files').toggle();
		return false
	});
	
	$('#supportDownloads').click(function() {
		$('#files,#upgrades').hide();
		$('#supportFiles,#supportUpgrades').addClass("tabInactive").css({WebkitBorderBottomRightRadius:0,MozBorderRadiusBottomright:0,WebkitBorderBottomLeftRadius:0,MozBorderRadiusBottomLeft:0});
		$('#supportDownloads').removeClass("tabInactive");
		$('#downloads').toggle();
		return false
	});
	
	$('#supportUpgrades').click(function() {
		$('#files,#downloads').hide();
		$('#supportDownloads,#supportFiles').addClass("tabInactive").css({WebkitBorderBottomLeftRadius:0,MozBorderRadiusBottomLeft:0});
		$('#supportUpgrades').removeClass("tabInactive").css({WebkitBorderBottomRightRadius:0,MozBorderRadiusBottomright:0});
		$('#upgrades').toggle();
		return false
	});
        
	
	// Gallery script. Pure JQuery. Thanks to Paul at PE design for his how-to at http://pedesign.co.uk/blog/xhtml/jquery-image-gallery/
		
	$('ul.galleryThumbs li').css({display:'none',opacity:'0.5'}).fadeIn(500);
	
	$('ul.galleryThumbs li').hover(
		function() {$(this).not('active').fadeTo('fast',1);},															   
		function() {$(this).not('active').fadeTo('fast',0.5);}
	);

	$('ul.galleryThumbs li').click(function() {
		$(this).siblings().fadeTo('fast',0.5);
		var slide = $(this).children('a').attr('href');
		$('#gallerySlide img').fadeOut('slow').hide();
		$('#gallerySlide img').attr('src',slide);
		$('#gallerySlide img').fadeIn('slow');
	});
	
	$('.midlineImageGallery a').click(function() {
		var slide = $(this).attr('href');
		$('#gallerySlide img').fadeOut().hide();
		$('#gallerySlide img').attr('src',slide);
		$('#gallerySlide img').fadeIn('slow');
	});
	
	$('#inlineSlide a').click(function() {
		var slide = $(this).attr('href');
		$('#gallerySlide img').fadeOut().hide();
		$('#gallerySlide img').attr('src',slide);
		$('#gallerySlide img').fadeIn('slow');
	});
	
	// And thanks to Brice Burgess for jqModal. http://dev.iceburg.net/jquery/jqModal.
	
	var loadInIframeModal = function(hash){
    	var $trigger = $(hash.t);
    	var $modal = $(hash.w);
    	var loadUrl = $trigger.attr('href');
    	var $modalContent = $('iframe', $modal);
                   
    $modalContent.html('').attr('src', loadUrl);
    $modal.fadeIn('slow');
	}
	
	
	$('#viewMasters').jqm({
		overlay: 60,modal: true,trigger: '.VM1', ajax: '@href', target: '#vmFrame', onShow: loadInIframeModal, 
			onHide: function(h) { 
				h.w.fadeOut("slow", function() {if(h.o) h.o.remove();}
		)}
	});	
	
	$('#viewQuickTime').jqm({
		overlay: 60, modal: true, trigger: '.QT1', ajax: '@href', target: '#qtFrame', onShow: loadInIframeModal, 
			onHide: function(h) { 
				h.w.fadeOut("slow", function() {if(h.o) h.o.remove();}
		)}
	});
	
	$('#hdQuickTime').jqm({
		overlay: 60, modal: true, trigger: '.QT1', ajax: '@href', target: '#qtFrame', onShow: loadInIframeModal,
			onHide: function(h) { 
				h.w.fadeOut("slow", function() {if(h.o) h.o.remove();}
		)}
	});
	
	$('#sdPopUpBG').jqm({
		overlay: 60, modal: true, trigger: '.sdTrigger', onShow: function(h) { 
			h.w.css('opacity',1.0).show("slow");
		},
		onHide: function(h) {
			h.w.hide("slow",function() {if(h.o) h.o.remove();
		}
		)}
	});
	
	$('#hdPopUpBG').jqm({
		overlay: 60, modal: true, trigger: '.hdTrigger', onShow: function(h) { 
			h.w.css('opacity',1.0).show("slow");
		},
		onHide: function(h) {
			h.w.hide("slow",function() {if(h.o) h.o.remove();
		}
		)}
	});
});

function swap() {
		
	if (document.pos.checkgroup[3].checked==true){
		$("#T4").show("slow");
		$("#complete-ON,#qton").show();
		$("#complete-OFF,#qtoff").hide();
		$("#T3,#T2,#T1").hide("slow");
		//$("#T7").attr("checked","checked");
		$("#T7,#T6").attr("disabled","disabled");
	}
		
	else if (document.pos.checkgroup[2].checked==true){
		$("#T1,#T2,#T4").hide("slow");
		$("#complete-ON,#qtoff").hide();
		$("#complete-OFF,#qton").show();
		$("#T3").show("slow");
		$("#T6").attr("disabled","disabled");
		$("#T7,#T8").removeAttr("disabled");
	}
	else if (document.pos.checkgroup[1].checked==true){
		$("#T1,#T3,#T4").hide("slow");
		$("#qton,#hdoff,#complete-ON").hide();
		$("#T2").show("slow");
		$("#hdon,#qtoff,#complete-OFF").show();
		$("#T6,#T7").removeAttr("disabled");
		$("#T8").attr("disabled","disabled")
	}
		
	else {
		$("#T2,#T3,#T4").hide("slow");
		$("#hdon,#qton,#complete-ON").hide();
		$("#complete-OFF,#hdoff").show();
		$("#T1").show("slow");
		$("#T7,#T8").attr("disabled","disabled");
	}
					
}

function swapPages() {
		
	if (document.pos.checkgroup[3].checked==true){
		$("#T4").show("slow");
		$("#complete-ON").show();
		$("#complete-OFF").hide();
		$("#T2,#T1").hide("slow");
		//$("#T7").attr("checked","checked");
		$("#T6").attr("disabled","disabled");
	}
	
	else if (document.pos.checkgroup[2].checked==true){
	
	}
		
	else if (document.pos.checkgroup[1].checked==true){
		$("#T1,#T4").hide("slow");
		$("#hdoff,#complete-ON").hide();
		$("#T2").show("slow");
		$("#hdon,#complete-OFF").show();
		$("#T8,#T6").removeAttr("disabled");
		//$("#T8").attr("disabled","disabled")
	}
		
	else {
		$("#T2,#T3,#T4").hide("slow");
		$("#hdon,#qton,#complete-ON").hide();
		$("#complete-OFF,#hdoff").show();
		$("#T1").show("slow");
		$("#T7,#T8").attr("disabled","disabled");
	}
					
}

function Preload()
{ 
  var args = Preload.arguments;
  document.imageArray = new Array(args.length);
  for(var i=0; i<args.length; i++)
  {
    document.imageArray[i] = new Image;
    document.imageArray[i].src = args[i];
  }
}
