$(document).ready(function() {

    // superfish can be called for every page
    $('ul.sf-menu').superfish({
        autoArrows: false,
        dropShadows: false
    });
	
	// Add corners to images using jquery cornerz
    tl.ImageCorners.init();


// Add corners to images used in modules
    tl.ModuleCorners.init();
	
// Initialize corners
    tl.Corners.init();
	
    $('#ctl02_ctl01_TXTQuery').keypress(function(e) 
    {
       if (e.keyCode == 13) 
       {
           tl.Search.submit();
           e.preventDefault();
       }
    });	
});

function SearchBtnSubmit()
{
    tl.Search.submit();
}




if (!TL) { var TL = {}; }
if (!TL.components) { TL.components = {}; }

	var tl = TL.components ;

TL.components.ModuleCorners = function() {

	return {
		init: function() {
			$('.rc-module').each(function(){
				if ( $(this).is('a') ) {
					if ($('img', this).length == 0 ) return ;
					$('img', this).css('padding', '0');
					var w = $('img', this).width();
					var h = $('img', this).height();
				} else {
					$(this).css('padding', '0');
					var w = $(this).width();
					var h = $(this).height();					
				}
				var container = $('<div class="holder-module"></div>').width(w).height(h) ;
				$(this).wrap( container );
			});
			
			$('.rc-module-bottom').each(function(){
				if ( $(this).is('a') ) {
					var w = $('img', this).width();
					var h = $('img', this).height();
				} else {
					var w = $(this).width();
					var h = $(this).height();					
				}
				var container = $('<div class="holder-module-bottom"></div>').width(200).height(h) ;
				$(this).wrap( container );
			});
			
			$('.holder-module').cornerz({radius:15, background: '#FFFFFF', fixIE:false}) ;
			$('.holder-module-bottom').cornerz({radius:15, background: '#F7F8F8', corners:'bl br'}) ;
		}
		
	}
	
}();

TL.components.ImageCorners = function() {
    var _bgSmall = 'rgb(237,237,237)';
    var _bgMedium = 'rgb(226,239,237)';
    var _bgLarge = 'rgb(255,255,255)';
    var _bgProfile = 'rgb(237,237,237)';
    return {
        init: function() {
            $('.rc-small').each(function() {

                if ($('img', this).length == 0) return;
                var w = $('img', this).width();
                var h = $('img', this).height();

                var container = $('<div class="holder-small"></div>').width(w).height(h);
                $(this).wrap(container);
            });

            $('.rc-medium').each(function() {
                if ($('img', this).length == 0) return;
                var w = $('img', this).width();
                var h = $('img', this).height();

                var container = $('<div class="holder-medium"></div>').width(w).height(h);
                $(this).wrap(container);
            });

            $('.rc-large').each(function() {

                if ($('img', this).length == 0) return;
                var w = $('img', this).width();
                var h = $('img', this).height();

                var container = $('<div class="holder-large"></div>').width(w).height(h);
                $(this).wrap(container);
            });

            $('.rc-feature').each(function() {

                if ($('img', this).length == 0) return;
                $('img', this).css('padding', '0');

                var w = $('img', this).width();
                var h = $('img', this).height();

                var container = $('<div class="holder-feature"></div>').width(w).height(h);
                $(this).wrap(container);
            });

            $('.rc-caption-large').each(function() {

                var w = $(this).width();
                var h = $(this).height();

                if ($(this).parent().is('a')) {
                    var color = $(this).parent().parent().parent().css('background-color');
                    var container = $('<div class="holder-caption-large"></div>').width(w).height(h).css('background-color', color);
                    $(this).parent().wrap(container);
                } else {
                    var color = $(this).parent().parent().css('background-color');
                    var container = $('<div class="holder-caption-large"></div>').width(w).height(h).css('background-color', color);
                    $(this).wrap(container);
                }
            });

            $('.rc-caption-small').each(function() {
                var w = $(this).width();
                var h = $(this).height();

                if ($(this).parent().is('a')) {
                    var color = $(this).parent().parent().parent().css('background-color');
                    var container = $('<div class="holder-caption-small"></div>').width(w).height(h).css('background-color', color);
                    $(this).parent().wrap(container);
                } else {
                    var color = $(this).parent().parent().css('background-color');
                    var container = $('<div class="holder-caption-small"></div>').width(w).height(h).css('background-color', color);
                    $(this).wrap(container);
                }

            });

            $('.rc-profile').each(function() {
                var w = $(this).width();
                var h = $(this).height();

                var container = $('<div class="holder-profile"></div>').width(w).height(h);
                $(this).wrap(container);
            });

            $('.holder-profile').cornerz({ radius: 15, background: _bgProfile });
            $('.holder-small').cornerz({ radius: 15, background: _bgSmall });
            $('.holder-medium').cornerz({ radius: 15, background: _bgMedium });
            $('.holder-feature').cornerz({ radius: 15, background: _bgSmall });

            $('.holder-large').cornerz({ radius: 15, background: _bgLarge, corners: 'tl tr' });
            $('.holder-caption-large').each(function() {
                $(this).cornerz({ radius: 20, background: $(this).css('background-color') });
            });
            $('.holder-caption-small').each(function() {
                if ($(this).next().is('.small-text')) {
                    $(this).cornerz({ radius: 20, background: $(this).css('background-color'), corners: 'tl tr' });
                } else {
                    // remove the bottom padding so the bottom corners are displayed properly
                    $(this).css('padding', '0');
                    // Round all corners if small image has no caption text
                    $(this).cornerz({ radius: 20, background: $(this).css('background-color') });
                }
            });
            $('.holder-caption-youtube').each(function() {
                $(this).cornerz({ radius: 20, background: $(this).css('background-color') });
            });
        }
} // end return
    } ();


