jQuery(document).ready(function($) {
    
    $(".tweet").tweet({
      join_text: "auto",
      username: "gatewaysa",
      count: 3,
      auto_join_text_default: "we said,",
      auto_join_text_ed: "we",
      auto_join_text_ing: "we were",
      auto_join_text_reply: "we replied",
      auto_join_text_url: "we were checking out",
      loading_text: "loading tweets..."
    });
    

    $("img.a1, img.a2, img.a3, img.a4, img.a5").hover(
    function() {
        $(this).stop().animate({"opacity": "0"}, "slow");
    },
    function() {
        $(this).stop().animate({"opacity": "1"}, "slow");
    });


    $("#topnav li").prepend("<span></span>"); //Throws an empty span tag right before the a tag
    $("#topnav li").each(function() { //For each list item...
            var linkText = $(this).find("a").html(); //Find the text inside of the a tag
            $(this).find("span").show().html(linkText); //Add the text in the span tag
    });
    $("#topnav li").hover(function() {	//On hover...
            $(this).find("span").stop().animate({
                    marginTop: "-40" //Find the span tag and move it up 40 pixels
            }, 250);
    } , function() { //On hover out...
            $(this).find("span").stop().animate({
                    marginTop: "0" //Move the span back to its original state (0px)
            }, 250);
    });


   
    
})

$(function() {
    
    function runExpand(ul) {
        $(ul).closest('li').children('ul.expanda').fadeSliderToggle(400);
    }
    
    $('.plus').click(function() {
        runExpand(this); return false;
    }); // Get the click

    $(".plus").click(function () {
        $(this).children(".arrow").toggle();
            return false;
    });
    
    $('.expanda').fadeSliderToggle(400);// Close the expanda


    var availableTags = ["Eastern Cape", "Free State", "Gauteng", "KwaZulu-Natal", "Mpumalanga", "North West", "Northern Cape", "Western Cape"];
    var availableTags2 = ["Hillcrest", "Gillets", "Pinetown", "Durban", "Ballito", "Umchlanga", "Drummond", "Kloof", "Westville", "Amazimatoti", "Botha's Hill"];
    var availableTags3 = ["World Cup", "Arno Cartens", "Security Options", "Beyond Commerce", "Gatewaysa", "Fun In The Sun", "Earth Dance", "Botha's Hill"];
    $("#place").autocomplete({
            source: availableTags
    });
    $("#area").autocomplete({
            source: availableTags2
    });
    //$("#keyword").autocomplete({
    //        source: availableTags3
    //});


    $('input.clear').focus(function() {
        $(this).val('')
    });

});



var padNorm = "#ddd7d3";
var padOn = "#56514d";
var strokeNorm = "#b0b0b0"
var strokeOn = "#000"

$(function(){
	$("ul#numbers li").hover( function () {
		$(this).animate({backgroundColor:padOn, borderColor:strokeOn}, 300);
	},
	function () {
		$(this).animate({backgroundColor:padNorm, borderColor:strokeNorm}, 300);
                }
	);
});

// execute your scripts when the DOM is ready. this is a good habit
$(function() {
    // assign a click event to the exposed element, using normal jQuery coding
    $(".twa, #quoteHold").click(function() {
            // perform exposing for the clicked element
            $(this).expose();
    });
});

$(document).ready(function(){
    $('A[rel="_blank"]').each(function(){
        $(this).attr('target', '_blank');
    });
    $("#stars-wrapper1").stars({
        split: 2
    });
});

$(document).ready(function() {
	/* This is basic - uses default settings */
	$("a.group").fancybox({
		'transitionIn'	: 'elastic',
                'speedIn'       : '100',
		'transitionOut'	: 'elastic',
		'easingIn'      : 'easeOutBack',
		'easingOut'     : 'easeInBack',
                'overlayShow'	:  true
	});
});

$(document).ready(function(){
    $("#stars-wrapper1").stars({
        split: 2
    });
});


$(function() {
        $(".datepicker").datepicker();
});

$(function() {
        var $elem = $('body');

        $('#nav_up').fadeIn('slow');
        $('#nav_down').fadeIn('slow');

        $(window).bind('scrollstart', function(){
                $('#nav_up,#nav_down').stop().animate({'opacity':'0'});
        });
        $(window).bind('scrollstop', function(){
                $('#nav_up,#nav_down').stop().animate({'opacity':'1'});
        });

        $('#nav_down').click(
                function (e) {
                        $('html, body').animate({scrollTop: $elem.height()}, 1800);
                }
        );
        $('#nav_up').click(
                function (e) {
                        $('html, body').animate({scrollTop: '0px'}, 1500);
                }
        );
});
$(document).ready(function(){
    $("#clickMe").click(function () {
        $(".theSwappa ul").slideToggle()
    });
});

$(document).ready(function(){
    $('.tTip').betterTooltip({speed: 150, delay: 300});
});

$(document).ready(function() {
  $('.first a').smoothScroll({
    afterScroll: function() {
      /* location.hash = this.hash; */
    }
  });
});

