function createCookie(name,value,days){if(days){var date=new Date();date.setTime(date.getTime()+(days*24*60*60*1000));var expires="; expires="+date.toGMTString();}
else{var expires="";}
document.cookie=name+"="+value+expires+"; path=/";}
function readCookie(name){var nameEQ=name+"=";var ca=document.cookie.split(';');for(var i=0;i<ca.length;i++){var c=ca[i];while(c.charAt(0)===' '){c=c.substring(1,c.length);}
if(c.indexOf(nameEQ)==0)return c.substring(nameEQ.length,c.length);}
return null;}
function eraseCookie(name){createCookie(name,"",-1);}
var changeFontSize = function(size) {
    jQuery('body').css('font-size', size+'px');
    if (size == 10) {
        eraseCookie('se_font_size');
    } else {
        createCookie('se_font_size', size, 180);
    }
    return true;
}

function accordionCorners() {
    if (jQuery('#sidebar-left .block-accordion:eq(0) h3').length > 1) {
        if ( jQuery('#sidebar-left .block-accordion:eq(0) h3:last').next('ul').is(':hidden') == true ) {
            jQuery('#sidebar-left .block-accordion:eq(0) h3:last').corner('bl');
        } else {
            if (jQuery('#sidebar-left .block-accordion:eq(0) h3').next('ul').length == 0) {
                jQuery('#sidebar-left .block-accordion:eq(0) h3:last').corner('bl');
            } else {
                jQuery('#sidebar-left .block-accordion:eq(0) h3:last').uncorner();
            }
        }
    }
    if (jQuery('#sidebar-left .block-accordion:eq(0) .sub-navigation ul').length > 0) {
        jQuery('#sidebar-left .block-accordion:eq(0) .sub-navigation ul:last').corner('bl');

    }
}
function showImageDesc(el) {
    var elHeight = el.innerHeight();
    var elWidth = el.innerWidth();
    var thumb = el.parent('li');
    var el_offset = thumb.offset();
    var windowHeight = jQuery(window).height();
    var windowWidth = jQuery(window).width();
    var el_offsetTop = Math.floor( el_offset.top ) - $(document).scrollTop();
    var el_offsetLeft = Math.floor( el_offset.left ) - $(document).scrollLeft() - Math.floor((windowWidth - 960)/2 );
    var thumbWidth = thumb.width();
    var thumbHeight = thumb.height();
    if ( (elHeight + el_offsetTop) > windowHeight ) {
        posy = -(windowHeight - (thumbHeight + el_offsetTop)-10);
    } else {
        posy = -elHeight+thumbHeight;
    }
    if ( (elWidth + el_offsetLeft + thumbWidth) > 960 ) {
        posx = thumbWidth + 10;
    } else {
        var th_padding = parseInt( thumb.css('padding-right').replace('px', '') );
        posx = -10-elWidth + th_padding;
    }
    el.css({bottom: posy+'px', right: posx+'px'});
    el.fadeIn('500');
}
var zIndex = 1000;
jQuery(function() {
    jQuery('#sidebar-right .sidebar-search form, #sidebar-right .sidebar-search ol').css('display','none');
    jQuery('#sidebar-left .block-accordion:eq(0) h3+ul:gt(0), #sidebar-left .block-accordion:eq(1) h3+ul:gt(0), #sidebar-left .block-accordion:eq(2) h3+ul:gt(0)').css('display', 'none');
    jQuery('#sidebar-left .block-accordion:eq(0) h3, #sidebar-left .block-accordion:eq(1) h3,#sidebar-left .block-accordion:eq(2) h3').click(function(){
        if (jQuery(this).next('ul').is(':visible')) {
            jQuery(this).removeClass('active').next('ul').slideUp('slow');
        } else {
            jQuery(this).parent().find('ul:visible').slideUp('slow');
            jQuery(this).parent().find('h3.active').removeClass('active');
            jQuery(this).addClass('active').next('ul').slideDown('slow');
        }
        accordionCorners();
    });
    accordionCorners();
    jQuery('#sidebar-left .block-accordion h3+ul:visible').prev('h3').addClass('active');

    //jQuery('#sidebar-left .twitter-feed').wrapInner('<div class="inner" />');
	
	 // insert classes for border radius effect in IE
	 jQuery("#menu-main-menu li a").addClass("br-topright br-bottomleft");
	 jQuery(".submenu-widget #menu-main-menu-1").addClass("br-topright br-bottomleft");
	 
	 

    jQuery.support.borderRadius = false;
    jQuery.each(['BorderRadius','MozBorderRadius','WebkitBorderRadius'], function() {
        if(document.body.style[this] !== undefined) jQuery.support.borderRadius = true;
        return (!jQuery.support.borderRadius);
    });

    if ( jQuery.support.borderRadius == false ) {
        jQuery('.br-all, .twitter-feed div.inner, #twitter-home .twitter-feed').corner('all');
        jQuery('.br-bottom').corner('bottom');
        jQuery('.br-top').corner('top');
        jQuery('.br-topleft').corner('tl');
        jQuery('.br-topright, .block h3, .block-accordion h3:first-child').not('.block-accordion div div h3:first-child').corner('tr');
        jQuery('.br-bottomright').corner('br');
        jQuery('.br-bottomleft').corner('bl');
        
        jQuery('#signup-toggle').corner('cc:#fff bottom');
        jQuery('#wrapper').corner('cc:#EDF7FC top');
        jQuery('#wrapper').corner('bottom');
    }

    if (jQuery('#slider-items').length) {
        jQuery('#slider-items').cycle({
            fx:     'scrollHorz',
            speed:   300,
            timeout: 0
        });
        jQuery('#slider-controls a').hover(function() {
            jQuery('#slider-controls .current').removeClass('current');
            jQuery(this).addClass('current');
            var tabNr =  parseInt( jQuery(this).attr('id').replace('slider-tab-', '') - 1 );
            jQuery('#slider-items').cycle(tabNr);
            return false;
        });
        
        var max = jQuery('#slider-controls li').eq(0).height();
        var max_item = 0;
        if (jQuery('#slider-controls li').eq(1).height() > max ) {
            max = jQuery('#slider-controls li').eq(1).height();
            max_item = 1;        
        }
        if (jQuery('#slider-controls li').eq(2).height() > max ) {
            max = jQuery('#slider-controls li').eq(2).height();
            max_item = 2;                
        }
        if (jQuery('#slider-controls li').eq(3).height() > max ) {
            max = jQuery('#slider-controls li').eq(3).height();
            max_item = 3;        
        }
        jQuery('#slider-controls li').eq(max_item).addClass('tab-wide');
        //jQuery('#slider-controls a').height(jQuery('#slider-controls').height()-22);
    }
    
    jQuery('#bookingform').css('display','none');
    jQuery('#btn-event-book').click(function(){
        jQuery('#bookingform').show();
    });
    jQuery('#content .google-btn a').click(function(){
		jQuery('#content .google-btn').css('display','none');
		jQuery('#content .google-btn-hide').css('display','inline');
		jQuery(this).addClass('hide');
		jQuery(this).addClass('active');
        jQuery('#map').slideDown('3000');
        return false;
    });
	jQuery('#content .google-btn-hide a').click(function(){
		jQuery('#content .google-btn-hide').css('display','none');
		jQuery('#content .google-btn').css('display','inline');
        jQuery('#map').slideUp('3000');
        return false;
    });
    jQuery('#btn-sign-in').click(function(){
        var elSignup = jQuery('#signup');

        if (elSignup.is(':hidden')) {
            elSignup.slideDown('3000');
            jQuery(this).text('Close sign in');
        } else {
            elSignup.slideUp('1000');
            jQuery(this).text('Sign in');
        }
        return false;
    });
    //Cufon.replace('#bottom-about .hTitle, #bottom-links .hTitle, #bottom-social .hTitle, #home-txt h2, #home-txt .subtitle, #latest-post h2, #content h1, #content h2, #posts .comments-count span, .small-blocks .title', {fontFamily: 'HelveticaNeue'});

    if (jQuery('#browse').length) {
        var height1 = jQuery('#browse-industry ul').height();
        var height2 = jQuery('#browse-area ul').height();
        if (height1 < height2) {
            jQuery('#browse-industry ul').height( jQuery('#browse-area ul').height() );
        } else {
            jQuery('#browse-area ul').height(jQuery('#browse-industry ul').height() );
        }
    }
    
    // videos    
    jQuery("a[rel^='prettyPhoto']").prettyPhoto({theme:'light_square'});

    jQuery('#gallery li .image-thumb').hover(
        function() {
            zIndex = $(this).parent().parent().css('z-index');
            $(this).parent().parent().css('z-index', 2000);
            showImageDesc($(this).parent().next().next('.image-desc'));
        },
        function() {
            $(this).parent().parent().css('z-index', zIndex);
            $(this).parent().next().next('.image-desc').fadeOut('300');
        }
    );

    /*font size*/
    if (readCookie('se_font_size')) {
        changeFontSize( parseInt( readCookie('se_font_size') ) );
    }
    jQuery('#font-size-1').click(function() {changeFontSize('12');return false;});
    jQuery('#font-size-2').click(function() {changeFontSize('14');return false;});
    jQuery('#font-size-0').click(function() {changeFontSize('10');return false;});
    jQuery('.business-lifecycle input[type=text], .business-lifecycle input[type=password]').addClass('text');
    jQuery('.business-lifecycle input[type=submit]').addClass('submit').val('').parent().addClass('clearfix');
    jQuery('#sidebar-right .sidebar-search h3').click(function(){
        if (jQuery(this).hasClass('switch')) {
            jQuery(this).removeClass('switch');
            jQuery(this).next('form').slideUp('500');
            jQuery(this).next('ol').slideUp('500');
        } else {
            jQuery(this).addClass('switch');
            jQuery(this).next('form').slideDown('500');
            jQuery(this).next('ol').slideDown('500');
        }
    });
	
	
	jQuery('#sidebar-right .sidebar-search-start h3').addClass('switch');
    jQuery('#sidebar-right .sidebar-search-start h3').next('form').slideDown('500');
    jQuery('#sidebar-right .sidebar-search-start h3').next('ol').slideDown('500');

    var th_height = jQuery('#twitter-home').outerHeight(true);
    var hp2_height = jQuery('#home-page-2').outerHeight(true);
    /*jQuery('#home-page-2 .home-sidebar').css({'padding-bottom': th_height+10, 'min-height': hp2_height-th_height+20 });*/
    //jQuery('#menu-contact').addClass("purple-menu br-topright br-bottomleft");
	if(document.getElementById("menu-contact")){
		document.getElementById("menu-contact").setAttribute("class", "purple-menu br-topright br-bottomleft");
	}
	jQuery('#menu-contact').removeClass("menu");
	
	/*$(".twitter-feed .inner").tweet({
      avatar_size: 0,
      count: 1,
      username: "_SEWM",
      loading_text: "searching twitter..."
    });	*/
	
});

