$(document).ready(function() {
	
	/* Fix for IE */
    	if (jQuery.browser.msie && jQuery.browser.version >= 9) {
		 jQuery.support.noCloneEvent = true;
		}
	/* End fix for IE */
	
	/* Load scripts */
		if ($('.tweet').length) {
				$(".tweet").tweet({
					join_text: "auto",
					username: "nixdanish",
					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..."
				  });
			}
		if ($('#flickrImages').length) {
				$('#flickrImages').jflickrfeed({
					limit: 4,
					qstrings: {
						id: '90933305@N00'
					},
					itemTemplate: '<a href="{{image_b}}"><img src="{{image_s}}" alt="{{title}}" /></a>'
				});
			}
		if ($('ul.sf-menu').length) {
				$('ul.sf-menu').superfish({
					hoverClass:    'sfHover',
					autoArrows:    false
				});
			}
		if ($('ul#myRoundabout').length) {
				var interval;
				$('ul#myRoundabout').roundabout({
					btnNext: '#next',
					btnPrev: '#previous',
					startingChild: 2,
					duration: 1000,
					easing: 'easeInOutBack'
				})
				.hover(
				function() {
				// oh no, it's the cops!
				clearInterval(interval);
				},
				function() {
				// false alarm: PARTY!
				interval = startAutoPlay();
				}
				);
				// let's get this party started
				interval = startAutoPlay();
				};
				function startAutoPlay() {
				return setInterval(function() {
				$('ul#myRoundabout').roundabout_animateToNextChild();
				}, 5000); 
				
			}
		if ($('#carousel').length) {
				$(function(){
					$("#carousel").carousel({
						loop:true,
						pagination: true,
						autoSlide:true,
						delayAutoSlide:5000,
						autoSlideInterval:5000,
						animSpeed:1000,
						slideEasing:'easeInOutBack'
					});
				});
			}
		if ($('#carousel-small').length) {
				$(function(){
					$("#carousel-small").carousel({
							dispItems: 3
						});
				});
			}
		if ($("a[rel^='prettyPhoto']").length) {
				$("a[rel^='prettyPhoto']").prettyPhoto({animationSpeed:'slow',theme:'light_rounded',slideshow:2000, autoplay_slideshow: true});
			}
	
		if ($("#slogan").length) {
				$("#slogan ul").rotate();
			}
			
	/* End load scripts*/
	
	// Form
	$('input[type="text"],textarea').focus(function() {
		if (this.value == this.defaultValue){ 
			this.value = '';
		}
		if(this.value != this.defaultValue){
			this.select();
		}
	});
	$('form.inner input[type="text"], form.inner textarea').blur(function() {
		if ($.trim(this.value) == ''){
			this.value = (this.defaultValue ? this.defaultValue : '');
		}
	});
	// End Form
	
	/* Hover */
	$('.hover').hover(function(){
			$(this).stop().addClass ('active')
		}, function(){
				$(this).stop().removeClass('active')
			})
	/* End hover */
	
	/* Image Caption Animate */
	$('.img-caption').hover(function(){
			$(this).find('span').animate({'bottom':-2}, 600, 'easeInOutSine')
		}, function(){
				$(this).find('span').stop(true, true).animate({'bottom':-100}, 600, 'easeInOutSine')
			})
	/* End image Caption Animate */
	
	/* Portfolio hover */
	
	$(".img-rollover").prepend("<span></span>")
	$(".img-rollover span").stop().animate({opacity:0},0)
		
	$(".img-rollover").hover(function(){
		$(this).find("span").stop().animate({opacity:0.65},300)
	}, function(){
		$(this).find("span").stop().animate({opacity:0},100)
	});
	
	/* End portfolio hover */
});

$(document).ready(function() {

	//Tooltips

	$(".tip_trigger").hover(function(){

		tip = $(this).find('.tip');

		tip.show(); //Show tooltip

	}, function() {

		tip.hide(); //Hide tooltip		  

	}).mousemove(function(e) {

		var mousex = e.pageX + 20; //Get X coodrinates

		var mousey = e.pageY + 20; //Get Y coordinates

		var tipWidth = tip.width(); //Find width of tooltip

		var tipHeight = tip.height(); //Find height of tooltip

		

		//Distance of element from the right edge of viewport

		var tipVisX = $(window).width() - (mousex + tipWidth);

		//Distance of element from the bottom of viewport

		var tipVisY = $(window).height() - (mousey + tipHeight);

		  

		if ( tipVisX < 20 ) { //If tooltip exceeds the X coordinate of viewport

			mousex = e.pageX - tipWidth - 20;

		} if ( tipVisY < 20 ) { //If tooltip exceeds the Y coordinate of viewport

			mousey = e.pageY - tipHeight - 20;

		} 

		tip.css({  top: mousey, left: mousex });

	});

});

