/* 2.8.10 need this */

/*  change window.location to vgw */
/*  7.8.10 I cannot fix the retained click background when returning to the link */

function popupsJ() {
	
	$("a[@href$='pdf'],a.map,a.friend").each(function(intindex){
		$(this).attr({title: $(this).attr(" title") + " (opens in a new window)"});
		//$("a[@href$='pdf'],a.map,a.friend").attr({title: this + "(opens in a new window)"}); to delete
		//$(this).append(" <img alt='(opens in a new window)' src='/i/new-win-icon.gif'>"); 2.8.10 taken out
		//$("a[@href$='pdf'],a.map,a.friend").append(" <img alt='(opens in a new window)' src='/i/new-win-icon.gif'>"); to delete
	});
	
	$("a[@href$='pdf']").click(function () { 
		createPopUp(this, "popper", "resizable,scrollbars");return false;
	});
	$("a.map").click(function () { 
		createPopUp(this, "popper", "height=450,width=375,resizable");return false;
	});
	$("a.virtual").click(function () { 
		// not sure we use this one now.
		createPopUp(this, "popper", "width=390,height=560,resizable,scrollbars");return false;
	});
	$("a.friend").click(function () { 
		createPopUp(this, "popper", "width=410,height=540,resizable,scrollbars");return false;
	});
	$("a.tc").click(function () { 
		createPopUp(this, "popper", "width=410,height=540,resizable,scrollbars");return false;
	});
}

/* 2.8.10 need this */
function cancelLinkJ() {
	$("a[href='#']").click(function () {return false;});
}

/* 2.8.10 need this */
function linkIncreaseJ() {
	$("#home #ad").hover(function () {
      		$("div", this).css({ background:"#c4130d", cursor:"pointer" });
      		$("a", this).css({ color:"#fff"});
      		$("p", this).css({ color:"#fff"});
    	}, function () {
      		$("div", this).css({ background:"#f3eaef", cursor:"arrow" });
      		$("a", this).css({ color:"#c4130d"});
      		$("p", this).css({ color:"#000"});
    	});
	$("#home #ad").click(function () {
		window.location = "http://www.vgwoodhouse.co.uk" + $("a", this).attr("href");
	});
}
/*  */
/* 2.8.10 need this */
function prepareFormsJ() {
	newsletterEmailJ();
	$("form").each(function( intIndex ){
			$(this).submit(function () {
				return validateFormJ(this);
			});
		}
	);
}


/*  2.8.10 need this */
function newsletterEmailJ() {
	$("#news .reqmail").blur(function () {
	      if (this.value == "") {
		this.value = "enter e-mail here";
	      }
	});
	$(".reqmail", "#news").focus(function () {	
	    if (this.value == "enter e-mail here") {
	      this.value = "";
	     }
	});
}


/*  2.8.10 need this */
function maximiseSplit(){
	maximiseSplitApplied(".split div div");
	$(".split.left div:last-child").unbind();
	$(".split.right div:first-child").unbind();
	$(".split.none div").unbind();
}


/* 2.8.10 need this  */
function maximiseSplitApplied(strSelector){
		if($(".split div div h2 a").length > 0 || $(".split div div h3 a").length > 0) {
			$(strSelector).hover(function () {
				if(!$(this).hasClass("nohover")){
					$(this).addClass("splitHover");
				}

			}, function () {
				if(!$(this).hasClass("nohover")){
					$(this).removeClass("splitHover");
				}
			});
			$(strSelector).bind('click', function() {
				if(!$(this).hasClass("nohover")){
					if($("h2 a",this).length > 0){
						window.location = $("h2 a", this).attr("href");
					}else{
						window.location = $("h3 a", this).attr("href");
					}
				}
			});
		}

}

/* 2.8.10 need this  */
function imageStyle(){

	if($("#home").length != 1)
	{
		if($(".portfolio").length == 0){
			$("#content img").each(function(intindex){
				if($(this).parents("#gallerymin").length == 0){
				
					if(this.width > 60){
					
						 if($.browser.msie){
						
							if(jQuery.browser.version > 6){
								$(this).wrap("<span class='imagestyle' style='max-width:" + (this.width + 12) +"px'><span></span></span>");
								//$(this).attr("style","width:100%")
							}
						 }else{
							$(this).wrap("<span class='imagestyle' style='max-width:" + (this.width + 12) +"px'><span></span></span>");
							$(this).attr("style","width:100%")					 
						 }


					}
				}
			});

			$("#clients div").each(function(intindex){
					$(this).wrap("<div class='imagestyle' style='width:151px'><div></div></div>");
			});
		}
	}
}

