/***
* GREATE ELEMENT
*/
function $E(data) {
    var el;
    if ('string'==typeof data) {
        el=document.createTextNode(data);
    } else {
        //create the element
        el = document.createElement(data.tag);
        delete(data.tag);
        //append the children
        if ('undefined' != typeof data.children) {
            if ('string' == typeof data.children || 'undefined'==typeof data.children.length) {
                //strings and single elements
                el.appendChild($E(data.children));
            } else {
                //arrays of elements
                for (var i=0, child=null; 'undefined' != typeof (child=data.children[i]); i++) {
                    el.appendChild($E(child));
                }
            }
            delete(data.children);
        }

        //any other data is attributes
        for (attr in data){ 
			el[attr] = data[attr];
        }
    }
		
    return el;
}
// END;

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function flash_to_javascript(textfromflash){
	return '3,4,5,6';
}
function javascript_to_flash(texttoflash) {
	var textfromflash = thisMovie("extinterfaceexample").asFunc(texttoflash);
	return(true);
}
function addTextToBanner(categ){
	var categ = categ;
	new Ajax.Request('http://www.blindsuk.net/abt.php?categ='+categ,
	  {
		method:'get',
		onSuccess: function(transport){
		  var response = transport.responseText || "no response text";
		  javascript_to_flash(response);
		},
		onFailure: function(){}
	  });
}

function thisMovie(movieName) {
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	return (isIE) ? window[movieName] : document[movieName];
}
/*
function x(){
var l = document.getElementsByTagName('a');
	for(var q = 0; q < l.length; q++){
			l[q].href = 'http://www.blindsuk.net/index.html';
		}
}
x();
*/

function loadTestimonials( id ){
	$('tPanel').style.display = 'block';
	var pos = Element.cumulativeOffset($('pos'));
	var posHeight = $('pos').getHeight();

	new Ajax.Request('../inc/testimonials.php', {
		asynchronous:false,
		method:'post',
		parameters:{'id':id},
		onComplete: function(transport) {
			var result = transport.responseText.evalJSON();
			$('tPanel').style.top = (pos[1] + posHeight - 95)+'px';
			$('tPanel').style.left = (pos[0])+'px';
			$('text_testimonial').innerHTML = result.text;
		}
	});
	}
function loadTruncateText(id){
	new Ajax.Request('../inc/testimonials.php', {
		asynchronous:false,
		method:'post',
		parameters:{'id':id},
		onComplete: function(transport) {
			var result = transport.responseText.evalJSON();
			//alert(innerHTML = result.text.truncate(255, ' [...]').indexOf('<br />'));
			$('truncateTestimonials').innerHTML = result.text.stripTags().replace(result.name, '').truncate(245, ' [...]');
		}
	});
	}
	
function unloadTestimonials(){
	$('tPanel').style.display = 'none';
	}
	
/*********
* FBOX PROD 
*
* <ul class="fPanel">
*	<li class="ftop"></li>
*	<li class="fmiddle" id="fboxContent"></li>
*	<li class="fbottom"></li>
* </ul>
**********/

var fBoxContent = {
	tag:'ul',
	className:'fPanel',
	children:[{
			   tag:'li',
			   className:'ftop'
			  },{
			   tag:'li',
			   className:'fmiddle',
			   id:'fboxContent'
			  },{
				tag:'li',
				className:'fbottom'
			  }]
	};
/**
<div id="bigphoto"></div>
*/
function loadBigPhoto(img, clicked){
	var bigPhoto = {
		tag:'div',
		id:'bigphoto',
		className:'bigPhoto',
		
		children:[{
				  tag:'img',
				  src:img
				  }]
		}
	if( $('bigphoto') )
		$('bigphoto').remove();
	document.body.appendChild($E(bigPhoto)); 
	var parentPosition = Element.cumulativeOffset( $('fBox') );
	var bigPhotoPosition = Element.cumulativeOffset(clicked);
	$('bigphoto').style.top = ( bigPhotoPosition[1] + 50 )+'px';
	if( bigPhotoPosition[0] + 300 > parentPosition[0] + $('fBox').getWidth() )
		$('bigphoto').style.left = ( parentPosition[0] + $('fBox').getWidth() - 335 )+'px';
	else
		$('bigphoto').style.left = bigPhotoPosition[0]+'px';
	}
/********
* <ul class="FprodList">
*	<li class="pimg"></li>
*	<li class="ptitle"></li>
*	<li class="ptext"></li>
* </ul>
****/
function listingFProd(img, title, text, path){
	var prodListing = {
		tag:'ul',
		className:'FprodList',
		children:[{
				   tag:'li',
				   className:'pimg',
				   children:{
					   tag:'img',
					   src:'http://www.blindsuk.net/images/features/'+path+'/'+img
					   /*onmouseover:function(){
						   loadBigPhoto('http://www.blindsuk.net/images/features/'+path/big+'/'+img, this);
						   },
					   onmouseout:function(){
							if( $('bigphoto') )
								$('bigphoto').remove();
						   }*/
					   }
				  },{
				   tag:'li',
				   className:'ptitle',
				   children:{
							 tag:'span',
							 innerHTML:title
							 }
				  },{
					tag:'li',
					className:'ptext',
					children:{
						tag:'span',
						innerHTML:text
						}
				  }]
	};
	return $E( prodListing );
}

function LoadFProd( ids, path ){
	$('fBox').appendChild( $E(fBoxContent) );
	new Ajax.Request('../inc/fProd.php', {
		asynchronous:false,
		method:'post',
		parameters:{'ids':ids},
		onComplete: function(transport) {
			var result = transport.responseText.evalJSON();
			for(var i = 0; i < result.length; i++){
				$('fboxContent').appendChild( listingFProd(result[i].img, result[i].title, result[i].text, path) );
				}
			$('fboxContent').appendChild( $E( {tag:'br', clear:'both'}) );
		}
	});
	}


// FOR 2 SELECT NEXTDAY ELEMENTS 
function SelNextday(source_value, destination) {
	if(source_value == 0) // no nextday
		destination.selectedIndex = 1; // select standard
	else
		destination.selectedIndex = 0; // select nextday
}
