/* Copyright 2011, Ben Lin (http://dreamerslab.com/)
* Licensed under the MIT License (LICENSE.txt).
*
* Version: 1.0.5
*
* Requires: jQuery 1.2.3+
*/
;(function(a){a.fn.extend({actual:function(b,k){var c,d,h,g,f,j,e,i;if(!this[b]){throw'$.actual => The jQuery method "'+b+'" you called does not exist';}h=a.extend({absolute:false,clone:false,includeMargin:undefined},k);d=this;if(h.clone===true){e=function(){d=d.filter(":first").clone().css({position:"absolute",top:-1000}).appendTo("body");};i=function(){d.remove();};}else{e=function(){c=d.parents().andSelf().filter(":hidden");g=h.absolute===true?{position:"absolute",visibility:"hidden",display:"block"}:{visibility:"hidden",display:"block"};f=[];c.each(function(){var m={},l;for(l in g){m[l]=this.style[l];this.style[l]=g[l];}f.push(m);});};i=function(){c.each(function(m){var n=f[m],l;for(l in g){this.style[l]=n[l];}});};}e();j=d[b](h.includeMargin);i();return j;}});})(jQuery);

/**
 * @author Alexander Farkas
 * v. 1.02
 */
(function($) {
	$.extend($.fx.step,{
	    backgroundPosition: function(fx) {
            if (fx.state === 0 && typeof fx.end == 'string') {
                var start = $.curCSS(fx.elem,'backgroundPosition');
                start = toArray(start);
                fx.start = [start[0],start[2]];
                var end = toArray(fx.end);
                fx.end = [end[0],end[2]];
                fx.unit = [end[1],end[3]];
			}
            var nowPosX = [];
            nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
            nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
            fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

           function toArray(strg){
               strg = strg.replace(/left|top/g,'0px');
               strg = strg.replace(/right|bottom/g,'100%');
               strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
               var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
               return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
           }
        }
	});
})(jQuery);



$(document).ready(function(){
	
	$("#cLoginWrap").stop().fadeTo(0,0).hide();
	//Fix Errors - http://www.learningjquery.com/2009/01/quick-tip-prevent-animation-queue-buildup/
	
	//Remove outline from links
	
	
////////////////////////////////////////////////slide btns
	$('.sl')
		.css( {backgroundPosition: "0px -18px"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(0px -34px)"}, {duration:500})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(0px -18px)"}, {duration:200, complete:function(){
				$(this).css({backgroundPosition: "0px -18px"})
			}})
		})
		
	$('.viewWork')
		.css( {backgroundPosition: "0px -7px"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(0px 0px)"}, {duration:500})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(0px -7px)"}, {duration:200, complete:function(){
				$(this).css({backgroundPosition: "0px -7px"})
			}})
		})


////////////////////////////////////////////////fade btns
	$('.fadeThis').append('<span class="hover"></span>').each(function () {
	  var $span = $('> span.hover', this).css('opacity', 0);
	


	  $(this).hover(function () {
			$span.stop().fadeTo(500, 1);
	  }, function () {
		  if ($(this).hasClass('active')){
		  } else{
			$span.stop().fadeTo(500, 0); 
		  }
	  });
	

$('.portBtns.active span').stop().fadeTo(500, 1);
	  
	});
	
	
	
	
/////////////////anchor slide
    $(".scroll").click(function (event) {
        //prevent the default action for the click event
        event.preventDefault();

        //get the full url - like mysitecom/index.htm#home
        var full_url = this.href;

        //split the url by # and get the anchor target name - home in mysitecom/index.htm#home
        var parts = full_url.split("#");
        var trgt = parts[1];

        //get the top offset of the target anchor
        var target_offset = $("#" + trgt).offset();
        var target_top = target_offset.top;

        //goto that anchor by setting the body scroll top to anchor top
        $('html, body').animate({ scrollTop: target_top }, 500);
    });
	
////////////////////////////////////////////////portfolio btns

	$('.portBtns').click(function(){
		$('.portBtns').removeClass('active');
		$(this).addClass('active');
		
		$(".portBtns:not('.active') span").each(function(){
			$(this).stop().fadeTo(500, 0);
		});	
			
	});

////////////////////////////////////////////////accordian	
//Set default open/close settings
$('.acc_container').hide(); //Hide/close all containers
$('.acc_trigger:first').addClass('active').next().show(); //Add "active" class to first trigger, then show/open the immediate next container

