$(document).ready(function(){
    
    /* === Carousels === */
	
    $(function(){
        
        var home_slider = $('#items ul').bxSlider({
            controls: false,
            mode: 'fade',
            speed: 800,
            pause: 5000,
            auto: true
        });
        
        $('#go-prev').click(function(){
            home_slider.goToPreviousSlide();
            return false;
        });
        
        $('#go-next').click(function(){
            home_slider.goToNextSlide();
            return false;
        });
        
        var gallery_slider = $('#gallery').bxSlider({
            controls: false,
            speed: 1600,
            pager: true
        });
        
        $('#ggo-prev').click(function(){
            gallery_slider.goToPreviousSlide();
            return false;
        });
        
        $('#ggo-next').click(function(){
            gallery_slider.goToNextSlide();
            return false;
        });
        
        $('#gallery_list .bx-pager').appendTo('li#pager');
        
        if($('#gallery li').length == 3){
            $('#ggo-prev, #ggo-next').parent().remove();
            $('.bx-pager').remove();
        }
                
    });
    
    
    /* === Corners === */
    
    $('#menu li a').corner('10px');
    $('.news_list .np, .prev a, .next a, #ggo-prev, #ggo-next').corner('5px');
    $('#carousel #items ul li, .slidey li img').corner('top 5px');
    $('.slidey-prev, .nav .prev').corner('tl 5px');
    $('.slidey-next, .nav .next, .newsletter fieldset .btn').corner('br 5px');
    $('.spot h2, .spot_photo').corner('br 5px');
    $('.date_selector .nav, .newsletter fieldset, .sh, .ic, .ib, .tc').corner('tl br 5px');
    $('#footer, .main_photo img').corner('bottom 5px;');
    $('#gallery_list img').uncorner();
    
    $('.date_selector a').live('click', function(){
        $('.nav').corner('tl br 5px');
        $('.prev').corner('tl 5px');
        $('.next').corner('br 5px');
    });
    
    

    
    /* === First child === */
    
    $('.news_list li:first-child, #sidebar .sidebar_box:first-child').addClass('first-child');
    
    
    /* === Lightbox === */
    
    $("a[rel]='fancybox'").fancybox({
        'titleShow'     : true,
        'speedIn'		: 400,
        'speedOut'		: 400,
        //showNavArrows   : false,
        enableKeyboardNav: false
    });    
    
    
    /* === Clear values === */
    
    $('input[type=text], input[type=password], textarea').each(function(){			
	    var d_value = this.value;			    
	    $(this).focus(function(){
	        if(this.value == d_value){
	            this.value = '';
	        }
	    });	
				    
	    $(this).blur(function(){
	    	if(this.value == ''){
	            this.value = d_value;
	        }
	    });		    
	});
    
    
    /* === Opera fixes === */
    
    if( $.browser.opera ){
        
        $('.spot_photo, .news_list, .main_photo').find('img').each(function(){
            $(this).replaceWith('<div class="ip" style="height:'+$(this).height()+'px'+'; width:'+$(this).width()+'px'+'; background:url('+ $(this).attr('src') +') no-repeat 0 0;" />');
        });
        
        $('.main_photo .ip').corner('bottom 5px;');
        $('.news_list .ip').corner('5px');
        $('.spot_photo .ip').corner('br 5px');
        
    }
    
});

$(window).load(function(){
   $('#main').find('iframe[src="http://www.connectcapital.se/iframe"]').wrap('<div id="frame" />').addClass('iframe');
});

function addEvent(obj, evType, fn){ 
	if (obj.addEventListener){ 
		obj.addEventListener(evType, fn, true); 
		return true; 
	}else if (obj.attachEvent){ 
		var r = obj.attachEvent("on"+evType, fn); 
		return r; 
	}else{ 
		return false; 
	} 
}

function hideFocusBorders(){
var theahrefs = document.getElementsByTagName("a");
	if (!theahrefs){return;}
		for(var x=0;x!=theahrefs.length;x++){
		theahrefs[x].onfocus = function stopLinkFocus(){this.hideFocus=true;};
	}
}

addEvent(window, 'load', hideFocusBorders);
