//var flashvars = {};
//var params = {
    //wmode:'transparent'
//};
//var attributes = {};

//swfobject.embedSWF("gallery.swf", "flash", "1001", "517", "9.0.0", "expressInstall.swf",flashvars,params,attributes, function(e){console.log(e)});

(function($){
    $.fn.extend({ 
        jslide: function(options) {

            var defaults = {  
                version: "9.0.0",
                params: {},
                attributes: {},
                flashvars:{ xmlAddr: options.xmlFile},
                imagesFolder: 'images',
                scaleImages: false,
                css: {},
                slideZIndex:1000

            };  
            
            var options = $.extend(defaults, options);  
            var obj = this;
            var testSuccess = function(e){
                if(! e.success){
                    $.ajax({
                            type: "GET",
	                    url: options.xmlFile,
	                    dataType: "xml",
	                    success: function(xml) {
	                        var count = 0;
                            $(xml).find('image').each(function(){

                                obj.append('<img style="margin-top:17px;margin-left:3px;z-index:'+ (options.slideZIndex - 2) +'" id="'+ obj.attr('id')+'-slide-'+ count +'" '+ ( typeof(options.scaleImages) == 'boolean' && options.scaleImages ? ' width="'+ options.width +'" height="'+ options.height +'" ' : (typeof(options.scaleImages) == 'object' ? ' width="'+ options.scaleImages[0] +'" height="'+ options.scaleImages[1] +'" ' : '' ) ) +' src="' +$(this).find('addr').text() +'" />');
                                
                                $('#flash').cycle({ 
                                    fx: 'fade', 
                                    startingSlide: 1,  // start on the slide that was in the markup 
                                    timeout:  5000, 
                                    speed:    500
                                    //prev:    '#prev', 
                                    //next:    '#next', 
                                    //before:   onBefore,
                                    //after: onAfter 
                                }); 
                            });
                          
                            $.each(options.css, function(attr, value){
                               
                                obj.css(attr, value);
                            });
                            
                            
                            //call jslide callback
                            options.callback.call();
	                    }
                    });
                }
            }
            
            return this.each(function() {
                
                swfobject.embedSWF(options.swf, $(this).attr('id'), "1001", "517", options.version, "expressInstall.swf",options.flashvars,options.params,options.attributes, testSuccess);
                
            });
        }
    });
})(jQuery);



