// JavaScript Document
/*
 * $Id: jquery.scrollable.js,v 1.4 2009/03/30 18:56:13 florent Exp $
*/
/*
 * jquery.scrollable 1.0.2. Put your HTML scroll.
 * 
 * Copyright (c) 2009 Tero Piirainen
 * http://flowplayer.org/tools/scrollable.html
 *
 * Dual licensed under MIT and GPL 2+ licenses
 * http://www.opensource.org/licenses
 *
 * Launch  : March 2008
 * Version : 1.0.2 - Tue Feb 24 2009 10:52:08 GMT-0000 (GMT+00:00)
 */
/*
 * Copyright (c) 2009 IBM Corporation
 * Owner: Corporate Webmaster (NUS_N_NIWWW)
*/

/* This code was changed to fit the Smart Planet requirements. */
/* 08.07.2009 by RedWorks.Digital Bratislava                   */

/* REDWORKS BEGIN */

function getDeeplinkValue( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

function trackSAFibmFPV( trackID )
{
	//alert(trackID);
	
	sa_flash(trackID);
	ibmCreateFlashPageviewTag(trackID);
}

function trackSAFcmML( trackID, url_str )
{
	
	var url_array = url_str.split("#");
	var anchor_str = (url_array[1] == undefined) ? "" : "#"+url_array[1];
	var link_array = url_array[0].split("?");
	var separator_str = (link_array[1] == undefined) ? "?" : "&";
	
	url_str = url_array[0]+separator_str+"cm_re=smartplanet-_-flash-_-"+trackID+anchor_str;
	
	//alert(url_str+"\n\n\n\n"+trackID+"\n\n"+getPageID());
	
	sa_flash(trackID);
	cmCreateManualLinkClickTag(url_str, trackID, getPageID());
}

/* REDWORKS END */



(function(D) {
    function B(J, H, F, E) {
        var I = J[H];
        if (D.isFunction(I)) {
            try {
                return I.call(F, E)
            } catch(G) {
                if (J.alert) {
                    alert("Error calling scrollable." + H + ": " + G)
                } else {
                    throw G
                }
                return false
            }
        }
        return true
    }
    var C = null;
    function A(O, M) {
        var R = this;
        if (!C) {
            C = R
        }
        var E = !M.vertical;
        var G = D(M.items, O);
        var K = 0;
        var P = D(M.navi).eq(0);
        var H = O.siblings(M.prev).eq(0);
        var J = O.siblings(M.next).eq(0);
				if (M.prevPage == ".masthead_prevPage"){
        	var I = O.children(M.items).children().children(M.prevPage);
        	var N = O.children(M.items).children().children(M.nextPage);
				}
				else{
					var I = O.siblings(M.prevPage).eq(0);
        	var N = O.siblings(M.nextPage).eq(0);
				}
        D.extend(R, {
            getVersion: function() {
                return [1, 0, 1]
            },
            getIndex: function() {
                return K
            },
            getConf: function() {
                return M
            },
            getSize: function() {
                return R.getItems().size()
            },
            getPageAmount: function() {
                return Math.ceil(this.getSize() / M.size)
            },
            getPageIndex: function() {
                return Math.ceil(K / M.size)
            },
            getRoot: function() {
                return O
            },
            getItemWrap: function() {
                return G
            },
            getItems: function() {
                return G.children()
            },
            seekTo: function(T, Z, U) {
                Z = Z || M.speed;
                if (D.isFunction(Z)) {
                    U = Z;
                    Z = M.speed
                }
                if (T < 0) {
                    T = 0
                }
                if (T > R.getSize() - M.size) {
                    return R
                }
                var V = R.getItems().eq(T);
                if (!V.length) {
                    return R
                }
                if (B(M, "onBeforeSeek", R, T) === false) {
                    return R
                }
                if (E) {
                    var Y = -(V.outerWidth(true) * T);
                    G.animate({
                        left: Y
                    },
                    Z, M.easing, U ?
                    function() {
                        U.call(R)
                    }: null)
                } else {
                    var X = -(V.outerHeight(true) * T);
                    G.animate({
                        top: X
                    },
                    Z, M.easing, U ?
                    function() {
                        U.call(R)
                    }: null)
                }
                if (P.length) {
                    var S = M.activeClass;
                    var W = Math.ceil(T / M.size);
                    W = Math.min(W, P.children().length - 1);
                    P.children().removeClass(S).eq(W).addClass(S)
                }
                if (T === 0) {
                    H.add(I).addClass(M.disabledClass)
                } else {
                    H.add(I).removeClass(M.disabledClass)
                }
                if (T >= R.getSize() - M.size) {
                    if (M.items != ".masthead_items"){
											J.add(N).addClass(M.disabledClass)
										}
                } else {
                    J.add(N).removeClass(M.disabledClass)
                }
                C = R;
                K = T;
                B(M, "onSeek", R, T);
                return R
            },
            move: function(U, T, S) {
                var V = K + U;
                if (M.loop && V > (R.getSize() - M.size)) {
                    V = 0
                }
                return this.seekTo(V, T, S)
            },
            next: function(T, S) {
                return this.move(1, T, S)
            },
            prev: function(T, S) {
                return this.move( - 1, T, S)
            },
            movePage: function(U, T, S) {
                return this.move(M.size * U, T, S)
            },
            setPage: function(W, X, U) {
                var T = M.size;
                var S = T * W;
                var V = S + T >= this.getSize();
                if (V) {
                    S = this.getSize() - M.size
                }
                return this.seekTo(S, X, U)
            },
            prevPage: function(T, S) {
                return this.setPage(this.getPageIndex() - 1, T, S)
            },
            nextPage: function(T, S) {
								if (M.items != ".masthead_items"){
									return this.setPage(this.getPageIndex() + 1, T, S)
								}
								else{
									if (this.getPageIndex() >= R.getSize() - M.size) {
										return this.setPage(0, T, S)
									} 
									else { return this.setPage(this.getPageIndex() + 1, T, S)}
								}
            },
            begin: function(T, S) {
                return this.seekTo(0, T, S)
            },
            end: function(T, S) {
                return this.seekTo(this.getSize() - M.size, T, S)
            },
            reload: function() {
                return Q()
            },
            click: function(T, W, U) {
                var V = R.getItems().eq(T);
                var S = M.activeClass;
                if (!V.hasClass(S) && (T >= 0 || T < this.getSize())) {
                    R.getItems().removeClass(S);
                    V.addClass(S);
                    var Y = Math.floor(M.size / 2);
                    var X = T - Y;
                    if (X > R.getSize() - M.size) {
                       X--;
                    }
                    if (X !== T) {
                        if (M.items != ".items"){
													return this.seekTo(X, W, U)
												}
                    }
                }
                return R
            }
        });
				// BOTTOM SCROLL TO PAGE - BEGIN
					if (M.items == ".items" && typeof M.firstpage == "number" && M.firstpage >= 0){
						R.setPage(M.firstpage);
					}
        // BOTTOM SCROLL TO PAGE - END
				// DISABLE MOUSEWHEEL FOR MASTHEAD - BEGIN
        if (M.items != ".masthead_items"){
					if (D.isFunction(D.fn.mousewheel)) {
							O.bind("mousewheel.scrollable", function(T, U) {
									var S = D.browser.opera ? 1 : -1;
									R.move(U > 0 ? S: -S, 50);
									return false
							})
					}
				}
				// DISABLE MOUSEWHEEL FOR MASTHEAD - END
        H.addClass(M.disabledClass).click(function() {
						R.prev()
        });
        J.click(function() {					 
            R.next()
        });
        N.click(function() {
            R.nextPage();
        });
        I.addClass(M.disabledClass).click(function() {
            R.prevPage()
        });
        if (M.keyboard) {
            D(function(S) {
                var T = C;
                if (!T) {
                    return
                }
                if (E && (S.keyCode == 37 || S.keyCode == 39)) {
                    T.move(S.keyCode == 37 ? -1 : 1);
                    return S.preventDefault()
                }
                if (!E && (S.keyCode == 38 || S.keyCode == 40)) {
                    T.move(S.keyCode == 38 ? -1 : 1);
                    return S.preventDefault()
                }
                return true
            })
				}
        function Q() {
            P.each(function() {
                var V = D(this);
                if (V.is(":empty") || V.data("me") == R) {
                    V.empty();
                    V.data("me", R);
                    for (var T = 0; T < R.getPageAmount(); T++) {
                        var U = D("<" + M.naviItem + "/>").attr("href", T).click(function(X) {
                            var W = D(this);
                            W.parent().children().removeClass(M.activeClass);
                            W.addClass(M.activeClass);
                            R.setPage(W.attr("href"));
                            return X.preventDefault()
                        });
												if (typeof M.firstpage == "number" && M.firstpage >= 0) {navisel = M.firstpage}
												else {navisel = 0}
                        if (T === navisel) {
                            U.addClass(M.activeClass)
                        }
                        V.append(U)
                    }
                } else {
                    var S = V.children();
                    S.each(function(W) {
                        var X = D(this);
                        X.attr("href", W);
                        if (W === 0) {
                            X.addClass(M.activeClass)
                        }
                        X.click(function() {
                            V.find("." + M.activeClass).removeClass(M.activeClass);
                            X.addClass(M.activeClass);
                            R.setPage(X.attr("href"))
                        })
                    })
                }
            });
            if (M.clickable) {
                R.getItems().each(function(T, S) {
                    var U = D(this);
                    if (!U.data("set")) {
                        U.bind("click.scrollable", function() {
                            R.click(T)
                        });
                        U.data("set", true)
                    }
                })
            }
            if (M.hoverClass) {
                R.getItems().hover(function() {
                    D(this).addClass(M.hoverClass)
                },
                function() {
                    D(this).removeClass(M.hoverClass)
                })
            }
            return R
        }
				// ADD THE SCRIPT FOR THE deepLinkID HERE
					if (M.items == ".masthead_items" && getDeeplinkValue("deepLinkID") != ""){
						myNum = O.children(M.items).children().index(O.children(M.items).children("#"+getDeeplinkValue("deepLinkID")));
						if (myNum != -1) {R.movePage(myNum);}
					}
        	//
				// ADD THE SCRIPT FOR THE deepLinkID HERE
				
				Q();
        var F = null;
        function L() {
            F = setInterval(function() {
                R.next()
            },
            M.interval)
        }
        if (M.interval > 0) {
            O.hover(function() {
                clearInterval(F)
            },
            function() {
                L()
            });
            L()
        }
    }
    D.prototype.scrollable = function(E) {
        var F = this.eq(0).data("scrollable");
        if (F) {
            return F
        }
        var G = {
            size: 5,
            vertical: false,
            clickable: true,
            loop: false,
            interval: 0,
						firstpage: E,
            speed: 400,
            keyboard: true,
            activeClass: "active",
            disabledClass: "disabled",
            hoverClass: null,
            easing: "swing",
            items: ".items",
            prev: ".prev",
            next: ".next",
            prevPage: ".prevPage",
            nextPage: ".nextPage",
            navi: ".navi",
            naviItem: "a",
            onBeforeSeek: null,
            onSeek: null,
            alert: true
        };
        D.extend(G, E);
        this.each(function() {
            var H = new A(D(this), G);
            D(this).data("scrollable", H)
        });
        return this
    }
		D.prototype.scrollable_masthead = function(E) {
        var F = this.eq(typeof E == "number" ? E: 0).data("masthead_scrollable");
        if (F) {
            return F
        }
        var G = {
            size: 1,
            vertical: false,
            clickable: true,
            loop: false,
            interval: 0,
            speed: 400,
            keyboard: true,
            activeClass: "active",
            disabledClass: "disabled",
            hoverClass: null,
            easing: "swing",
            items: ".masthead_items",
            prev: ".prev",
            next: ".next",
            prevPage: ".masthead_prevPage",
            nextPage: ".masthead_nextPage",
            navi: ".masthead_navi",
            naviItem: "a",
            onBeforeSeek: null,
            onSeek: null,
            alert: true
        };
        D.extend(G, E);
        this.each(function() {
            var H = new A(D(this), G);
            D(this).data("masthead_scrollable", H)
        });
        return this
    }
})(jQuery);
/*
 * jquery.mousewheel.js
*/
/*
 Copyright (c) 2006 Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 * Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers.
 * Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix.
 *
 * jQueryLastChangedDate: 2007-12-20 09:02:08 -0600 (Thu, 20 Dec 2007) jQuery
 * jQueryRev: 4265 jQuery
 *
 * Version: 3.0
 * 
 * Requires: jQuery 1.2.2+
 */
/*
 * Copyright (c) 2009 IBM Corporation
 * Owner: Corporate Webmaster (NUS_N_NIWWW)
*/
(function(A) {
    A.event.special.mousewheel = {
        setup: function() {
            var B = A.event.special.mousewheel.handler;
            if (A.browser.mozilla) {
                A(this).bind("mousemove.mousewheel", function(C) {
                    A.data(this, "mwcursorposdata", {
                        pageX: C.pageX,
                        pageY: C.pageY,
                        clientX: C.clientX,
                        clientY: C.clientY
                    })
                })
            }
            if (this.addEventListener) {
                this.addEventListener((A.browser.mozilla ? "DOMMouseScroll": "mousewheel"), B, false)
            } else {
                this.onmousewheel = B
            }
        },
        teardown: function() {
            var B = A.event.special.mousewheel.handler;
            A(this).unbind("mousemove.mousewheel");
            if (this.removeEventListener) {
                this.removeEventListener((A.browser.mozilla ? "DOMMouseScroll": "mousewheel"), B, false)
            } else {
                this.onmousewheel = function() {}
            }
            A.removeData(this, "mwcursorposdata")
        },
        handler: function(D) {
            var B = Array.prototype.slice.call(arguments, 1);
            D = A.event.fix(D || window.event);
            A.extend(D, A.data(this, "mwcursorposdata") || {});
            var E = 0,
            C = true;
            if (D.wheelDelta) {
                E = D.wheelDelta / 120
            }
            if (D.detail) {
                E = -D.detail / 3
            }
            if (A.browser.opera) {
                E = -D.wheelDelta
            }
            D.data = D.data || {};
            D.type = "mousewheel";
            B.unshift(E);
            B.unshift(D);
            return A.event.handle.apply(this, B)
        }
    };
    A.fn.extend({
				mousewheel: function(B) {
						return B ? this.bind("mousewheel", B) : this.trigger("mousewheel")
				},
				unmousewheel: function(B) {
						return this.unbind("mousewheel", B)
				}
    })
})(jQuery);