/*!
 * Copyright (c) 2010 Liberty Concepts
 * http://www.libertyconcepts.com
 * All right reserved *
 * @version 1.5
 * @description Put all jQuery code into engine.structure.allBrowsers
 * engine.structure.ie is reserved only for IE lte 8.0 browsers
 */

var engine = {
	structure: {
		init : function(){
			if (!jQuery.support.opacity) { //Change this to jQuery.browser.msie when IE9 will be released.
				this.ie();
				this.allBrowsers();
			}
			else {
				this.allBrowsers();
			}
		},
		ie : function(){
		//HERE GOES jQUERY FOR IE BROWSERS ONLY!
		},
		allBrowsers : function(){
			$j('.main .rtCol img.imgRt, .main .rtCol img[style*=right], .main .rtCol img[align=right]').wrap('<div class="imgRtDiv"/>');
			$j('.main .rtCol img.imgLeft, .main .rtCol img[style*=left], .main .rtCol img[align=left]').wrap('<div class="imgLeftDiv"/>');

			// rotating footer quotes
			$j(".quotes").cycle({
				fx: 'fade' ,
				timeout: 8000,
				cleartypeNoBg: true,
		 		pager:  '.controls' ,
				pagerAnchorBuilder:function(idx,slide){
					return '<li><a href="#">'+ parseFloat(idx+1) +'</a></li>';
				}
			});

			// slide show
			$j(".slides").cycle({
				fx: 'scrollHorz' ,
				timeout: 8000,
				cleartypeNoBg: true,
				pause: true,
				next: '.next',
       	prev: '.prev'
			});

			//twitter
			if ($j('#twitterFeed').length) {
					$j('#twitterFeed').twitterSearch({
					term: 'from%3AEricGreitens', //insert twitter feed ID
					bird: false,
					avatar: false,
					colorExterior: '#efeeec',
					colorInterior: '#5e5e5e',
					pause:   true,
					timeout: 5000
				});
			}

			if ($j("ul.sf-menu").length) {
				$j("ul.sf-menu").supersubs({
						minWidth:15, //minimum width (in em units) of sub-menus
						maxWidth:30, //maximum width (in em units) of sub-menus
						extraWidth:1 //extra width can ensure lines don't sometimes turn over due to slight rounding differences and font-family
				}).superfish({delay:0}).find('ul').bgIframe({
						opacity:false
				});
			}
		}
	}
}

$j(function(){
    engine.structure.init();
    plugins.externalLinks(); //When specified, browser will open external links in new tab (or window)


    function isLength(input, length){
       if($j(input).val().length > 700){
           return true;
       }
           return false;
    };

    //limit number of chrs textarea
    $j('#msg textarea').keyup(function(){
        if(isLength(this, 700)){
        alert('You have exceeded the 700 character limit. Please shorten your message.');
       };
   });
   
   $j('input.submit_tag').click(function(){
        var limit = isLength('#msg textarea', 700);
       if(limit){
        alert('You have exceeded the 700 character limit. Please shorten your message.');
        return false;
       } else {
        $j(this).submit();
       }
   });

});