$(document).ready(function(){
        //To switch directions up/down and left/right just place a "-" in front of the top/left attribute
        //Vertical Sliding
        $('.boxgrid.slidedown').hover(function(){
                $(".cover", this).stop().animate({top:'-260px'},{queue:false,duration:300});
        }, function() {
                $(".cover", this).stop().animate({top:'0px'},{queue:false,duration:300});
        });
        //Horizontal Sliding
        $('.boxgrid.slideright').hover(function(){
                $(".cover", this).stop().animate({left:'325px'},{queue:false,duration:300});
        }, function() {
                $(".cover", this).stop().animate({left:'0px'},{queue:false,duration:300});
        });
        //Diagnal Sliding
        $('.boxgrid.thecombo').hover(function(){
                $(".cover", this).stop().animate({top:'260px', left:'325px'},{queue:false,duration:300});
        }, function() {
                $(".cover", this).stop().animate({top:'0px', left:'0px'},{queue:false,duration:300});
        });
        //Partial Sliding (Only show some of background)
        $('.boxgrid.peek').hover(function(){
                $(".cover", this).stop().animate({top:'90px'},{queue:false,duration:160});
        }, function() {
                $(".cover", this).stop().animate({top:'0px'},{queue:false,duration:160});
        });
        //Full Caption Sliding (Hidden to Visible)
        $('.boxgrid.captionfull').hover(function(){
                $(".cover", this).stop().animate({top:'90px'},{queue:false,duration:160});
        }, function() {
                $(".cover", this).stop().animate({top:'177px'},{queue:false,duration:160});
        });
        //Caption Sliding (Partially Hidden to Visible)
        $('.boxgrid.caption').hover(function(){
                $(".cover", this).stop().animate({top:'80px'},{queue:false,duration:160});
        }, function() {
                $(".cover", this).stop().animate({top:'100px'},{queue:false,duration:160});
        });
});

/* social network url inserting */
$(document).ready(function() {
    var pathname = window.location.href;
    $("a#stumbleeeer").attr("href", "http://www.stumbleupon.com/submit?url="+pathname+"")
    $("a#deliscioussss").attr("href", "http://del.icio.us/post?v=2&url="+pathname+"")
    $("a#digggg").attr("href", "http://digg.com/submit?phase=2&url="+pathname+"")
    $(".faceLikeBut").attr("href", pathname)

});
/* social network url inserting */


/* Fade box */


(function($) {

    $.fn.innerfade = function(options) {
        return this.each(function() {
            $.innerfade(this, options);
        });
    };

    $.innerfade = function(container, options) {
        var settings = {
            'animationtype':    'fade',
            'speed':            'normal',
            'type':             'sequence',
            'timeout':          2000,
            'containerheight':  '55',
            'runningclass':     'innerfade',
            'children':         null
        };
        if (options)
            $.extend(settings, options);
        if (settings.children === null)
            var elements = $(container).children();
        else
            var elements = $(container).children(settings.children);
        if (elements.length > 1) {
            $(container).css('position', 'relative').css('height', '145px').addClass(settings.runningclass);
            for (var i = 0; i < elements.length; i++) {
                $(elements[i]).css('z-index', String(elements.length-i)).css('position', 'absolute').hide();
            };
            if (settings.type == "sequence") {
                setTimeout(function() {
                    $.innerfade.next(elements, settings, 1, 0);
                }, settings.timeout);
                $(elements[0]).show();
            } else if (settings.type == "random") {
            		var last = Math.floor ( Math.random () * ( elements.length ) );
                setTimeout(function() {
                    do {
												current = Math.floor ( Math.random ( ) * ( elements.length ) );
										} while (last == current );
										$.innerfade.next(elements, settings, current, last);
                }, settings.timeout);
                $(elements[last]).show();
						} else if ( settings.type == 'random_start' ) {
								settings.type = 'sequence';
								var current = Math.floor ( Math.random () * ( elements.length ) );
								setTimeout(function(){
									$.innerfade.next(elements, settings, (current + 1) %  elements.length, current);
								}, settings.timeout);
								$(elements[current]).show();
						}	else {
							alert('Innerfade-Type must either be \'sequence\', \'random\' or \'random_start\'');
						}
				}
    };

    $.innerfade.next = function(elements, settings, current, last) {
        if (settings.animationtype == 'slide') {
            $(elements[last]).slideUp(settings.speed);
            $(elements[current]).slideDown(settings.speed);
        } else if (settings.animationtype == 'fade') {
            $(elements[last]).fadeOut(settings.speed);
            $(elements[current]).fadeIn(settings.speed, function() {
							removeFilter($(this)[0]);
						});
        } else
            alert('Innerfade-animationtype must either be \'slide\' or \'fade\'');
        if (settings.type == "sequence") {
            if ((current + 1) < elements.length) {
                current = current + 1;
                last = current - 1;
            } else {
                current = 0;
                last = elements.length - 1;
            }
        } else if (settings.type == "random") {
            last = current;
            while (current == last)
                current = Math.floor(Math.random() * elements.length);
        } else
            alert('Innerfade-Type must either be \'sequence\', \'random\' or \'random_start\'');
        setTimeout((function() {
            $.innerfade.next(elements, settings, current, last);
        }), settings.timeout);
    };

})(jQuery);

// **** remove Opacity-Filter in ie ****
function removeFilter(element) {
	if(element.style.removeAttribute){
		element.style.removeAttribute('filter');
	}
}

            $(document).ready(
                function(){
                        $('.fadeMe').innerfade({
                                speed: 'slow',
                                timeout: '5000',
                                containerheight: 'auto',
                                type: 'random'
                        });
                }
            );