TL.components.Corners = function() {
	return {
		init: function() {
			
			/** 
			* Initialize corners from the inside most elements
			* and work outwards to resolve temporarily bottom artifacts in IE6
			*/
			
			$('.form-message').cornerz({radius:15, background: '#F7F8F8'}) ;
			
			$('.cameras h2').cornerz({radius:8, background: '#FFF'}) ;
			
			$('.cameras .details .scroll-container').cornerz({radius:8, background: '#dedede'}) ;
			$('.cameras .details h2').cornerz({radius:8, background: '#dedede'}) ;
			$('.cameras .details').cornerz({radius:15, background: '#FFF'}) ;
			$('.cameras').cornerz({radius:15, background: '#ededed'}) ;
			
			$('#login-search-box li.bg').cornerz({radius:3, background: '#FFFFFF' }) ;
			$('.call-to-action').cornerz({ radius: 15, background: '#F7F8F8' });
			$('.call-to-action-ol').cornerz({ radius: 15, background: '#FFFFFF' });
			$('.ol-list-op').cornerz({ radius: 5, background: '#FFFFFF' });
			$('.ol-list-op2').cornerz({ radius: 5, background: '#FFFFFF' });
			
			$('.index-title-module').cornerz({ radius: 20, background: '#F7F8F8' });
			
			$('.feature-format-link').cornerz({ radius: 10, background: '#F7F8F8' });
			$('.feature-format-link h2').cornerz({ radius: 5, background: '#EDEDED' });
			$('.medium-format-link').cornerz({ radius: 10, background: '#F7F8F8' });
			$('.small-format-link').cornerz({ radius: 10, background: '#F7F8F8' });
			$('.external-links h2').cornerz({ radius: 5, background: '#ededed' });
			$('.external-links').cornerz({ radius: 15, background: '#F7F8F8' });
			
			
			$('.caption .text').cornerz({ radius: 25, corners: "tl, tr, br", background: '#F7F8F8' });
			$('.page-module-rss-list').cornerz({ radius: 15, background: '#EDEDED' });
			$('.callout-large').cornerz({ radius: 15, background: '#EDEDED' });
			
			// When class is applied directly to p tag in content editor
			$('p.inline-callout').each(function(){
				$(this).removeClass('inline-callout');
				$(this).wrap('<div class="inline-callout"></div>') ;
			});
			$('.inline-callout').cornerz({ radius: 15, background: '#EDEDED' });
			$('.consult-inline-callout').cornerz({ radius: 15, background: '#EDEDED' });
			
			
			$('.externalLinks h2').cornerz({ radius: 5, background: '#EDEDED' });
			$('.callout-large h2, .table-wrapper-wide h2, .table-wrapper-mid h2').cornerz({ radius: 5, background: '#FFFFFF' });
			$('.subsidiaryLinks h2').cornerz({ radius: 5, background: '#F7F8F8' });

			$('.footer h2').cornerz({ radius: 8, background: '#EDEDED' });
			
			$('.person').cornerz({radius:15, background:'#EDEDED'});
			$('.alertFilterBox').cornerz({radius:15, background:'#FFF'});
			$('.alertListGrey').cornerz({radius:10, background:'#FFF'});
			
			$('.inner-gray-box').cornerz({radius:15, background:'#FFF'});
			$('.trip-planner-tips').cornerz({radius:15, background:'#edf5f4'});
			
			$('.tab-help-middle-grey').cornerz({radius:5, background:'#FFF'});
			
			
			$('.job .thumb').cornerz({ radius: 15, background: '#FFF'});
			$('.jobs-online .featured').cornerz({ radius: 15, background: '#E2EFED' });
			$('.jobs-online h2').cornerz({ radius: 5, background: '#E2EFED' });
			
			
			$('.how-to-apply h2:first').cornerz({ radius: 5, background: '#ededed' });
			$('.how-to-apply .callout').cornerz({ radius: 15, background: '#ededed' });	
			$('.jobs-online, .how-to-apply').cornerz({ radius: 15, background: '#F7F8F8' });
			
			$('.road-details .status-box .status, .road-details .status-box .schedule').cornerz({ radius: 5, background: '#fff' });
			
			$('.related-docs h2.bg').cornerz({radius:7, background: '#F7F8F8', corners:"tr tl"}) ;
			$('.small-promo h2.bg, .large-promo h2.bg, .popularTopics h2.bg, .related-items h2.bg, .external-links-small h2.bg, .module-recent-posts h2.bg, .module-blog-archives h2.bg').cornerz({radius:7, background: '#F7F8F8', corners:"tr tl"}) ;
			
			$('#content .page-not-found .white-bg').cornerz({radius:15, background:'#E2EFED'}) ;
			
			$('#content .pr').cornerz({radius:15, background:'#EDEDED'}) ;
			$('#content .pr h2').cornerz({radius:8, background:'#fff'}) ;
			
			$('.find-stop').cornerz({radius:10, background: '#edf5f4'}) ;
			$('.road-details').cornerz({radius:15, background: '#ededed'}) ;
			
			$('.sitemap .section').cornerz({radius:15, background: '#F7F8F8'}) ;
			$('#content .page').cornerz({ radius: 15, background: '#F7F8F8' });
			
		}
	}
}();

TL.components.Search = function() {
    return {
        submit: function() {
            var tzOffset = -new Date().getTimezoneOffset();
            var searchString = $.trim(document.getElementById('ctl02_ctl01_TXTQuery').value);

            location.href = 'http://www.translink.ca/site-info/search-results.aspx?&amp;lcid=9&amp;q=' + encodeURIComponent(searchString) + '&amp;t=' + tzOffset;
        },
        submitDocLib: function() {
            var form = document.forms[0];
            form.action = "http://www.translink.ca/site-info/search-results.aspx";
            form.method = "post";
            var el = document.createElement("input");
            el.type = "hidden";
            el.name = "docLib";
            el.value = "1";

            form.appendChild(el);
            form.submit();
        }
    }
} ();




	





