var main = new function()
{

var l_xml = '';	
var l_soundnumber = 1;
var l_copyright = '';
//HOME PAGE CREATION
 this.init = function()
    {
	$('main').update();
	main.l_soundnumber = 1;
	main.l_copyright = 'All images on this website: artist retains copyright and all other rights not explicitly granted by the artist.';
	    
	var div = document.createElement('div');
	div.id='logo';
	div.appendChild(document.createTextNode('Sharon Charney'));
	$('main').appendChild(div);
	    
	
	var img = document.createElement('img');
	img.src='img/entitledtree_homepage.jpg';
	img.id='homepagepainting';
	$('main').appendChild(img);
	    
	    
	//homepage left links
	//gallery
	var div = document.createElement('div');
	div.id='homepage_left';
	$('main').appendChild(div);
	    
	var link = document.createElement('div');
	link.className='leftlink';
	link.onclick=function(){
		main.build_gallerypage();
	}
	link.appendChild(document.createTextNode('Gallery'));
	$('homepage_left').appendChild(link);
	
	//pricelist
	var link = document.createElement('div');
	link.className='leftlink';
	link.onclick=function(){
		//main.EvalSound2('Bach');
		main.build_pricelistpage();
	}
	link.appendChild(document.createTextNode('Price List'));
	$('homepage_left').appendChild(link);
	
	//biography
	var link = document.createElement('div');
	link.className='leftlink';
	link.onclick=function(){
		main.build_biographypage();
	}
	link.appendChild(document.createTextNode('Biography'));
	$('homepage_left').appendChild(link);
	
	//contact
	var link = document.createElement('div');
	link.className='leftlink';
	link.onclick=function(){
		main.build_contactpage();
	}
	link.appendChild(document.createTextNode('Contact'));
	$('homepage_left').appendChild(link);
	
	
	
	
	
	//homepage right section
	var div = document.createElement('div');
	div.id='homepage_right';
	$('main').appendChild(div);
	
	var div = document.createElement('div');
	div.id='homepage_right_sect1';
	div.appendChild(document.createTextNode('Sharon Charney paints colorful oil and acrylic paintings. Her subjects include the landscape, plants, and animals. Trees, mountains, the seashore, sheep and goats appear in her work. The painting is done either on stretched canvas, wood, or paper. Art work on paper is framed under glass or plexiglass. Sharon Charney’s paintings may be viewed in the gallery. '));
	$('homepage_right').appendChild(div);
	    
	var div = document.createElement('div');
	div.className='bold1';
	div.id='homepage_right_sect2heading';
	div.appendChild(document.createTextNode('Artist\'s Statement:'));
	$('homepage_right').appendChild(div);
	
	var div = document.createElement('div');
	div.id='homepage_right_sect2';
	div.appendChild(document.createTextNode('My subject matter comes from places where I have lived and traveled—from everything I have ever seen, tasted, smelled, heard and felt. Like a huge recipe from time, the ingredients are mixed together, sifted and sorted through some mysterious process in my mind.'));
	$('homepage_right').appendChild(div);
	
	
	var div = document.createElement('div');
	div.id='homepage_copyright';
	$('main').appendChild(div);
	div.appendChild(document.createTextNode(main.l_copyright));
    }	 

    
    
    /*-------------  sound --------------*/

this.EvalSound2=function(soundobj){
  var thissound=document.getElementById(soundobj);
  thissound.Play();
}


this.playSound = function(soundfile) {
	$("sound").innerHTML= "<embed src=\""+soundfile+"\" hidden=\"true\" autostart=\"true\" loop=\"false\" />";
 }


this.playGallerySound= function() {
	var soundfile = 'sound/crowd-talking-10.mp3';
	var div = document.createElement('div')
	div.id='gallerysound';
	$('main').appendChild(div);
	$("gallerysound").innerHTML= "<embed src=\""+soundfile+"\" hidden=\"true\" autostart=\"true\" loop=\"true\" />";
 }

 this.turnsoundonoff = function(){
	 var soundfile = 'sound/crowd-talking-10.mp3';
	 try{
		if($("gallerysound").innerHTML.length>0){
			$("gallerysound").update();
			$('soundonoff').src='img/sound_mute.png';
			$('soundonoff').className='soundmute';
		}
		else{
			/*
			var div = document.createElement('div')
			div.id='gallerysound';
			$('main').appendChild(div);
			*/
			$("gallerysound").innerHTML= "<embed src=\""+soundfile+"\" hidden=\"true\" autostart=\"true\" loop=\"true\" />";
			$('soundonoff').src='img/sound.png';
			$('soundonoff').className='soundon';
		}
	 }
	 catch(e){
		
	 }
}
//main.playGallerySound('sound/crowd-talking-10.mp3'); 
  


  
	
	
	
	
	
	
	
	
    //TOP LINKS
    this.build_toplinks = function(page){
	    //top links
	var toplinkcontainer = document.createElement('div');
	toplinkcontainer.id='toplinkcontainer';
	$('main').appendChild(toplinkcontainer);
	    
	var highlite ='';
	//home
	var link = document.createElement('div');
	link.className='toplink' + highlite;
	link.onclick=function(){
		main.init();
	}
	link.appendChild(document.createTextNode('Home'));
	$('toplinkcontainer').appendChild(link);
	
	//gallery
	if(page=='gallery'){
		highlite='on';
	}
	else{
		highlite='';
	}
	var link = document.createElement('div');
	link.className='toplink' + highlite;
	link.onclick=function(){
		main.build_gallerypage();
	}
	link.appendChild(document.createTextNode('Gallery'));
	$('toplinkcontainer').appendChild(link);
	
	//pricelist
	if(page=='pricelist'){
		highlite='on';
	}
	else{
		highlite='';
	}
	var link = document.createElement('div');
	link.className='toplink' + highlite;
	link.onclick=function(){
		main.build_pricelistpage();
	}
	link.appendChild(document.createTextNode('Price List'));
	$('toplinkcontainer').appendChild(link);
	
	//biography
	if(page=='biography'){
		highlite='on';
	}
	else{
		highlite='';
	}
	var link = document.createElement('div');
	link.className='toplink' + highlite;
	link.onclick=function(){
		main.build_biographypage();
	}
	link.appendChild(document.createTextNode('Biography'));
	$('toplinkcontainer').appendChild(link);
	
	//contact
	if(page=='contact'){
		highlite='on';
	}
	else{
		highlite='';
	}
	var link = document.createElement('div');
	link.className='toplink' + highlite;
	link.onclick=function(){
		main.build_contactpage();
	}
	link.appendChild(document.createTextNode('Contact'));
	$('toplinkcontainer').appendChild(link);
	
    }
    
    
    
    
    
   //CONTACT CREATION
    this.build_contactpage = function(){
	/*
	$('main').update();
		    
	var div = document.createElement('div');
	div.id='logo';
	div.appendChild(document.createTextNode('Sharon Charney'));
	$('main').appendChild(div);
	
	main.build_toplinks('contact');
	*/
	try{
		document.location = 'mailto:sharoncharney@hotmail.com';
	}
	catch(e){
		
	}
	
	
    }
    
    
    
    
    //BIOGRAPHY CREATION
    this.build_biographypage = function(){
	$('main').update();
	
	var div = document.createElement('div');
	div.id='logo';
	div.appendChild(document.createTextNode('Sharon Charney'));
	$('main').appendChild(div);
	    
	main.build_toplinks('biography');
	    
	var div = document.createElement('div');
	div.className='biotext';
	div.appendChild(document.createTextNode('Sharon Charney was born in Pittsburgh, Pennsylvania. She began studying art at an early age and went on to major in painting in college at Carnegie Mellon University. There she studied with Lawrence Calcagno and earned a Bachelor of Fine Arts Degree. She continued her art studies at the University of Wisconsin, studying with abstract expressionist Milton Resnick, and earning a master\'s degree.'));
	div.appendChild(document.createElement('br'));
	div.appendChild(document.createElement('br'));
	var img=document.createElement('img');
	img.src='img/Headshot.jpg';
	img.id='bioimage';
	div.appendChild(img);
	div.appendChild(document.createTextNode('Her first solo exhibition was in Madison Wisconsin. She has had numerous solo exhibitions over the past thirty five years, including shows at the Metro Nashville International Airport, and The Tennessee Performing Arts Center. In addition to local exhibitions, she has participated in national and regional juried exhibitions. Her paintings are in many corporate and private collections throughout the United States and abroad. Her work is also published in American Art Collector, Alcove Books, 2005.'));
	div.appendChild(document.createElement('br'));
	div.appendChild(document.createElement('br'));
	div.appendChild(document.createTextNode('Online her paintings may be seen at '));
	
	//var a = document.createElement('a');
	//a.className='generallink';
	//a.setAttribute('href','http://www.art-exchange.com');
	//a.innerText = 'www.art-exchange.com';
	//div.appendChild(a);
	var link = document.createElement('div');
	link.className='generallink';
	link.appendChild(document.createTextNode('www.art-exchange.com'));
	link.onclick=function(){
		window.open('http://www.art-exchange.com/search_result.aspx?Ltr=C&ArtistId=48205');
	}
	div.appendChild(link);
	div.appendChild(document.createTextNode(' and at the '));
	var link = document.createElement('div');
	link.className='generallink';
	link.appendChild(document.createTextNode('Metro Nashville Artist Registry'));
	link.onclick=function(){
		window.open('http://www.artsnashville.org/registry/index.php?scan=az&main=artist&id=166');
	}
	div.appendChild(link);
	div.appendChild(document.createTextNode('.'));
	
	
	div.appendChild(document.createElement('br'));
	div.appendChild(document.createElement('br'));
	div.appendChild(document.createTextNode('Charney is best known for her use of color and her imaginative interpretations of her subjects.'));
	
	$('main').appendChild(div);
	
	var div = document.createElement('div');
	div.id='insidepages_copyright';
	$('main').appendChild(div);
	div.appendChild(document.createTextNode(main.l_copyright));
	
    }
    
    
    //PRICELIST CREATION
    this.build_pricelistpage = function(){
	$('main').update();
	
	var div = document.createElement('div');
	div.id='logo';
	div.appendChild(document.createTextNode('Sharon Charney'));
	$('main').appendChild(div);
	    
	main.build_toplinks('pricelist');
	    
	var div = document.createElement('div');
	div.id='comingsoon';
	$('main').appendChild(div);
	
	div.appendChild(document.createTextNode('Coming soon...'));

    }


    
    
    
    //GALLERY CREATION
    this.build_gallerypage = function(){
	$('main').update();
	
	main.playGallerySound(); 
	
	var div = document.createElement('div');
	div.id='logo';
	div.appendChild(document.createTextNode('Sharon Charney'));
	$('main').appendChild(div);
	    
	main.build_toplinks('gallery');
	
	


	

	

	
	
	
	
	
	
	
		
	
		
		
	var x = new Ajax.Request('php/getpaintingcategories.php', {
            method: 'post',
            parameters: {
            },
            onSuccess: handle_getPaintingcategories,
            onFailure: function(x,y) {
                alert('data retrieval failure');
                //module_container.className = 'module_container';
                //$('back').hide();
            }
        });
	    
    }
  function handle_getPaintingcategories(transport){
		var xml = transport.responseXML;
	   
		if(xml!=null)
		{
			var errors = xml.getElementsByTagName('error');
			if(errors.length>0)
			{
				alert(errors.length);
				var msg = main.getNodeValue(errors[0], 'message');
				alert(msg);
				return;
			}
		
			var rows = xml.getElementsByTagName('row');
			/*
			var scroll_container=$('gallerycategorylinkscrollcontainer');
			var scroll_left = $('gallerylinks_scroll_left');
			var linkcontainer = $('gallerylinks_container');
			var scroll_area = $('gallerylinks_scrollable_area');
			*/
		
			var scroll_container=document.createElement('div');
			scroll_container.id='gallerycategorylinkscrollcontainer';
			$('main').appendChild(scroll_container);
				
			var scroll_left = new Element('div', {id: 'gallerylinks_scroll_left'});
			scroll_container.appendChild(scroll_left);

			var linkcontainer = new Element('div', {id: 'gallerylinks_container'});

			var scroll_area = new Element('div', {id: 'gallerylinks_scrollable_area'});

	
			for(var i=0;i<rows.length;i++){
				var categoryid = main.getNodeValue(rows[i], 'paintingcategoryid');
				var category = main.getNodeValue(rows[i], 'paintingcategorydescr');
				
				//gallery link 1
				categorylink = document.createElement('div');
				if(i==0){
					categorylink.className='gallerycategorylinkon';
				}
				else{
					categorylink.className='gallerycategorylink';
				}
				categorylink.id='categorylink_' + categoryid;
				categorylink.appendChild(document.createTextNode(category));
				
				scroll_area.appendChild(categorylink);
				categorylink.onclick=function(self){
					var categorylinkid = this.id.replace('categorylink_','');
					$$('#gallerylinks_scrollable_area').each(
						function(object,index){
						for(var x=0; x<object.childNodes.length;x++){
							object.childNodes[x].className = 'gallerycategorylink';
						};
						
					});
					this.className = 'gallerycategorylinkon';
					main.showgallerypictures(categorylinkid);
				}
			}
			
			
			
			linkcontainer.appendChild(scroll_area);
			
			scroll_container.appendChild(linkcontainer);

			var scroll_right = new Element('div', {id: 'gallerylinks_scroll_right'});
			scroll_container.appendChild(scroll_right);

			$('main').appendChild(scroll_container);

			
			var total_margin = $$('#gallerylinks_scrollable_area div').length; // * 24;
			var total_widthOfElements = 0;
			$$('#gallerylinks_scrollable_area div').each(function(obj,ix) {
			    total_widthOfElements+=obj.getWidth();
			});
			
			if((total_widthOfElements+total_margin)>(linkcontainer.getWidth()+5))
			{
			    scroll_right.title = 'more paintings';
			    scroll_right.onclick = scroll_gallerylinks;
			    scroll_right.className = 'active';
			}
		}

		
		/*
		var img = document.createElement('img');
		img.src='img/whitepixel.png';
		img.id='gallerypixelextension';
		$('main').appendChild(img);
		*/
		var img = document.createElement('img');
		img.src='img/linktriangle2.png';
		img.id='gallerytriangleextension';
		$('main').appendChild(img);
		
		//picture container
		var div = document.createElement('div');
		div.id='picturecontainer';
		$('main').appendChild(div);


		var img=document.createElement('img');
		img.src='img/sound.png';
		img.id='soundonoff';
		img.className='soundon';
		$('main').appendChild(img);
		img.onclick=function(){
			main.turnsoundonoff();
		}
	
		
	div = document.createElement('div');
	div.id='gallerycontainer';
	$('main').appendChild(div);
	
	div = document.createElement('div');
	div.id='thumbnailscrollcontainer';
	$('gallerycontainer').appendChild(div);
		
	
	div = document.createElement('div');
	div.id='thumbnailscrollleft';
	$('thumbnailscrollcontainer').appendChild(div);
	
	div = document.createElement('div');
	div.id='thumbnaillinks_container';	
	$('thumbnailscrollcontainer').appendChild(div);
		
	div = document.createElement('div');
	div.id='thumbnaillinks_scrollable_area';	
	$('thumbnaillinks_container').appendChild(div);
		
	
	
	

	main.showgallerypictures(1);
	
	}
	
	
	
	
	function scroll_gallerylinks()
	{
		var direction = this.id;
		var container_width = $('gallerylinks_container').getWidth();
		//        var scroll_area_width = $('scrollable_area').getWidth();
		//        var move = scroll_area_width - container_width;
		var total_margin = $$('#gallerylinks_scrollable_area div').length; //*24
		var total_widthOfElements = 0;
		$$('#gallerylinks_scrollable_area div').each(function(obj,ix) {
		    total_widthOfElements+=obj.getWidth();
		});
		var move = (total_widthOfElements + total_margin) - container_width;
		if(direction=='gallerylinks_scroll_right') move = -move;
		new Effect.Move('gallerylinks_scrollable_area', { 
			x: move, 
			y: 0,
			mode:'relative'
		});

		if(direction=='gallerylinks_scroll_right')
		{
		    $('gallerylinks_scroll_left').title = 'more paintings';
		    $('gallerylinks_scroll_left').className = 'active';
		    $('gallerylinks_scroll_left').onclick = scroll_gallerylinks;
		}
		else if(direction=='gallerylinks_scroll_left')
		{
		    $('gallerylinks_scroll_right').title = 'more paintings';
		    $('gallerylinks_scroll_right').className = 'active';
		    $('gallerylinks_scroll_right').onclick = scroll_gallerylinks;
		}

		this.title = '';
		this.className = '';
		this.onclick = function() {  };
	};																			

	
	
	
	function scroll_thumbnaillinks(reset)
	{
		if(reset==1){
			$('thumbnaillinks_scrollable_area').style.left='0px';
		}
		else{
			var direction = this.id;
			var container_width = $('thumbnaillinks_container').getWidth();
			//        var scroll_area_width = $('scrollable_area').getWidth();
			//        var move = scroll_area_width - container_width;
			var total_margin = $$('#thumbnaillinks_scrollable_area img').length; //*24
			var total_widthOfElements = 0;
			$$('#thumbnaillinks_scrollable_area img').each(function(obj,ix) {
			    total_widthOfElements+=obj.getWidth();
			});
			//var move = (total_widthOfElements + total_margin) - container_width;
			var moveamount = 660;
			var move = moveamount;
			//var move = (total_widthOfElements + total_margin) - container_width;
			if(direction=='thumbnailscrollright') move = -move;
			new Effect.Move('thumbnaillinks_scrollable_area', { 
				x: move, 
				y: 0,
				mode:'relative'
			});
			
			
		

			if(direction=='thumbnailscrollright')
			{
			    $('thumbnailscrollleft').title = 'more paintings';
			    $('thumbnailscrollleft').className = 'active';
			    $('thumbnailscrollleft').onclick = scroll_thumbnaillinks;
			}
			else if(direction=='thumbnailscrollleft')
			{
			    $('thumbnailscrollright').title = 'more paintings';
			    $('thumbnailscrollright').className = 'active';
			    $('thumbnailscrollright').onclick = scroll_thumbnaillinks;
			}
			
			var pos = $('thumbnaillinks_scrollable_area').style.left
			pos = pos.replace('px','');
			if(direction=='thumbnailscrollright'){
				pos=(pos*1)-moveamount;
			}
			else {
				pos=(pos*1)+moveamount;
			}
			//alert(pos);
		
			if(pos<(-total_widthOfElements+750)){
				$('thumbnailscrollright').title = '';
				$('thumbnailscrollright').className = '';
				$('thumbnailscrollright').onclick = function() {  };
			}
			
			if(pos>=0){
				//alert(pos);
				$('thumbnailscrollleft').title = '';
				$('thumbnailscrollleft').className = '';
				$('thumbnailscrollleft').onclick = function() {  };
			}
			//alert(pos);
		}
	};																			

	
	
	
	
	
	
    //GET GALLERY PICTURE THUMBNAILS
    this.showgallerypictures = function(categoryid){
	  //  $('thumbnailscrollcontainer').style.width='780px';
	    
     var x = new Ajax.Request('php/getpaintings.php', {
            method: 'post',
            parameters: {
                paintingcategoryid: categoryid
            },
            onSuccess: handle_getPaintings,
            onFailure: function(x,y) {
                alert('data retrieval failure');
                //module_container.className = 'module_container';
                //$('back').hide();
            }
        });
	    
    }
  function handle_getPaintings(transport){
	     var xml = transport.responseXML;
	   
	  $('thumbnaillinks_scrollable_area').update();
	  $('picturecontainer').update();
	    //alert(xml);
	      if(xml!=null)
		{
			main.l_xml = xml;
			var errors = xml.getElementsByTagName('error');
			if(errors.length>0)
			{
				alert(errors.length);
				var msg = main.getNodeValue(errors[0], 'message');
				alert(msg);
				main.logout();
				return;
			}
		
			var rows = xml.getElementsByTagName('row');
			
			
			//$('thumbnaillinks_container').style.width='1500px';
			/*
			var tmpwidth = $('thumbnailscrollcontainer').style.width;
			//alert(tmpwidth.replace('px',''));
			var width = tmpwidth.replace('px','');
			if(rows.length>7){
				width = width + ((rows.length-6)*100);
				$('thumbnailscrollcontainer').style.width=width + 'px';
			}
			*/
			
			for (var i=0;i<rows.length;i++){
				var filename = 'img/gallery/' + main.getNodeValue(rows[i], 'filename');
				var name = main.getNodeValue(rows[i], 'name');
				var dimensions = main.getNodeValue(rows[i], 'dimensions');
				var paintingid = main.getNodeValue(rows[i], 'paintingid');
				var thumbnail = main.getNodeValue(rows[i], 'thumbnail');
				var price = main.getNodeValue(rows[i], 'price');
				var bsold = main.getNodeValue(rows[i], 'bsold');
				var bunavailable = main.getNodeValue(rows[i], 'bunavailable');
				var paintingcategorydescr = main.getNodeValue(rows[i], 'paintingcategorydescr');
				var paintingtypedescr = main.getNodeValue(rows[i], 'paintingtypedescr');
				var width = main.getNodeValue(rows[i], 'width');
				var height = main.getNodeValue(rows[i], 'height');
				
				//for(var t=0;t<4;t++){
					//MAKE THUMBNAILS
					var img = document.createElement('img');
					if (thumbnail!=''){
						img.src =  'img/gallery/' + thumbnail;
					}
					else{
						img.src = filename;
					}
					//img.lowsrc = 'img/ajax-loader.gif';
					//alert(img.offsetWidth);
					img.className='thumbnaildark';
					img.id='thumbnail_' + paintingid;
					$('thumbnaillinks_scrollable_area').appendChild(img);
					main.clipImage(img,width,height,90,90);
				//}
				
				if(i==0){
					//SHOW FIRST IMAGE (i.e. click)
					main.loadpicture(paintingid);
					
				}
				
				img.onclick=function(self){
					//SHOW IMAGE WHEN CLICKED
					var paintingid = this.id.replace('thumbnail_','');
					main.loadpicture(paintingid);
					
				}
				
				
			}
			
	   
			
		}
		
		try{
			var element = document.getElementById('thumbnailscrollright');
			element.parentNode.removeChild(element);
		}
		catch(err){
		}
		
		var thumbnailscrollright = document.createElement('div');
		thumbnailscrollright.id='thumbnailscrollright';
		$('thumbnailscrollcontainer').appendChild(thumbnailscrollright);
	
		var total_margin = $$('#thumbnaillinks_scrollable_area div').length * 24;
		var total_widthOfElements = 0;
		$$('#thumbnaillinks_scrollable_area img').each(function(obj,ix) {
		    total_widthOfElements+=obj.getWidth();
		});

		scroll_thumbnaillinks(1);
		
		try{
			var thumbnailscrollleft = $('thumbnailscrollleft');
			thumbnailscrollleft.title = '';
			thumbnailscrollleft.className = '';
			thumbnailscrollleft.onclick = function() {  };
		}
		catch(err){
			
		}
			
		if((total_widthOfElements+total_margin)>$('thumbnaillinks_container').getWidth())
		{
		    thumbnailscrollright.title = 'more paintings';
		    thumbnailscrollright.onclick = scroll_thumbnaillinks;
		    thumbnailscrollright.className = 'active';
		}
		else{
			thumbnailscrollright.title = '';
			thumbnailscrollright.className = '';
			thumbnailscrollright.onclick = function() {  };
		}
    }


  
//LOAD A SINGLE PAINTING, and DARKEN ALL OTHER THUMBNAILS
this.loadpicture = function(pictureid){
	try{
		$('picturecontainer').update();
	}
	catch(e){
		
	}
	main.l_soundnumber++;
	if(main.l_soundnumber>6){
		main.l_soundnumber = 1;
	}
	//main.playSound('sound/page-flip-' + main.l_soundnumber + '.mp3'); 
	
	
	
	
	
	var img = document.createElement('img');
	
	
	var id = '';
	var filename = '';
	var name = '';
	var dimensions = '';
	var thumbnail ='';
	var price = '';
	var bsold = '';
	var bunavailable = '';
	var paintingcategorydescr ='';
	var paintingtypedescr = '';
	
	
	var rows = main.l_xml.getElementsByTagName('row');
	for (var i=0;i<rows.length;i++){
		
		 id = main.getNodeValue(rows[i], 'paintingid');
		 filename = 'img/gallery/' + main.getNodeValue(rows[i], 'filename');
		 name = main.getNodeValue(rows[i], 'name');
		 dimensions = main.getNodeValue(rows[i], 'dimensions');
		 thumbnail = main.getNodeValue(rows[i], 'thumbnail');
		 price = main.getNodeValue(rows[i], 'price');
		 bsold = main.getNodeValue(rows[i], 'bsold');
		 bunavailable = main.getNodeValue(rows[i], 'bunavailable');
		 paintingcategorydescr = main.getNodeValue(rows[i], 'paintingcategorydescr');
		 paintingtypedescr = main.getNodeValue(rows[i], 'paintingtypedescr');
		width = main.getNodeValue(rows[i], 'width');		
		height = main.getNodeValue(rows[i], 'height');		
		
		if(pictureid==id){
			img.id=id;
			img.src=filename;
			img.title='View large image';
			img.onclick=function(self){
			
				var rows = main.l_xml.getElementsByTagName('row');
				for (var i=0;i<rows.length;i++){
					var id = main.getNodeValue(rows[i], 'paintingid');
					var filename = main.getNodeValue(rows[i], 'filename');
					if(id==this.id){
						var width = main.getNodeValue(rows[i], 'width') * 1 + 10;
						var height = main.getNodeValue(rows[i], 'height');
						//var randomnumber=Math.floor(Math.random()*11) //this.src
						
						window.open('largeimage.htm?img=' + filename,'paintinglargeview' + this.id,'toolbar=no,scrollbars=0,resizable=no,titlebar=no,height=' + height  + ',width=' + width  + '');
					}
				}
				
			}
			//img.lowSrc='img/ajax-loaderbig.gif';
			break;
		}
	}
			
	var div = document.createElement('div');
	div.id='paintingtextcontainer';
	$('picturecontainer').appendChild(div);
	
	//title
	var div = document.createElement('div');
	div.id='paintingtitle';
	div.appendChild(document.createTextNode(name));
	$('paintingtextcontainer').appendChild(div);
	
	//medium
	var div = document.createElement('div');
	div.id='paintingtypedescr';
	div.appendChild(document.createTextNode(paintingtypedescr));
	$('paintingtextcontainer').appendChild(div);
	
	//dimensions
	var div = document.createElement('div');
	div.id='paintingdimensions';
	div.appendChild(document.createTextNode(dimensions));
	$('paintingtextcontainer').appendChild(div);
	
	
	$('picturecontainer').appendChild(img);
	
	main.clipImage(img,width,height,350,360);
	img.className='picture';
	
	
	//DARKEN ALL THUMBNAILS
	$$('#thumbnaillinks_scrollable_area').each(
		function(object,index){
		for(var x=0; x<object.childNodes.length;x++){
			object.childNodes[x].className = 'thumbnaildark';
		};
		
	});
	//LIGHTEN CURRENT THUMBNAIL
	$('thumbnail_' + pictureid).className = 'thumbnail';
	
	/*
	var img = document.createElement('img');
	img.id='largecrack';
	img.src='img/wallcrack2.png';	
	$('picturecontainer').appendChild(img);
	if(main.l_soundnumber<=2){
		$('largecrack').style.top='190px';
		$('largecrack').style.left='530px';
		$('largecrack').style.width='260px';
	}
	else if(main.l_soundnumber==6){
		$('largecrack').style.top='100px';
		$('largecrack').style.left='530px';
		$('largecrack').style.width='160px';
	}
	else if(main.l_soundnumber==3){
		$('largecrack').style.top='120px';
		$('largecrack').style.left='120px';
		$('largecrack').style.width='100px';
	}
	else if(main.l_soundnumber==4){
		$('largecrack').style.top='320px';
		$('largecrack').style.left='100px';
		$('largecrack').style.width='100px';
	}
	else{
		$('largecrack').style.top='190px';
		$('largecrack').style.left='0px';
		$('largecrack').style.width='150px';
	}
	*/
	try{
		var e = $('insidepages_copyright');
		e.parentNode.removeChild(e);
	}
	catch(err){
		
	}
	
	var div = document.createElement('div');
	div.id='insidepages_copyright';
	$('main').appendChild(div);
	div.appendChild(document.createTextNode(main.l_copyright));
	div.style.top='134px';
	
}
    
//CLIPS IMAGE TO MAX HEIGHT MAX WIDTH
this.clipImage = function(img,width,height,maxheight,maxwidth){
	//var width=img.width;
	//if(width==0){
	//	//width=600;
	//}
	//var height = img.height;
	var newx = maxwidth; // set to whatever you want the images max width to be.
	var newy = maxheight; // whatever you want the images maximum height to be.
	if ( width >= height ) {
		// landscape
		var tmpy = height*newx/width;
		
		if ( tmpy <= newy ){
			newy = tmpy;
		}
		else{
			newx = width*newy/height;
		}
	}
	else {
		// portrait
		tmpx = width*newy/height;
		if ( tmpx <= newx ){
			newx = tmpx;
		}
		else{
			newy = height*newx/width;
		}
	}
	//alert(newx);
	//alert(newy);
	if(newx!=NaN){
		img.width = newx;
	}
	if(newy!=NaN){
		img.height = newy;
	}
}






 this.getNodeValue = function(obj,tag) { return getNodeValue(obj,tag); };
    function getNodeValue(obj,tag) {
		try {
			if(obj.getElementsByTagName(tag)[0].firstChild.nodeValue) { return obj.getElementsByTagName(tag)[0].firstChild.nodeValue; }
			else return '';
		}
		catch (e) { return ''; }
	};

    
}





main.init();
