//version 19.10.09

String.prototype.toProperCase = function(){
     return this.toLowerCase().replace(/\w+/g,function(s){
          return s.charAt(0).toUpperCase() + s.substr(1);
     })
}

function onSelectColor(ind, color, base_folder)
{
	defColor[ind] = color;
	var img_url = base_folder+defColor.join("_")+".jpg";
	//alert(img_url);
	//alert([ind, color, base_folder]);
	//alert(defColor.join(" / ").replace(/\+/g, " ").toProperCase());
	thisMovie('zoomer').SelectColorImage(img_url, defColor.join(" / ").replace(/\+/g, " ").toProperCase());
}
var colcname;
function onJqueryLoad()
{
	$(document).ready(function()
	{
		$("#searchbox").keypress(function(event)

		{
			//alert(event.keyCode);
			if (event.keyCode == 13)
				startSearch();
		});
		if ($.browser.msie)
			$("#left_texts").css({"width":"181px", "margin-right":"0px"});
		//static cosmetic:
		$(".t_menu a,.b_menu a").each(function()
		{
			//alert($(this).attr("href").window.location.href.replace("http://www.lizfields.com", ""));
			tmp = window.location.href.split("fields.com")
			tmp = tmp[tmp.length-1];
			if ($(this).attr("href") == tmp)
			{
				$(this).css(
					{
						"color":"#256d93",
						"font-weight":"bold"
					}
				);
			}
		});
		//alert($("#outer_lent").size());
		if ($("#outer_lent").size() > 0)
		{
			colcname = window.location.href.split("/")[4]+"_scroll";
			//alert(colcname);
			var lt = readCookie(colcname);
			//alert(lt);
			if (lt)
			{
				$("#outer_lent").scrollLeft(lt);
			}
			$("#outer_lent").scroll(function()
			{			
				createCookie(colcname,$("#outer_lent").scrollLeft(),10);
			});
				
		}
	});
}

function sendEmail()
{
	data={};
	data.to = $("#sendEmailTo").val();
	data.text = $("#sendEmailText").val();
	$.post("/email.php", data, function(data)
	{
		if ($.trim(data) == "success")
		{
			alert("Your message has been successfully sent.");
			$('#email_holder').fadeOut('fast');
		}
		else
		{
			alert(data);
		}
	});
}
function ReloadMainImage(src)
{
	$("#mainImage").attr("src", src);
}
function AddToFavorites(n)
{
	$("#favlink").html("Please, wait...");
	$.post("/ajax.php?action=addf", {name:n}, function(data)
	{
		//alert(data);
		$("#favlink").replaceWith("<a class='print' href='/Bridesmaid-Wedding-Destination-Special-Dresses/Favorites/' style='color:green;'>My Favorite</a>");
	});
}
function RemoveFromFavorites(n)
{
	if (confirm("Are you sure you want to remove the style from My favorites?"))
	{
		$.post("/ajax.php?action=rmf", {name:n}, function(data)
		{
			window.location.reload();
		});
	}
}
swWindow = null;
function showSwatchHolder(cols)
{
	if (cols==2){ w=460; } else { w=300; }
	swWindow = window.open("", "swatches", "status=no,scrollbars=no,toolbar=no,location=no,menubar=no,width="+w+",height=520,left=250,top=100");
	swWindow.document.open("text/html", "replace");
	swWindow.document.write('<HTML><head><title>Swatch Card</title></head><BODY>'+$("#sw_card_holder").html()+"</BODY></HTML>");
	swWindow.document.close();
}
function startSearch()
{
	if($.trim($("#searchbox").val())!="")
	{
		$.get("/index.php?action=check_style_exist&name="+$.trim($("#searchbox").val()),
			{},
			function(data)
			{
				if ($.trim(data) == "exist")
					onStartSearch()
				else
					$("#searchbox").val("not found...");
			});
	}
}
function onStartSearch()
{
	window.location.href="/styles/"+$("#searchbox").val();
}
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

