// JavaScript Document
 function get_cookie(cookie_name) {
        var results = document.cookie.match('(^|;) ?' + cookie_name + '=([^;]*)(;|$)');
        alert(unescape(results[2]));
        if (results) {
            //alert(unescape(results[2]));
            return (unescape(results[2]));
        }
        else
            return null;
    }


    function set_cookie(name, value, exp_y, exp_m, exp_d, path, domain, secure) {
        //var cookie_string = "";
        var cookie_string = name + "=" + escape(value);

        if (exp_y) {
            var expires = new Date(exp_y, exp_m, exp_d);
            cookie_string += "; expires=" + expires.toGMTString();
        }

        if (path)
            cookie_string += "; path=" + escape(path);

        if (domain)
            cookie_string += "; domain=" + escape(domain);

        if (secure)
            cookie_string += "; secure";

        document.cookie = cookie_string;
    }
	
	function removeChildNodes(ctrl)
	{
  		while (ctrl.childNodes[0])
  		{
    		ctrl.removeChild(ctrl.childNodes[0]);
  		}
	}
	
	function MM_Init()
	{
		var newWineSliderThumb = document.getElementById('WineSliderThumb');
		var thumbelem = document.getElementById('WineSliderThumbMain');
		var myallContainedElements = thumbelem.getElementsByTagName('img');
		var newdivOuter = document.createElement('div');
		newdivOuter.setAttribute('id','myOuterDiv');
		var newdivInner = document.createElement('div');
		newdivInner.setAttribute('id','myInnerDiv');
		var newtable = document.createElement('table');
		var tl = myallContainedElements.length * 218;
		newtable.setAttribute('width',tl);
  		newtable.setAttribute('height','400');
		newtable.setAttribute('cellspacing','0');
		newtable.setAttribute('cellpadding','0');
		newtable.setAttribute('border','0');
		var newtr = document.createElement('tr');
		var i = 0;
		var f = myallContainedElements.length;
    	for (i = 0; i < myallContainedElements.length; i++) {
        	var myimg = myallContainedElements[i];
			var newtd = document.createElement('td');
			newtd.setAttribute('width','218');
			newtd.setAttribute('valign','top');
			newtd.setAttribute('align','center');
			newtd.setAttribute('class','imgdiv');
		    newtd.className = "imgdiv";
			var newImg = document.createElement('img');
			newImg.setAttribute('src',myimg.getAttribute('src'));
			newImg.setAttribute('width', myimg.getAttribute('width'));
			newImg.setAttribute('height', myimg.getAttribute('height'));
			newtd.appendChild(newImg);
			newtr.appendChild(newtd);
		}
		newtable.appendChild(newtr);
		newdivInner.appendChild(newtable);
		newdivOuter.appendChild(newdivInner);
		newWineSliderThumb.appendChild(newdivOuter);
		removeChildNodes(thumbelem);
		
		//var x = get_cookie("myposition");
    var y = 1;
    //if (x != null) {
       //y = x;
    //}
    //if (x != null) {
       // newdivInner.setAttribute("style", "left: -" + (((parseInt(x) - 1) * 160)) + ((parseInt(x) - 1) * 10) + ";");
       // newdivInner.style.left = "-" + (((parseInt(x) - 1) * 160) + ((parseInt(x) - 1) * 10));
   // }
	
   // MM_Show(y, f);
    // alert(y);

    var browserName = navigator.appName;


    $('#WineSliderLeft').click(function() {
        var xlength2 = 0;
        var xPos2 = 0;

        if ((parseInt(y) - 1) > 0) {
            if (browserName == "Microsoft Internet Explorer") {
                xlength2 = 218;
            }
            else {
                xlength2 = 218;
            }
            xPos2 = parseInt(y) - 1;
        }
        else {
            xlength2 = 0;
            xPos2 = 0;
        }
        y = xPos2;
        $('#myInnerDiv').animate({
            left: "+=" + xlength2
        }, 1500, "swing", function() {
            //set_cookie("myposition", y);
            //MM_Show(y, f);
        });
    });

    $('#WineSliderBtnRight').click(function() {
        var xlength = 0;
        var xPos = 0;
        //alert(y + "," + f);
        if ((parseInt(f) - parseInt(y)) >= 4) {
            if (browserName == "Microsoft Internet Explorer") {
                xlength = 218;
            }
            else {
                xlength = 218;
            }
            xPos = parseInt(y) + 1;
        }
        else {
            //alert(y);
            //xlength = ((((parseInt(f) - 1) - parseInt(y))) * 218) + ((((parseInt(f) - 1) - parseInt(y))) * 10);
            //xPos = (parseInt(f) - 1);
            xlength = 0;
            xPos = parseInt(y);
        }
        y = xPos;
        //alert("-=" + xlength2 + "px");
        $('#myInnerDiv').animate({
            left: "-=" + xlength
        }, 1500, "swing", function() {
            //set_cookie("myposition", y);
            //MM_Show(y, f);
        });
    });

	}
	
	function MM_Init2()
	{
		var newWineSliderThumb = document.getElementById('VineyardSliderThumb');
		var thumbelem = document.getElementById('VineyardSliderThumbMain');
		var myallContainedElements = thumbelem.getElementsByTagName('img');
		var newdivOuter = document.createElement('div');
		newdivOuter.setAttribute('id','myOuterDiv');
		var newdivInner = document.createElement('div');
		newdivInner.setAttribute('id','myInnerDiv');
		var newtable = document.createElement('table');
		var f = myallContainedElements.length;
		var tl = myallContainedElements.length * 101;
		newtable.setAttribute('width',tl);
  		newtable.setAttribute('height','91');
		newtable.setAttribute('cellspacing','0');
		newtable.setAttribute('cellpadding','0');
		newtable.setAttribute('border','0');
		var newtr = document.createElement('tr');
		var i = 0;
		
    	for (i = 0; i < myallContainedElements.length; i++) {
        	var myimg = myallContainedElements[i];
			
			var newtd = document.createElement('td');
			newtd.setAttribute('width','101');
			newtd.setAttribute('valign','top');
			newtd.setAttribute('align','center');
			newtd.setAttribute('class','imgdiv2');
			newtd.className = "imgdiv2";
			var newImg = document.createElement('img');
			var newLink = document.createElement('a');
			newLink.setAttribute('href', myimg.getAttribute('longdesc'));
			newLink.setAttribute('class','lightboxCss');
			newLink.className = "lightboxCss";
			newLink.innerHTML = '<img src="' + myimg.getAttribute('src') + '" alt="" width="' 
			+ myimg.getAttribute('width') + '" height="' + myimg.getAttribute('height') + '" border="0" />';
			//newImg.setAttribute('src',myimg.getAttribute('src'));
			//newImg.setAttribute('width',myimg.getAttribute('width'));
			//newImg.setAttribute('height',myimg.getAttribute('height'));
			newtd.appendChild(newLink);
			newtr.appendChild(newtd);
		}
		newtable.appendChild(newtr);
		newdivInner.appendChild(newtable);
		newdivOuter.appendChild(newdivInner);
		newWineSliderThumb.appendChild(newdivOuter);
		removeChildNodes(thumbelem);
		
    	var y = 1;
	
    $('#VineyardSliderBtnLeft').click(function() {
        var xlength2 = 0;
        var xPos2 = 0;
		
        if ((parseInt(y) - 1) > 0) {
           
			xlength2 = 101;
            xPos2 = parseInt(y) - 1;
        }
        else {
             xlength2 = 0;
            xPos2 =0;
        }
        y = xPos2;
            $('#myInnerDiv').animate({
                left: "+=" + xlength2
            }, 1500, "swing", function() {
                    //set_cookie("myposition", y);
                    //MM_Show(y, f);
        });
    });

    $('#VineyardSliderBtnRight').click(function() {
        var xlength = 0;
        var xPos = 0;
        //alert(y + "," + f);
        if ((parseInt(f) - parseInt(y)) >= 8) {
            xlength = 101;
            xPos = parseInt(y) + 1;
        }
        else {
            //alert(y);
            //xlength = ((((parseInt(f) - 1) - parseInt(y))) * 218) + ((((parseInt(f) - 1) - parseInt(y))) * 10);
            //xPos = (parseInt(f) - 1);
			xlength = 0;
            xPos = parseInt(y);
        }
        y = xPos;
        //alert("-=" + xlength2 + "px");
       $('#myInnerDiv').animate({
                left: "-=" + xlength
            }, 1500, "swing", function() {
                    //set_cookie("myposition", y);
                    //MM_Show(y, f);
        });
    });

	}
	
	