//On Click
$('.acc_trigger').click(function(){
	if( $(this).next().is(':hidden') ) { //If immediate next container is closed...
		$('.acc_trigger').removeClass('active').next().slideUp(); //Remove all .acc_trigger classes and slide up the immediate next container
		$(this).toggleClass('active').next().slideDown(); //Add .acc_trigger class to clicked trigger and slide down the immediate next container
	} else {
		$('.acc_container').slideUp();	
		$('.acc_trigger').removeClass('active');
	}	
	return false; //Prevent the browser jump to the link anchor
});

//////////////////////////////////price formatting
$(".priceWrap").each(function () {
    var newtarget = $(this);
    nodes = $(this).contents().clone(); // the clone is critical!
    nodes.each(function () {
        if (this.nodeType == 3) { // text
            var newhtml = "";
            var text = this.wholeText; // maybe "textContent" is better?
            for (var i = 0; i < text.length; i++) {
                if (text[i] === ",") newhtml += "<span class='priceBlank'>" + "," + "</span>";
                else if (text[i] === "$") newhtml += "<span class='priceBlank'>" + "$" + "</span>";
                else newhtml += "<span class='priceNumber'>" + text[i] + "</span>";	
            }
            newtarget.html($(newhtml));
        }
        else { // recursion FTW!
            $(this).html(wrap($(this)));
            newtarget.html($(this));
        }
		
    });

});



////////////////////////////////////////////////ticker
/*!
 * liScroll 1.0
 * Examples and documentation at: 
 * http://www.gcmingati.net/wordpress/wp-content/lab/jquery/newsticker/jq-liscroll/scrollanimate.html
 * 2007-2010 Gian Carlo Mingati
 * Version: 1.0.2 (30-MARCH-2009)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 * Requires:
 * jQuery v1.2.x or later
 * 
 */


jQuery.fn.liScroll = function(settings) {
		settings = jQuery.extend({
		travelocity: 0.07
		}, settings);		
		return this.each(function(){
				var $strip = jQuery(this);
				$strip.addClass("newsticker")
				var stripWidth = 0;
				var $mask = $strip.wrap("<div class='mask'></div>");					
				var containerWidth = $strip.parent().parent().width();	//a.k.a. 'mask' width 	
				$strip.find("li").each(function(i){
				stripWidth += jQuery(this, i).outerWidth(true); // thanks to Michael Haszprunar
				});
				$strip.width(stripWidth);			
				var totalTravel = stripWidth+containerWidth;
				var defTiming = totalTravel/settings.travelocity;	// thanks to Scott Waye		
				function scrollnews(spazio, tempo){
				$strip.animate({left: '-='+ spazio}, tempo, "linear", function(){$strip.css("left", containerWidth); scrollnews(totalTravel, defTiming);});
				}
				scrollnews(totalTravel, defTiming);				
				$strip.hover(function(){
				jQuery(this).stop();
				},
				function(){
				var offset = jQuery(this).offset();
				var residualSpace = offset.left + stripWidth;
				var residualTime = residualSpace/settings.travelocity;
				scrollnews(residualSpace, residualTime);
				});			
		});	
};



/////////////////////////////////////////////////tool tip
	$("#ticker01 li .con").hover(function() {
		$(".tickercontainer .mask").css("height", "130px");
		$(this).next("em").stop(true, true).animate({opacity: "show", top: "38"}, "slow");
	
	}, function() {
		$(".tickercontainer .mask").css("height", "33px");
		$(this).next("em").animate({opacity: "hide", top: "30"}, "fast");
	});
	

////////////////////////////////////////////////page peel
$("#pageflip").hover(function() { //On hover...
	$("#pageflip img , .msg_block").stop()
		.animate({ //Animate and expand the image and the msg_block (Width + height)
			width: '307px',
			height: '319px'
		}, 500);
	} , function() {
	$("#pageflip img").stop() //On hover out, go back to original size 50x52
		.animate({
			width: '50px',
			height: '52px'
		}, 220);
	$(".msg_block").stop() //On hover out, go back to original size 50x50
		.animate({
			width: '50px',
			height: '50px'
		}, 200); //Note this one retracts a bit faster (to prevent glitching in IE)
});



