function CookieSelectRow() {
	//do nothing purely to circumvent the current link generation
}

$(document).ready(function(){
	var DispFmt = 'Closed';
	//colour coded class fields
	$('.classfield').each(function(){
		var ClassColor = $(this).find('span').css('color');
		var ClassBackgroundColor = $(this).find('span').css('backgroundColor');
		$(this).css({'backgroundColor':ClassBackgroundColor, 'color':ClassColor})
	});
	
	//remove empty fData & add subject + keyword search
	var FieldTagsArray = FieldTags.split(',');
	var FieldCharsArray = FieldChars.split(',');
	var KeywordsCodeIndex = -1;
	var SubjectsCodeIndex = -1;
	for(var i=0; i<FieldTagsArray.length; i++){
		if(FieldTagsArray[i] == 'Keywords'){
			KeywordsCodeIndex = i;
		} 
	}

	if(KeywordsCodeIndex!='-1'){
		KeywordsCode = FieldCharsArray[KeywordsCodeIndex];
	} else {
		KeywordsCode = false;
	}
	
	for(var i=0; i<FieldTagsArray.length; i++){
		if(FieldTagsArray[i] == 'Subjects'){
			SubjectsCodeIndex = i;
		} 
	}

	if(SubjectsCodeIndex!='-1'){
		SubjectsCode = FieldCharsArray[SubjectsCodeIndex];
	} else {
		SubjectsCode = false;
	}
	
	$('.fData').each(function(){
		var pTitle = $(this).attr("title");
		var trimpText =  $(this).text().replace(/^[\s\xA0]*/g,"").replace(/[\s\xA0]*$/g,"");
		if(trimpText!=pTitle){
			$(this).removeClass('hidden');
			//var trimpTextStart = trimpText.indexOf(pTitle);
			var trimpTextEnd = pTitle.length;
			var trimpTextBase = trimpText.substr(trimpTextEnd,trimpText.length-1);
			var trimpTextArray = trimpTextBase.split(',');
			if(pTitle=='Subjects' && trimpTextArray!='' && SubjectsCode!=false){
				for(i=0 ; i < trimpTextArray.length ; i++){
					trimpTextArray[i] = trimpTextArray[i].trim();
					if(SubjectsWholeTerm!=0){
						trimpTextArray[i] = trimpTextArray[i].replace(/\s/g,'_');
					}
				}
				var subjects = encodeURI(trimpTextArray.join(' AND '));
				var findSubjects = scriptpath + '/search2?' + 'searchterm=' + subjects + '&Fields=' + SubjectsCode + '&Media=%23&SearchPrecision=40';
				$(this).append('<a href="'+findSubjects+'"><img class="mag" src="' + PublicDir + '/Images/magnifying_glass.png" title="Search for catalogue records containing all of these Subjects"/></a>')
			} else if(pTitle=='Keywords' && trimpTextArray!='' && KeywordsCode!=false){
				for(i=0 ; i < trimpTextArray.length ; i++){
					trimpTextArray[i] = trimpTextArray[i].trim();
					if(KeywordsWholeTerm!=0){
						trimpTextArray[i] = trimpTextArray[i].replace(/\s/g,'_');
					}
				}
				var keywords = encodeURI(trimpTextArray.join(' AND '));
				var findKeywords = scriptpath + '/search2?' + 'searchterm=' + keywords + '&Fields=' + KeywordsCode + '&Media=%23&SearchPrecision=40';
				$(this).append('<a href="'+findKeywords+'"><img class="mag" src="' + PublicDir + '/Images/magnifying_glass.png" title="Search for catalogue records containing all of these Keywords"/></a>')
			}
		}
	});
	
	$('.fLabel').each(function(){
		var pTitle = $(this).text();
		var trimpTextBase = $(this).parent().find('.fDataM').text().replace(/^[\s\xA0]*/g,"").replace(/[\s\xA0]*$/g,"");
		var trimpTextArray = trimpTextBase.split(',');
		
		if(pTitle=='Subjects' && trimpTextArray!='' && SubjectsCode!=false){
			
			for(i=0 ; i < trimpTextArray.length ; i++){
				trimpTextArray[i] = trimpTextArray[i].trim();
				if(SubjectsWholeTerm!=0){
					trimpTextArray[i] = trimpTextArray[i].replace(/\s/g,'_');
				}
			}
			var subjects = encodeURI(trimpTextArray.join(' AND '));
			var findSubjects = scriptpath + '/search2?' + 'searchterm=' + subjects + '&Fields=' + SubjectsCode + '&Media=%23&SearchPrecision=40';
			$(this).parent().find('.fDataM').append(' <a href="'+findSubjects+'"><img class="mag" src="' + PublicDir + '/Images/magnifying_glass.png" title="Search for catalogue records containing all of these Subjects"/></a>')
		} else if(pTitle=='Keywords' && trimpTextArray!='' && KeywordsCode!=false){
			for(i=0 ; i < trimpTextArray.length ; i++){
				trimpTextArray[i] = trimpTextArray[i].trim();
				if(KeywordsWholeTerm!=0){
					trimpTextArray[i] = trimpTextArray[i].replace(/\s/g,'_');
				}
			}
			var keywords = encodeURI(trimpTextArray.join(' AND '));
			var findKeywords = scriptpath + '/search2?' + 'searchterm=' + keywords + '&Fields=' + KeywordsCode + '&Media=%23&SearchPrecision=40';
			$(this).parent().find('.fDataM').append(' <a href="'+findKeywords+'"><img class="mag" src="' + PublicDir + '/Images/magnifying_glass.png" title="Search for catalogue records containing all of these Keywords"/></a>')
		}
	});
	
	//on startup check appropriate boxes
	var SelResults = $.cookie('SelResults');
	if(SelResults){
		var SelResultsArray = SelResults.split(',');
		for (var i=0; i<SelResultsArray.length; i++) {
			$('#I'+SelResultsArray[i]).attr('checked','checked');
		}
	}
	//Checkbox select
	$('.CookieSelectRow').parent().parent().each(function(){
		$(this).find('input[type="checkbox"]').click(function(event){
			var checkedStatus = $(this).attr('checked');
			if(checkedStatus){
				$(this).attr('checked',null);
			} else {
				$(this).attr('checked','checked');
			}
		});
		$(this).find('a').each(function(){
			$(this).click(function(){
				linkClick='1';
			});
		});
		$(this).find('.button').each(function(){
			$(this).click(function(){
				linkClick='1';
			});
		});
		$(this).find('button').each(function(){
			$(this).click(function(){
				linkClick='1';
			});
		});
		$(this).find('.ButtonSmall').each(function(){
			$(this).click(function(){
				linkClick='1';
			});
		});
		$(this).click(function(){
			if(!linkClick){
				checkId = $(this).find('input[type="checkbox"]').attr('id');
				checkIdNo = checkId.slice(1);
				isChecked = $(this).find('input[type="checkbox"]').attr('checked');
				if(isChecked){
					$(this).find('input[type="checkbox"]').attr('checked',null);
					isChecked = false;
				} else {
					$(this).find('input[type="checkbox"]').attr('checked','checked');
					isChecked = true;
				} 
				name = $(this).find('input[type="checkbox"]').attr('name');
				isSelection = name.indexOf('selection') + 1;
				if(isSelection){
					if(isChecked){
						//get existing selection
						var SelResults = $.cookie('SelResults');
						if(SelResults){
							var SelResultsArray = SelResults.split(',');
							SelResultsArray[SelResultsArray.length] = checkIdNo;
							SelResults=SelResultsArray.join(',');
						} else {
							SelResults = checkIdNo;
						}
					} else {
						var SelResults = $.cookie('SelResults');
						if(SelResults){
							var SelResultsArray = SelResults.split(',');
							for (var i=0; i<SelResultsArray.length; i++) {
								if(SelResultsArray[i]==checkIdNo){
									SelResultsArray.splice(i,1);
								}
							}
							SelResults=SelResultsArray.join(',');
						} else {
							SelResults = '';
						}
					}
					$.cookie('SelResults', SelResults, {path: cookiepath}); 
				
				} else {
					
				}
			}
		});
	});

	//Checkbox select all
	$('#selclr').click(function(){
		var active = $(this).attr('class');
		if(active=='inactive'){
			$(this).attr('src', PublicDir+'/images/Cleard.png');
			$(this).attr('class','active');
			$('.CookieSelectRow').each(function(){
				$(this).attr('checked','checked');
				//add cookie
				var checkId = $(this).attr('id');
				var checkIdNo = checkId.slice(1);
				var SelResults = $.cookie('SelResults');
				if(SelResults){
					var SelResultsArray = SelResults.split(',');
					SelResultsArray[SelResultsArray.length] = checkIdNo;
					SelResults=SelResultsArray.join(',');
				} else {
					SelResults = checkIdNo;
				}
				$.cookie('SelResults', SelResults, {path: cookiepath}); 

			});
		} else if(active=='active'){
			$(this).attr('class','inactive');
			$(this).attr('src', PublicDir+'/images/selted.png');
			$('.CookieSelectRow').each(function(){
				$(this).attr('checked',null);
				//remove cookie
				var checkId = $(this).attr('id');
				var checkIdNo = checkId.slice(1);
				var SelResults = $.cookie('SelResults');
				if(SelResults){
					var SelResultsArray = SelResults.split(',');
					for (var i=0; i<SelResultsArray.length; i++) {
						if(SelResultsArray[i]==checkIdNo){
							SelResultsArray.splice(i,1);
						}
					}
					SelResults=SelResultsArray.join(',');
				} else {
					SelResults = '';
				}
				$.cookie('SelResults', SelResults, {path: cookiepath}); 
			});
		}
	});

	//Check maintain select all option on startup
	var startChkSelected = '0';
	var startChkTotal = '0';
	
	$('.CookieSelectRow').each(function(){
		startChkTotal++;
		checkedStatus = $(this).attr('checked');
		
		if(checkedStatus){
			startChkSelected++;
		}
	});
	
	if(startChkSelected == startChkTotal  && startChkSelected!='0'){
		$('#selclr').attr('src', PublicDir+'/images/Cleard.png');
	}
	
	
	
	//get current URL
	var startURL = document.location.href;
	var currentParamsChar = startURL.indexOf('?');
	if(currentParamsChar!='-1'){
		var currentURL = startURL.substr(0, currentParamsChar+1);
		var currentParams = startURL.substr(currentParamsChar+1, startURL.length);
		var fullDispRegexp = new RegExp('Dispfmt=F', "i");
		isFullDisplay = currentParams.match(fullDispRegexp);
		var rawSearchRegexp = new RegExp('SearchTerm0=~', "i");
		isRawSearch = currentParams.match(rawSearchRegexp);
	} else {
		isRawSearch = false;
		var currentURL = startURL;
		var currentParams = '?';
		var currentParamsArray = new Array();
	}
	
	//check for raw search
	var dispFmtTableStart = '<table id="dispFmtTable">';
	var dispFmtTableEnd = '</table>';
	var dispFmtBrief = $('#dispFmtBrief').html();
	var dispFmtFull = $('#dispFmtFull').html();
	var dispFmtSort = $('#dispFmtSort').html();
	var dispFmtPrecision = $('#dispFmtPrecision').html();
	if(isRawSearch){
		var dispFmtOptions = dispFmtTableStart + '<tr>' + dispFmtBrief + '</tr><tr>' + dispFmtFull + '</tr><tr>' + dispFmtSort + '</tr>' + dispFmtTableEnd;
	} else {
		var dispFmtOptions = dispFmtTableStart + '<tr>' + dispFmtBrief + '</tr><tr>' + dispFmtFull + '</tr><tr>' + dispFmtSort + '</tr><tr>' + dispFmtPrecision + '</tr>' + dispFmtTableEnd;
	}
	
	
	
	function DisplayOptions(){
		//setup params for display format change
		var startURL = document.location.href;
		var currentParamsChar = startURL.indexOf('?');
		//create the form (closing removes the html each time so need to recreate on click)
		$('#dispFmt').after('<form id="dispFmtForm" action="#" name="dispFmtForm"></form>');
		//open the display format options form
		//check for raw search - disable search precision as it is inappropriate
		
		
		$('#dispFmtForm').html(dispFmtOptions).dialog({
			width: 600,
			title: 'Choose display format',
			buttons: {
				"Cancel": function() { $(this).dialog("close"); },
				"OK": function(){
					var newParams ='';
					$('select.DisplayOptions').each(function(){
						var thisVal = $(this).val();
						var thisName = $(this).attr('name');
						if (newParams!=''){
							thisName = '&' + thisName;
						} else {
							
						}
						newParams += thisName + '=' + thisVal;
					});
					var newParamsArray = new Array();
					newParamsArray = newParams.split('&');
					var initialParamsArray = new Array();
					for(i=0 ; i < newParamsArray.length ; i++){
						var termsArray2 = newParamsArray[i].split('=');
						initialParamsArray[termsArray2[0]]=termsArray2[1];
					}
					if(currentParams!=''){
					  for (key in initialParamsArray) {
							paramRegexp = new RegExp(key + '=' + '[^&]+', "i");
							var paramMatch = currentParams.match(paramRegexp);
							if(paramMatch){
								//replace parameter
								currentParams = currentParams.replace(paramRegexp, key+"="+initialParamsArray[key]);
							} else {
								//append parameter
								currentParams = currentParams + "&" + key+"="+initialParamsArray[key];
							}
						}
						document.location = currentURL + currentParams;
					}
				}
			}
		});
		if(isRawSearch){
			var iter = 0;
			$('.SearchPrecisionRow').each(function(){
				$(this).remove();
			});
		}
		if(isIE6 || isIE7){
			$('.DisplayOptions').each(function(){
				$(this).width('430');
			});
		}
	}
	
	$('#dispFmt').click(function(event){
		event.preventDefault();
		DisplayOptions();
		if(isFullDisplay!=null){
			$('select#Dispfmt_f').focus();
		} else {
			$('#dispsort select:first').focus();
		}
	});
	
	$('#SortOrder2').change(function(){
		var startURL = document.location.href;
		var currentParamsChar = startURL.indexOf('?');
		
		var thisVal = $(this).val();
		var thisName = $(this).attr('name');
		
		if(currentParamsChar!='-1'){
			var currentURL = startURL.substr(0, currentParamsChar+1);
			var currentParams = startURL.substr(currentParamsChar+1, startURL.length);
			var fullDispRegexp = new RegExp('Dispfmt=F', "i");
			isFullDisplay = currentParams.match(fullDispRegexp);
		} else {
			var currentURL = startURL;
			var currentParams = '?';
			var currentParamsArray = new Array();
		}
		var newParams = thisName + '=' + thisVal;
		var newParamsArray = new Array();
		newParamsArray = newParams.split('&');
		var initialParamsArray = new Array();
		for(i=0 ; i < newParamsArray.length ; i++){
			var termsArray2 = newParamsArray[i].split('=');
			initialParamsArray[termsArray2[0]]=termsArray2[1];
		}
		if(currentParams!=''){
		  for (key in initialParamsArray) {
				paramRegexp = new RegExp(key + '=' + '[^&]+', "i");
				var paramMatch = currentParams.match(paramRegexp);
				if(paramMatch){
				  //replace parameter
				  currentParams = currentParams.replace(paramRegexp, key+"="+initialParamsArray[key]);
				} else {
				  //append parameter
				  currentParams = currentParams + "&" + key+"="+initialParamsArray[key];
				}
			}
			var newUrl = currentURL + currentParams;
			if(startURL != newUrl){
				document.location = newUrl;
			}
			
		}
	});
		//replace certificate with image
	$('.certificate').each(function(){
		var Certificate = $(this).text();
		switch (Certificate){
			case "U":
			$(this).html('<img src="'+PublicDir+'/Images/Certificate/U.gif" alt="U"/>').parent().find('.fulllabel').addClass('hidden');
			break;
			case "Uc":
			$(this).html('<img src="'+PublicDir+'/Images/Certificate/Uc.gif" alt="Uc"/>').parent().find('.fulllabel').addClass('hidden');
			break;
			case "pg":
			$(this).html('<img src="'+PublicDir+'/Images/Certificate/pg.gif" alt="pg"/>').parent().find('.fulllabel').addClass('hidden');
			break;
			case "12":
			$(this).html('<img src="'+PublicDir+'/Images/Certificate/12.gif" alt="12"/>').parent().find('.fulllabel').addClass('hidden');
			break;
			case "15":
			$(this).html('<img src="'+PublicDir+'/Images/Certificate/15.gif" alt="15"/>').parent().find('.fulllabel').addClass('hidden');
			break;
			case "18":
			$(this).html('<img src="'+PublicDir+'/Images/Certificate/18.gif" alt="18"/>').parent().find('.fulllabel').addClass('hidden');
			break;
		}
	});
	
	//synopsis expand
	$('.synopsisExpand').each(function(){
		$(this).click(function(event){
			event.preventDefault();
			var synopsisId = this.id;
			var synopsisNo = synopsisId.charAt(8);
			$('#synopsis'+synopsisNo+'Extension').css('display','inline');
			$(this).fadeOut('slow');
		});
	});
	
	//Bind shortcut keys for search resultsclassfield
	dispFmt = 'Closed';
	$(document).keypress(function(event){
		//alert(event.which);
		//alert(currentFocus);
		if(currentFocus==null){
			if(event.which==62||event.which==43||event.which==46){
				//Press > + .
				var url = $('.navNext').parent().attr("href");
				if (url!=undefined){
					window.location = url;
				}
			}else if (event.which==60||event.which==44||event.which==45){
				//Press < , -
				var url = $('.navPrev').parent().attr("href");
				if (url!=undefined){
					window.location = url;
				}
			}else if (event.which==83||event.which==115){
				//Press S to get summary display
				var url = $('a.briefbtn').attr("href");
				if (url!=undefined){
					window.location = url;
				}
			}else if (event.which==68||event.which==100){
				//Press D to get full display
				var url = $('a.fullbtn').attr("href");
				if (url!=undefined){
					window.location = url;
				}
			} else if (event.which==79||event.which==111){
				if(currentFocus!='Dispfmt_b' & currentFocus!='Dispfmt_f' & currentFocus!='SortOrder'){
					//Press O to get display Options
					if(DispFmt=='Open'){
						DispFmt = 'Closed';
						$("button:contains('Cancel')").click();
						currentFocus=null;
					} else {
						DisplayOptions();
						DispFmt = 'Open';
					}
					
					
					// Give focus to appropriate select element
					if(isFullDisplay!=null){
						$('select#Dispfmt_f').focus();
					} else {
						$('#dispsort select:first').focus();
					}
				} else {
					//Press O to close display Options
					$("button:contains('Cancel')").click();
					currentFocus=null;
				}
			}
		}
	});
});

