var hostname = window.location.hostname,
links = document.getElementsByTagName('a'),
pattern = /^https?:\/\/(www.)?/i;
 
for(var i=0, len = links.length; i<len; i++) {
  if(pattern.test(links[i].href) && links[i].href.toLowerCase().indexOf(hostname) == -1){
    links[i].target = "_blank";
    links[i].className += ' external';
  }
}

(function($){
	
	$(document).ready(function() {

		$("ul.thumbs a.thumb").fancybox({
			titleShow: true,
			'transitionIn'	:	'elastic',
			'transitionOut'	:	'elastic',
			'speedIn'		:	600, 
			'speedOut'		:	200, 
			'overlayShow'	:	false
		});
		
	});
	
	// carousel
	 function mycarousel_initCallback(carousel){
        carousel.clip.hover(function(){
            carousel.stopAuto();
        }, function(){
            carousel.startAuto();
        });
    };
	
    $('#banners').jcarousel({
        auto: 3,
        scroll: 1,
        wrap: 'last',
        animation: 2000,
		initCallback: mycarousel_initCallback
    });
    
    //tootltip //@author: mihai vaduva //@copyright: mihai.vaduva@spotonearth.com
    $('body').append('<div id="tooltip"></div>');
    $('#tooltip').hide();
    var $tooltip = $('#tooltip');
    $('ul#offers a').each(function(){
        var $this = $(this), $title = this.title;
        
        $this.hover(function(){
            this.title = '';
            $tooltip.text($title).show();
        }, function(){
            this.title = $title;
            $tooltip.text('').hide();
        });
        
        $this.mousemove(function(e){
            $tooltip.css({
                top: e.pageY - 10,
                left: e.pageX + 20
            });
        });
    });
    
    
    $("ul.twitter-posts li:even").addClass('even');
    $("ul.twitter-posts li:odd").addClass('odd');
    $("ul.twitter-posts li:last-child").addClass('last-child');
    $("ul.menu li:last-child").addClass('last-child');
    
    $('#gform_1 #field_1_1').addClass('col-1');
    $('#gform_1 #field_1_3').addClass('col-1');
    $('#gform_1 #field_1_7').addClass('col-1');
    $('#gform_1 #field_1_2').addClass('col-1');
    
    $('#gform_1 #field_1_4').addClass('g-section-el');
    $('#gform_1 #field_1_6').addClass('g-section-el');
    $('#gform_1 #field_1_5').addClass('g-section-el');
    
    $('#gform_1 .g-section-el').wrapAll('<div class="g-section col-1" />');
    $('#gform_1 .col-1').wrapAll('<div class="col-left" />');
    
    
    $("#slideshow").after('<span id="prev" title="Previous">Prev</span><span id="next" title="Next">Next</span>');
    
    $('#slideshow').cycle({
        timeout: 5000,
        prev: '#prev',
        next: '#next'
    });
    $('#next').click(function(){
        $('#slideshow').cycle('resume');
    });
    
    $('textarea, input:text').bind('focus click', function(){
        if (this.value == this.defaultValue) {
            this.value = '';
        }
    }).bind('blur', function(){
        if (this.value == '') {
            this.value = this.defaultValue;
        }
    });
    
    //accordion
    jQuery('div.accordion').accordion({
        header: '.section-head',
        autoheight: false
    });
    
})(jQuery);
