var prevTitle = null;

jQuery(document).ready(function () {
    jQuery('#mainImageSlide').cycle({
        speed:   600,
        fx: 'none',
        startingSlide: 0,
        timeout: fistTimeout,
        before: function() {
            //added selected class to navigation li on change
            var title = this.title;
            //this happens if user hoovers the same LI
            if (title == prevTitle){
                return false;
            }
            jQuery("li[title="+title+"]").addClass("selected");
            jQuery("li[title="+prevTitle+"]").removeClass("selected");
            prevTitle = title;

            data = this.lang.split("|");
            if (data.length == 2){
                loadFlash(data[1],this.title,this.id,this.getAttribute('rel'));
            }
            
        },
        timeoutFn: function(currElement, nextElement, opts, isForward) {       
            //setf timeout for flash player to the preferd timeout set in DB
            if (nextElement.lang != undefined){
                var timeout = nextElement.lang.split("|")[0];
                if (timeout > 0){
                    return timeout*1000;
                }else{
                    return 4500;
                }
            }else if (nextElement == 1 && typeof fistTimeout != undefined){
                return fistTimeout;
            }else{
                return 4500;
            }
            
        }
    });
});
	

jQuery(document).ready(function(){   
    // Create the tooltips only on document load
    // Notice the use of the each() method to acquire access to each elements attributes
    jQuery('a.popup').each(function(){
        jQuery(this).qtip({
            content: jQuery("div#"+this.lang).html(), // Use the tooltip attribute of the element for the content
            style: 'dark', // Give it a crea mstyle to make it stand out
            position: {
                corner: {
                    tooltip: "topRight", // Use the corner...
                    target: "bottomLeft" // ...and opposite corner
				 
                },
                adjust: {
                    x: 30,
                    y: -30
                }
            },
            style: {
                tip: true // Give it a speech bubble tip with automatic corner detection
            }
        });
    });

    jQuery('#slideNav a').click(function(){
        return false;
    });
});

function loadFlash(flashSrc,title,divId, URL){
    var so = new SWFObject(flashSrc, title,"930", "320", "8");
    so.addVariable("clickTAG", URL);
    so.addParam("wmode", "transparent");
    so.write(divId);
}