///////////////////////////////////////////////portfolio
	//Set Default State of each portfolio piece
	//$(".paging").show();
	$(".pagingPort a:first").addClass("active");
		
	//Get size of images, how many there are, then determin the size of the image reel.
	var imageWidthPort = $(".windowPort").width();
	var imageHeightPort = $(".windowPort").height();
	var imageSumPort = $(".image_reelPort img").size();
	var imageReelWidthPort = imageWidthPort //* imageSum;
	var imageReelHeightPort = imageHeightPort
	

	//Paging + Slider Function
	rotatePort = function(){	
		var triggerIDPort = $active.attr("rel") - 1; //Get number of times to slide
		var image_reelPositionPort = triggerIDPort * imageWidthPort; //Determines the distance the image reel needs to slide
		var image_reelPositionHPort = triggerIDPort * imageHeightPort;
		$(".pagingPort a").removeClass('active'); //Remove all active class
		$active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)
		
		//Slider Animation
		$(".image_reelPort").animate({ 
			left: -image_reelPositionPort
			//top: -image_reelPositionHPort
		}, 500 );
		
	}; 
	

	
	//On Click
	$(".pagingPort a").click(function() {	
		$active = $(this); //Activate the clicked paging
		//Reset Timer
		//clearInterval(play); //Stop the rotation
		rotatePort(); //Trigger rotation immediately
		//rotateSwitch(); // Resume rotation
		return false; //Prevent browser jump to link anchor
	});	

	$("#cLogin").hover(function(){
		$("#cLoginWrap").show();
		$("#cLoginWrap").stop().fadeTo(500,1);
		$(this).addClass("active");
	}, function(){
		//doNothing
	});
	
	$("#cLoginWrap").hover(function(){
		//do nothing
	}, function(){
		$(this).stop().fadeTo(500,0, function(){
			$("#cLogin").removeClass("active");
			$(this).hide();
		});
		
	});

$('#hImg').stop().fadeTo(1,0);

	  $('#galleryBox img').hover(function () {
		  	newimg = $(this).attr("rel");
			$('#hImg').attr("src", newimg).stop().fadeTo(500, 1);
	  }, function () {
			$('#hImg').attr("src", newimg).stop().fadeTo(500, 0);
		
	  });


});



////////////////ticker
window.twttr = window.twttr || {};

var processSummizeInternal = function (B) {
    var J = page.trendDescriptions[page.query];
    if (J) {
        $("#trend_info").hide();
        $("#trend_description span").text(_("%{trend} is a popular topic on Twitter right now.", {
            trend: J[0]
        }));
        $("#trend").text(_("%{trend}", {
            trend: J[0]
        }));
        $("#trend_description p").html(J[1]);
        $("#trend_description").show()
    } else {
        $("#trend_description").hide();
        $("#trend_info").show()
    }(J && J[1].length > 0) ? $(".trenddesc").show() : $(".trenddesc").hide();

};

$.fn.isSearchLink = function (A) {
    return this.each(function () {
        var B = $(this);
        B.click(function (C) {

            $("#trends_list li.active a").removeClass("active")
        })
    })
};


function loadTrendDescriptions() {
    $("#trends a").each(function () {
        var A = $(this);
        var C = A.parent().find("em");
        if (C.length) {
            var B = A.text();
            var D = C.text().replace(new RegExp(B.replace(/([^\w])/gi, "\\$1"), "gi"), "<strong>" + B + "</strong>");
            var E = A.attr("title").length ? A.attr("title") : A.attr("name");page.trendDescriptions[E] = [B, D]
        }
    })
}
$(document).ready(function () {

    page.trendDescriptions = {};
    loadTrendDescriptions();

});

window.twttr.bounds = window.twttr.bounds || {};
$.extend(twttr.bounds, {
    Bounds: function (b, d, c, a) {
        this.x = b;
        this.y = d;
        this.width = c;
        this.height = a
    }
});
$.extend(twttr.bounds.Bounds.prototype, {
    encloses: function (a, b) {
        return a > this.x && a < this.x + this.width && b > this.y && b < this.y + this.height
    },
    toString: function () {
        return "(" + this.x + "," + this.y + ") " + this.width + "x" + this.height
    }
});
(function (a) {
    a.fn.extend({
        bounds: function () {
            var c = this.eq(0);
            var b = c.offset();
            return new twttr.bounds.Bounds(b.left, b.top, c.outerWidth(), c.outerHeight())
        }
    })
})(jQuery); 