//make sure background image shows
$(window).bind('load', function() {
	//remove background image from local image versions
	$('.cLocImgSmall').each(function(){
		//clear background image
		$(this).parent().parent().css('background','');
	});
	
	$('.cLocImgLarge').each(function(){
		//clear background image
		$(this).click(function(){
			var imgSource = $(this).attr('src');
			window.open(imgSource);
		}).css('cursor','pointer');
		$(this).parent().css('background','');
	});

	$('.cImgLarge').each(function(){
		var imgWidth = $(this).width();
		var imgHeight = $(this).height();
		var thisId = $(this).attr('id');
		var recordType = thisId.slice(0,4);
		if(recordType=='AIDN'){
			recordType='ISBN';
		}
		var recordId = thisId.slice(4,(thisId.length));
		var imgIDFull = $('#'+thisId).attr('src');
		var imgID = imgIDFull.slice(34,44);
		if(imgWidth > '1' && (imgWidth!=128 && imgHeight!=128)){
			//Amazon acreditation
			$('#'+thisId).attr('Title','Image provided by "Amazon.co.uk" Click to view the Amazon record.');
			//add Amazon link
			$('#'+thisId).click(function(){
				document.location = 'http://www.amazon.co.uk/gp/product/product-description/'+imgID+'?t='+AmazonWebServicesID;
			});
			$('#'+thisId).css('cursor','pointer');
			//clear background image
			$('#'+thisId).parent().css('background','');
		}
		if(recordType!='IHSN'&&recordType!='AIDN'){
			//look for google cover / preview
			url = 'http://books.google.com/books?jscmd=viewapi&bibkeys='+ recordType +':'+recordId;
			$.ajax({
				url: url,
				dataType: "script",
				success: function(data){
					if(_GBSBookInfo){
						for (key in _GBSBookInfo){
							if(_GBSBookInfo[key]['thumbnail_url']){
								var thumbnail_url = _GBSBookInfo[key]['thumbnail_url'];
							}
							if(_GBSBookInfo[key]['preview']!='noview'){
								var preview_url = _GBSBookInfo[key]['preview_url'];
								$('#gbslink').html('<a href="'+preview_url+'"><img src="'+PublicDir+'/images/gbs_preview_button1.png" title="Click to preview"/></a>').click(function(){
									linkClick='1';
								});;
							}
							if(_GBSBookInfo[key]['info_url']){
								var info_url = _GBSBookInfo[key]['info_url'];
							}
						}

						if(imgWidth > '1'){
						} else if (recordType){
							if(thumbnail_url!=null){
								//change the zoom for larger size images
								var thumbnail_url = thumbnail_url.replace(/zoom=5/, "zoom=1");
								$('#'+recordType+recordId).attr('src',thumbnail_url);
								$('#'+recordType+recordId).parent().css('background','');
								
								$('#'+recordType+recordId).attr('title','Image provided by "Google Books" Click to view the Google Books record.');
								//add Google link
								$('#'+recordType+recordId).click(function(){
									document.location = info_url;
								});
								$('#'+recordType+recordId).css('cursor','pointer');
							} else {
								$('#'+recordType+recordId).css({'width':'128px','height':'128px'});
								var thisBG = $('#'+recordType+recordId).parents('.fImage').css('backgroundImage');
								$('#'+recordType+recordId).parents('.fImage').css('backgroundImage','');
								re = new RegExp(/url/);
								re2 = new RegExp(/[\(\)"]/g);
								thisBG = thisBG.replace(re, '');
								thisBG = thisBG.replace(re2, '');
								$('#'+thisId).attr('src',thisBG);
								$('.'+thisId).attr('title','Media image');
							}
						}
					} else {
						$('#'+recordType+recordId).css({'width':'128px','height':'128px'});
					}
					
				}
			});
		} else {
			if(imgWidth < '2'){
				$('#'+thisId).css({'width':'128px','height':'128px'});
				var thisBG = $('#'+thisId).parents('.fImage').css('backgroundImage');
				$('#'+thisId).parents('.fImage').css('backgroundImage','');
				re = new RegExp(/url/);
				re2 = new RegExp(/[\(\)"]/g);
				thisBG = thisBG.replace(re, '');
				thisBG = thisBG.replace(re2, '');
				$('#'+thisId).attr('src',thisBG);
				$('.'+thisId).attr('title','Media image');
			}
		}
	});
	
	$('.cImgSmall').each(function(){
		var imgWidth = $(this).width();
		var thisId = $(this).attr('id');
		if(imgWidth > '1'){
			//clear background image
			$('.'+thisId).parent().parent().css('background','');
		} else {
			var recordType = thisId.slice(0,4);
			var recordId = thisId.slice(4,(thisId.length));
			if(recordType!='IHSN' &&recordType!='AIDN'){
				//look for google cover
				url = 'http://books.google.com/books?jscmd=viewapi&bibkeys='+ recordType +':'+recordId;
				var _GBSBookInfo;
				$.ajax({
					url: url,
					dataType: "script",
					success: function(data){
						if(_GBSBookInfo && _GBSBookInfo!=''){
							for (key in _GBSBookInfo){
								if(_GBSBookInfo[key]['thumbnail_url']){
									var thumbnail_url = _GBSBookInfo[key]['thumbnail_url'];
								}
							}
							//var ThumbType = key.slice(0,4);
							//var ThumbId = key.slice(5,(key.length));
							if(thumbnail_url){
								$('.'+recordType+recordId).attr('src',thumbnail_url);
								$('.'+recordType+recordId).attr('title','Cover image courtesy of Google');
								$('.'+recordType+recordId).width('48px');
								$('.'+recordType+recordId).parent().css('background','');
							} else {
								$('.'+recordType+recordId).css({'width':'48px','height':'48px'});
								var thisBG = $('#'+thisId).parents('.dImagesmall').css('backgroundImage');
								if(thisBG!='none'){
									$('.'+thisId).parents('.dImagesmall').css('backgroundImage','');
									re = new RegExp(/url/);
									re2 = new RegExp(/[\(\)"]/g);
									thisBG = thisBG.replace(re, '');
									thisBG = thisBG.replace(re2, '');
									$('.'+thisId).attr('src',thisBG);
									$('.'+thisId).attr('title','Media image');
								}
								
							}
						} else {
							$('.'+thisId).css({'width':'48px','height':'48px'});
						}
					}
				});
			} else {
				$('.'+thisId).css({'width':'48px','height':'48px'});
				var thisBG = $('#'+thisId).parents('.dImagesmall').css('backgroundImage');
				
				if(thisBG!='none'){
					$('.'+thisId).parents('.dImagesmall').css('backgroundImage','');
					re = new RegExp(/url/);
					re2 = new RegExp(/[\(\)"]/g);
					thisBG = thisBG.replace(re, '');
					thisBG = thisBG.replace(re2, '');
					$('.'+thisId).attr('src',thisBG);
					$('.'+thisId).attr('title','Media image');
				}
			}
			
		}
	});
	
	//Highlight On / Off
	var highlight = $.cookie('isHighlight');
	
	if (highlight == '0') {
		$(".highlight").addClass("nohighlight");
		$(".highlight").removeClass("highlight");
	}
	$('#highlightSwitch').click(function(event){
		event.preventDefault();
		var highlight = $.cookie('isHighlight');

		if (highlight == '1') {
			$(".highlight").addClass("nohighlight");
			$(".highlight").removeClass("highlight");
			$.cookie("isHighlight","0",{ path: cookiepath});
			var highlight = '0';
		} else if (highlight == '0') {
			$(".nohighlight").addClass("highlight");
			$(".nohighlight").removeClass("nohighlight");
			$.cookie("isHighlight","1",{ path: cookiepath});
			var highlight = '1';
		}
	});
	if(isIE){
		$('#SortOrder2 option').each(function(){
			var OptionText = $(this).text();
			$(this).attr('title',OptionText);
		});
	}
});