/*  

/*  2.8.10 need this */
function smallgallery(){
	
	if($("#gallerymin span.imagetitle").length > 0){
	
		var blnshowtitle = false;
		
		if ($("#gallerymin").hasClass("showlabels")){
			blnshowtitle = true;
		}
	
		var widthgallery = (parseInt($("#gallerymin span.imagetitle").length) * 3.5) + "em;";
	
		var relativeli =  (parseInt($("#gallerymin span.imagetitle").length) * 3) / 2 + "em;";

		var newgallery = '<ul class="galleryminpag" style="width:'+widthgallery+'">';
		
		$("#gallerymin ul.galleryimages li").each(function( intIndex ){
			intIndex++;	
			$(this).addClass("image" + intIndex);
			if(!blnshowtitle){
				$(this).find("img").attr("alt",$(this).find(".imagetitle").text());
			}
		});
		
		$("#gallerymin span.imagetitle").each(function( intIndex ){
			intIndex++;
			if(intIndex == 1){
				addSelected = ' class ="selected"'
			}else{
				addSelected = ""
			}
			newgallery += '<li' + addSelected + ' style="left:-' + relativeli + '"><a class="gallerymin' + intIndex + '" href="#"><span>' + intIndex + "</span> <span class='hidden'>" +  $(this).text()  + '</span></a></li>';
			$(this).parents("li:first").attr("style", "z-index:"+ (100 - intIndex))

			if(!blnshowtitle){
				$(this).remove();
			}
		});
		newgallery += "</ul>";
		$("#gallerymin").append(newgallery)
		
		$(".galleryminpag a").click(function () {
			if(!$(this).parents("li:first").hasClass("selected")){
				var classis = $(this).attr("class");
				classis = classis.replace("gallerymin", "");

				$("#gallerymin ul.galleryimages li").fadeOut();
				$("#gallerymin ul.galleryimages li:nth-child(" + classis + ")").fadeIn('slow', function() {
					$(".galleryminpag li").removeClass("selected");
					classis = classis.replace("image", "");
					$("#gallerymin li:nth-child(" + classis + ")").addClass("selected");
				});
			}
			return false;
		});
	}
}



/* 2.8.10 need this */

$(document).ready(function(){
	javascriptEnabled();
	createFlashObject()
	imageStyle();
	smallgallery();
	popupsJ();
	cancelLinkJ();
	linkIncreaseJ();
	prepareFormsJ();
	maximiseSplit();
	maximiseTraining();
	maxWebcreds();
	createViewingOptionsHTML();
	showMore();
	topicsOrTags();
	moreLinks();
	showHideDiscounts();
	calenderRoundedCorners();
	if($.browser.msie){
		if(jQuery.browser.version >= 6){
			newslettertabs();
		}else{

		}
	}else{
		newslettertabs();
	}
});


/*  2.8.10 need this */
function javascriptEnabled(){
	$("body").addClass("javascript");
}


