(function($) {
    $.fn.gcuiSwfObjEmbed = function(aSwf,aSettings) {
        if (aSwf) {
            var myConfig = {};
            $.each($.fn.gcuiSwfObjEmbed.defaults,function(k,v) {
                // NOTE: jQuery.extend() doesn't copy properties,
                // may work in jQuery 1.4, but we're on 1.3.2
                // copy default
                // http://jquery14.com/day-01/jquery-14
                var mySub = {};
                for (var p in v) {
                    mySub[p] = v[p];
                }
                // on the copy overwrite the defaults with the specific settings
                for (var p in aSettings[k]) {
                    mySub[p] = aSettings[k][p];
                }
                // assign to myConfig
                myConfig[k] = mySub;
            });
            this.each(function() {
                myConfig.attributes.id = $(this).attr('id');
                if (myConfig.attributes.id == '') {
                  gcui_log('ID of div missing, cannot embed video');
                }
                swfobject.embedSWF(
                    aSwf, myConfig.attributes.id, myConfig.config.width,
                    myConfig.config.height, myConfig.config.requiredVersion,
                    myConfig.config.alternativeSwf,
                    myConfig.flashvars, myConfig.params, myConfig.attributes
                    );
            });
        } else {
          console.log('aSwf not passed in');
        }
        return this;
    };
    $.fn.gcuiSwfObjEmbed.defaults = {
        config : {
            height : '360',
            width: '640',
            requiredVersion :  '8.0.0',
            alternativeSwf : 'expressInstall.swf'
        },
        params :{
            quality: "high",
            scale: "noscale",
            wmode: "transparent",
            allowscriptaccess: "always",
            allowFullScreen: "true",
            bgcolor: "#000000"
        },
        flashvars : {
            fullLocale:"en_US",
            locale:"en",
            cdnPath:"",
            localPath:"",
            trackerCode:"",
            configuration:"production",
            sharedAssetPath:"/assets/",
            siteAssetPath: "/assets/",
            sharedDataPath: "/en/sdata/",
            siteDataPath: "/data/",
            siteStylesPath: "/data/styles/",
            siteRootPath: "/",
            infoRequestUrl: "http://contact2.firechrome.org/inquiry.action",
            siteXML:"/site.xml",
            localePostfix: "",
            region: "US",
            autoplay: "true"
        },
        attributes : {}
    };

    $.createElement = function(aEl,innerHtml,aClose,attrs) {
        var r = ['<', aEl,' '];
        for(var k in attrs) {
            r.push(k);
            r.push('="');
            r.push($.isArray(attrs[k]) ? attrs[k].join(' ') : attrs[k]);
            r.push('" ');

        }
        r.push('>');
        r.push(innerHtml);
        if(aClose) {
            r.push('</');
            r.push(aEl);
            r.push('>');
        }
        return r.join('');
    };

    $.fn.gcuiSlideShow = function(aId,aImages,aSettings) {
        var config = {};
        if (settings) $.extend(config, settings);
        this.each(function() {});
        return this;
    };

    $.gcuiDataClone = function(aTarget,aSources) {
        // NOTE: jQuery.extend() doesn't copy properties we're on 1.3.2
        // http://jquery14.com/day-01/jquery-14
        var mySources = $.makeArray(aSources)
        $.each(mySources,function(i,v) {
            for (var p in v) {
                aTarget[p] = v[p];
            }
        });
        return aTarget;
    };
    $.intRange = function(aFrom,aTo,aMin,aMax,aDir) {
        var myF = parseInt(aFrom);
        var myT = parseInt(aTo);
        var myMin = parseInt(aMin);
        var myMax = parseInt(aMax);
        if(myF==myT) return [];
        var r = [myF];
        var myInc = aDir==null?myF < myT:aDir;
        var i = myF;
        while(i!=myT) {
            r.push(i = $.increment(i,myMin,myMax,myInc));
            //if(i) {break;}//Avoid infinite loops
        }
        return r;
    };
    $.increment = function(aFrom,aMin,aMax,aDir) {
        var i = aDir ? ++aFrom : --aFrom;
        if(i > aMax) return aMin;
        if(i < aMin) return aMax;
        return i;
    };
    $.getAt = function(aObj,aParams) {
    	    var r = null;
    	    $.each(aParams,function(){
		    if(aObj[this]) r=aObj[this];
    	    });
    	    return r; 
    };
    
	$.fn.customFadeIn = function(speed, callback) {
		return $(this).fadeIn($.support.opacity ? speed : 1,callback);
	};
	$.fn.customFadeOut = function(speed, callback) {
		return $(this).fadeOut($.support.opacity ? speed : 1,callback);
	};
	
	$.getHost = function() {
		var h = new String(document.location);
		return h.replace(/http:\/\/([^\/]*)\/.*/,'$1');
	};

	/**
	 * Find out if certain support exists
	 */
	$.gcuiSupports = function(features) {
	    var ret = true;
	    if (features.canvas) {
	        if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
	            return false;
	        }
	    }
		if (features.basic_html5) {
	        if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
	            return false;
	        }
 			if (/Version\/3\.[0-9. ]+ Safari\//.test(navigator.userAgent)) {
				return false;
	        }
			if (/Version\/3\.[0-9. ]+ Mobile\//.test(navigator.userAgent)) {
				return false;
	        }
			if (/Firefox\/[1-2]\.[0-9]/.test(navigator.userAgent)) {
				return false;
	        }
			if (/Firefox\/3\.0/.test(navigator.userAgent)) {
				return false;
	        }
			if (/iPad/.test(navigator.userAgent)) {
				return false;
			}
			if (/iPhone/.test(navigator.userAgent)) {
				return false;
			}
			/*if (/Version\/4\.[0-9. ]+ Mobile\//.test(navigator.userAgent)) {
				return false;
	        } */
	    }
	    return ret;
	};
	$.gcuiSupportsNativeCanvasText = function(supports) {
		var ret = true;
		if (supports.supportsCanvasText) {
 	        if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
	            return false;
	        }
			if (/Version\/3\.[0-9. ]+ Safari\//.test(navigator.userAgent)) {
				return false;
	        }
			if (/Version\/3\.[0-9. ]+ Mobile\//.test(navigator.userAgent)) {
				return false;
	        }
			if (/Version\/4\.[0-9. ]+ Mobile\//.test(navigator.userAgent)) {
				return false;
	        } 
	    }
		return ret;
	}
	

})(jQuery);

if(!console) {
    var console = {log : function(){}};
}

if (typeof $.fn.delay != 'function') {
    $.fn.delay = function(time, callback){
        jQuery.fx.step.delay = function(){};
        return this.animate({delay:1}, time, callback);
    }
}