var geo;
var map;

if (typeof GUnload == 'undefined') {
    GUnload = function(){};
}	
	
function mapStart(title, address)
{
	if(GBrowserIsCompatible())  
	{
		map = new GMap2(document.getElementById("map"),{size: new GSize(481,320) , mapTypes: [G_NORMAL_MAP,G_SATELLITE_MAP,G_HYBRID_MAP]});
	    map.setCenter(new GLatLng(52.409077,-1.525416), 15);
		
		// kontrolki mapy
		map.addControl(new GLargeMapControl());
		var typyMapy = map.getMapTypes();    
		typyMapy[0].getName= function() {return "map";}
		typyMapy[1].getName = function() {return "Satelite";}
		typyMapy[2].getName = function() {return "Hybrid";}
		map.addControl(new GMapTypeControl());
		map.addControl(new GOverviewMapControl()); 
		map.addControl(new GScaleControl());
		
	    geo = new GClientGeocoder();

		geo.getLatLng(address,function(point)
		{
			if (!point)
			{
				alert("Sorry, cannot find " + address);
			}
			else
			{
				map.setCenter(point, 15);				
				var marker = new GMarker(point,{title: address});
				map.addOverlay(marker);
				//marker.openInfoWindowHtml('<strong>' + title + '</strong><br />' + address);
				marker.closeInfoWindow();
				GEvent.addListener(marker, "click", function() { 															 
					marker.openInfoWindowHtml('<strong>' + title + '</strong><br />' + address);
				});
			}
		});
	}
}