/*  need this */
function createFlashObject(){

	if(jQuery.browser.msie && jQuery.browser.version > "5.5" || !jQuery.browser.msie){
		
		if(checkForFlash()){
			var numberOfServices = $("#banners h2").length - 1;
			var defaultHeading = $("#banners .first h1").text().replace("&", "and");
			var defaultParagraph = $("#banners .first p").text().replace(/\&/g, "and");
			
			var serviceheadings = "";
			$("#banners h2").each(function(intindex){
				removeAnd = $(this).text().replace("&", "and");
				serviceheadings = serviceheadings + ":" + removeAnd;
			});


			var serviceParagraphs = "";
			$("#banners div p").each(function(intindex){
				if($(this).parent().attr("class") != "first"){
				removeAnd = $(this).text().replace("&", "and");
				serviceParagraphs = serviceParagraphs + ":" + removeAnd;
				}
			});
			

			strCSSText = "standard";
			strCSSColor = "standard";

			CSSFiles = $("link");

			$("link").each(function(intindex){
				if($(this).attr("type") == "text/css" && $(this).attr("media") == "all"){
					if($(this).attr("href") == "/css/med.css" || $(this).attr("href") == "/css/lar.css"){
						strCSSTextB4 = $(this).attr("href").replace("/css/","");
						strCSSTextB4 = strCSSTextB4.replace(".css","");
						strCSSText = strCSSTextB4;

					}else{
						strCSSColorB4 = $(this).attr("href").replace("/css/","");
						strCSSColorB4 =strCSSColorB4.replace(".css","");
						strCSSColor = strCSSColorB4;

					}
				}
			});



			var strFlash = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"\" width=\"100%\" height=\"264\"  id=\"wcMovie\" align=\"middle\">"
			strFlash += "<param name=\"allowscriptAccess\" value=\"sameDomain\" />"
			strFlash += "<param name=\"movie\" value=\"services.swf\" />"
			strFlash += "<param name=\"wmode\" value=\"transparent\">"
			strFlash += "<param name=\"quality\" value=\"high\" />"
			strFlash += "<param name=\"FlashVars\" value=\"focusDetected=" + 0 + "&strintButtons=" + numberOfServices + "&strCSSText=" + strCSSText + "&strCSSColor=" + strCSSColor + "&strDefaultHeading=" + defaultHeading + "&strDefaultContent=" + defaultParagraph +"&strHeading='" + serviceheadings + "&serviceParagraphs='" + serviceParagraphs + "" + "\"/>"
			strFlash += "<embed src=\"services.swf\" FlashVars=\"focusDetected=" + 0 + "&strintButtons=" + numberOfServices + "&strCSSText=" + strCSSText + "&strCSSColor=" + strCSSColor + "&strDefaultHeading=" + defaultHeading + "&strDefaultContent=" + defaultParagraph +"&strHeading='" + serviceheadings + "&serviceParagraphs='" + serviceParagraphs + "" + "\" wmode=\"transparent\" quality=\"high\" width=\"100%\" height=\"290\" align=\"middle\" allowscriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" swLiveConnect=\"true\" name=\"wcMovie\"/>"
			strFlash += "</object>";
			
			
			$("#banners div div div[class!='flashcontainer']").addClass("off");
			$("#banNav ul").addClass("off");
			
			$(".flashcontainer").attr("style","height:250px");
			$("#banners").attr("style","margin-bottom:0px");
			$(".flashcontainer").show();
			$("#banners").addClass("flashbanner");
			$(".flashcontainer div").html(strFlash);
			

			 $("#banNav a").focus(function (){
					navNum = $(this).attr("class")
					focusState(navNum);
			 });
			 
			 $(".tabclear").focus(function (){
			 	focusState(-1);
			 	
			 });
		 }
	}
}



/*  2.8.10 need this  */
function checkForFlash(){
	var isInstalled = false;
	var version = null;
	if (window.ActiveXObject) {
		
	    var control = null;
	    try {
		control = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
	    } catch (e) {

	    }
	    if (control) {
		isInstalled = true;
		version = control.GetVariable('$version').substring(4);
		version = version.split(',');
		version = parseFloat(version[0] + '.' + version[1]);
	    }
	    if(version > 6){
		isInstalled = true
	    }else{
	   	 isInstalled = false
	    }
	} else {
		for (i=0; i < navigator.plugins.length; i++) {
			 //loop through all the plugins installed
			
			for (i=0; i < navigator.plugins.length; i++)
			{
				var pluginIdent = navigator.plugins[i].description.toLowerCase();
				
				if(pluginIdent.indexOf('flash') > 0){
					
					arrFlash = pluginIdent.split(" ");
					
					for (j=0; j < arrFlash.length; j++){
							var FlashNum = parseFloat(arrFlash[j]);
							if(!isNaN(FlashNum)){
								version = parseFloat(FlashNum);
								 if(version > 6){
								 	
									isInstalled = true
								 }

							}

						j++;
					}

				}
		}
		}
	}
	return isInstalled;
}

function showFlash(valueIs){
	//alert("hello");
}
/*  */