/***********************************
/*
Copyright (c) Copyright (c) 2007, Carl S. Yestrau All rights reserved.
Code licensed under the BSD License: http://www.featureblend.com/license.txt
Version: 1.0.4
*/
var FlashDetect = new function(){
    var self = this;
    self.installed = false;
    self.raw = "";
    self.major = -1;
    self.minor = -1;
    self.revision = -1;
    self.revisionStr = "";
    var activeXDetectRules = [
        {
            "name":"ShockwaveFlash.ShockwaveFlash.7",
            "version":function(obj){
                return getActiveXVersion(obj);
            }
        },
        {
            "name":"ShockwaveFlash.ShockwaveFlash.6",
            "version":function(obj){
                var version = "6,0,21";
                try{
                    obj.AllowScriptAccess = "always";
                    version = getActiveXVersion(obj);
                }catch(err){}
                return version;
            }
        },
        {
            "name":"ShockwaveFlash.ShockwaveFlash",
            "version":function(obj){
                return getActiveXVersion(obj);
            }
        }
    ];
    /**
     * Extract the ActiveX version of the plugin.
     * 
     * @param {Object} The flash ActiveX object.
     * @type String
     */
    var getActiveXVersion = function(activeXObj){
        var version = -1;
        try{
            version = activeXObj.GetVariable("$version");
        }catch(err){}
        return version;
    };
    /**
     * Try and retrieve an ActiveX object having a specified name.
     * 
     * @param {String} name The ActiveX object name lookup.
     * @return One of ActiveX object or a simple object having an attribute of activeXError with a value of true.
     * @type Object
     */
    var getActiveXObject = function(name){
        var obj = -1;
        try{
            obj = new ActiveXObject(name);
        }catch(err){
            obj = {activeXError:true};
        }
        return obj;
    };
    /**
     * Parse an ActiveX $version string into an object.
     * 
     * @param {String} str The ActiveX Object GetVariable($version) return value. 
     * @return An object having raw, major, minor, revision and revisionStr attributes.
     * @type Object
     */
    var parseActiveXVersion = function(str){
        var versionArray = str.split(",");//replace with regex
        return {
            "raw":str,
            "major":parseInt(versionArray[0].split(" ")[1], 10),
            "minor":parseInt(versionArray[1], 10),
            "revision":parseInt(versionArray[2], 10),
            "revisionStr":versionArray[2]
        };
    };
    /**
     * Parse a standard enabledPlugin.description into an object.
     * 
     * @param {String} str The enabledPlugin.description value.
     * @return An object having raw, major, minor, revision and revisionStr attributes.
     * @type Object
     */
    var parseStandardVersion = function(str){
        var descParts = str.split(/ +/);
        var majorMinor = descParts[2].split(/\./);
        var revisionStr = descParts[3];
        return {
            "raw":str,
            "major":parseInt(majorMinor[0], 10),
            "minor":parseInt(majorMinor[1], 10), 
            "revisionStr":revisionStr,
            "revision":parseRevisionStrToInt(revisionStr)
        };
    };
    /**
     * Parse the plugin revision string into an integer.
     * 
     * @param {String} The revision in string format.
     * @type Number
     */
    var parseRevisionStrToInt = function(str){
        return parseInt(str.replace(/[a-zA-Z]/g, ""), 10) || self.revision;
    };
    /**
     * Is the major version greater than or equal to a specified version.
     * 
     * @param {Number} version The minimum required major version.
     * @type Boolean
     */
    self.majorAtLeast = function(version){
        return self.major >= version;
    };
    /**
     * Is the minor version greater than or equal to a specified version.
     * 
     * @param {Number} version The minimum required minor version.
     * @type Boolean
     */
    self.minorAtLeast = function(version){
        return self.minor >= version;
    };
    /**
     * Is the revision version greater than or equal to a specified version.
     * 
     * @param {Number} version The minimum required revision version.
     * @type Boolean
     */
    self.revisionAtLeast = function(version){
        return self.revision >= version;
    };
    /**
     * Is the version greater than or equal to a specified major, minor and revision.
     * 
     * @param {Number} major The minimum required major version.
     * @param {Number} (Optional) minor The minimum required minor version.
     * @param {Number} (Optional) revision The minimum required revision version.
     * @type Boolean
     */
    self.versionAtLeast = function(major){
        var properties = [self.major, self.minor, self.revision];
        var len = Math.min(properties.length, arguments.length);
        for(i=0; i<len; i++){
            if(properties[i]>=arguments[i]){
                if(i+1<len && properties[i]==arguments[i]){
                    continue;
                }else{
                    return true;
                }
            }else{
                return false;
            }
        }
    };
    /**
     * Constructor, sets raw, major, minor, revisionStr, revision and installed public properties.
     */
    self.FlashDetect = function(){
        if(navigator.plugins && navigator.plugins.length>0){
            var type = 'application/x-shockwave-flash';
            var mimeTypes = navigator.mimeTypes;
            if(mimeTypes && mimeTypes[type] && mimeTypes[type].enabledPlugin && mimeTypes[type].enabledPlugin.description){
                var version = mimeTypes[type].enabledPlugin.description;
                var versionObj = parseStandardVersion(version);
                self.raw = versionObj.raw;
                self.major = versionObj.major;
                self.minor = versionObj.minor; 
                self.revisionStr = versionObj.revisionStr;
                self.revision = versionObj.revision;
                self.installed = true;
            }
        }else if(navigator.appVersion.indexOf("Mac")==-1 && window.execScript){
            var version = -1;
            for(var i=0; i<activeXDetectRules.length && version==-1; i++){
                var obj = getActiveXObject(activeXDetectRules[i].name);
                if(!obj.activeXError){
                    self.installed = true;
                    version = activeXDetectRules[i].version(obj);
                    if(version!=-1){
                        var versionObj = parseActiveXVersion(version);
                        self.raw = versionObj.raw;
                        self.major = versionObj.major;
                        self.minor = versionObj.minor; 
                        self.revision = versionObj.revision;
                        self.revisionStr = versionObj.revisionStr;
                    }
                }
            }
        }
    }();
};
FlashDetect.JS_RELEASE = "1.0.4";