(function (A) {
    A.extend(window, {
        TrendTip: {
            parseIntDefault: function (B, D) {
                D = D || 0;
                var C = parseInt(B);
                return isNaN(C) ? D : C
            },
            clearBounds: function () {
                this.data("bounds", [])
            },
            addToBounds: function (B) {
                if (!this.data("bounds")) {
                    this.data("bounds", [])
                }
                this.data("bounds").push(B)
            },
            enclosing: function (B, D) {
                if (!this.data("bounds")) {
                    this.data("bounds", [])
                }
                var C = false;
                A.each(this.data("bounds"), function (F, E) {
                    if (E.encloses(B, D)) {
                        C = true
                    }
                });
                return C
            },
            clearScrollInterval: function () {
                clearInterval(this.data("interval"))
            },
            setScrollInterval: function (B) {
                if (this.data("interval")) {
                    this.clearScrollInterval()
                }
                this.data("interval", setInterval(B, 30))
            },
            duplicateContent: function (B) {
                var C = 0;
                B.children().each(function () {
                    C += A(this).outerWidth(true);
                    B.append(A(this).clone())
                });
                B.css({
                    zoom: 1,
                    width: (2 * C) + "px"
                });
                return C
            },
            initScroller: function () {
                var C = this;
                var E = this.duplicateContent(C);
                var B = TrendTip.parseIntDefault(C.css("left"), 0);
                var D = function () {
                    B = (B % E) - 1;
                    C.css({
                        left: B
                    })
                };
                C.bind("trendEnter", function () {
                    C.clearScrollInterval()
                }).bind("trendLeave", function () {
                    C.setScrollInterval(D)
                }).trigger("trendLeave")
            }
        }
    });
    A.extend(A.fn, {
        trendTip: function () {
            var B = false;
            var C = A(this);
            A.extend(C, TrendTip);
            C.initScroller();
            C.find("li a").each(function () {
                var D = A(this).closest("li");
                var E = {
                    mouseenter: function (G) {
                        var F = A(this);
                        A("#trends .inner").trigger("trendLeave");
                        if (C.oldCapturedTrend) {
                            C.oldCapturedTrend.trigger("trendLeave")
                        }
                        C.oldCapturedTrend = F;
                        C.addToBounds(F.bounds());
                        if (C.enclosing(G.pageX, G.pageY)) {
                            A("#trends .inner").trigger("trendEnter");
                            F.trigger("trendEnter");
                            var H = function (I) {
                                if (!C.enclosing(I.pageX, I.pageY)) {
                                    A("#trends .inner").trigger("trendLeave");
                                    F.trigger("trendLeave")
                                }
                            };
                            A(document).bind("mousemove", H);
                            F.bind("trendLeave", function (I) {
                                C.clearBounds();
                                A(document).unbind("mousemove", H)
                            })
                        }
                    },
                    trendenter: function () {
                        if (!C.hoveringTrend) {
                            var F = A(".trendtip");
                            var K = A(this).offset();
                            var J = Math.round(A(this).outerWidth() / 2);
                            var I = Math.round(F.outerWidth() / 2);
                            var H = D.find("a").text();
                            var G = D.find("em.description").html();
                            F.find(".trendtip-trend").html(H);
                            F.find(".trendtip-trend").attr("href", A(this).attr("href")).attr("name", H);
                            if (A.trim(G) != "") {
                                F.find(".trendtip-why").show();
                                F.find(".trendtip-desc").html(G)
                            } else {
                                F.find(".trendtip-why").hide()
                            }
                            B = setTimeout(function () {
                                clearTimeout(B);
                                D.find("a.search_link").addClass("active");
                                F.css({
                                    top: K.top + 35,
                                    left: K.left + J - I,
                                    position: "absolute",
                                    zIndex: 10000
                                });
                                F.fadeIn("fast", function () {
                                    C.hoveringTrend = true
                                });
                                C.addToBounds(F.bounds())
                            }, 400)
                        }
                    },
                    trendleave: function (G) {
                        clearTimeout(B);
                        A("#trends a.search_link").removeClass("active");
                        if (C.hoveringTrend) {
                            var F = A(".trendtip");
                            F.fadeOut("fast");
                            C.hoveringTrend = false
                        }
                    }
                };
                A(this).mouseenter(E.mouseenter).bind("trendEnter", E.trendenter).bind("trendLeave", E.trendleave)
            });
            return this
        }
    })
})(jQuery);


function FrontPage() {
    return $.extend(this, {
        $trends: $("#trends"),
        $trendTip: $(".trendtip:eq(0)")

    })
}


$.extend(FrontPage.prototype, {
	init: function () {
        this.initTrendHover();
    },
    initTrendHover: function () {
        this.hoveringTrend = false;
        var A = this;
        $("#trends ul").trendTip()
    }
});
(jQuery);




