/*
 * 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(){
			Cufon.replace("#menu > li > a, #current-date, .footer-nav-top-level-item, #footer-2-links, #sidebar-most-shared-content-tabs, #homepage-latest-update-tabs, #conference-latest-news", {fontFamily: 'DIN 1451 Std'}); // IDs and Classes to replace with Cufon
			$j('#footer-1 ul li:first-child').addClass('footer-nav-top-level-item'); 
			// adds the footer-nav-top-level-item class to the first item in #footer-1
			$j('#menu > li > ul > li').css({'border':'0'});
			$j('#menu > li > ul > li a').css({'font':'12px Arial, Vedana'});			
 
			
			$j("#footer-1 a").hover(function(){
                $j(this).stop().animate({
                    "left":5,
                    "color":"#F1F1F2"
                },100)
            }, function(){
                $j(this).stop().animate({
                    "left":0,
                    "color":"#A8D4D3"
                },200)
            });
			// animates the position of the link
			
			/*///////////////// MOST SHARED CONTENT BLOCK /////////////////*/
			$j(".tab-content").hide(); //Hide all content
			$j("ul#sidebar-most-shared-content-tabs li:first").addClass("active").show(); //Activate first tab
			$j(".tab-content:first").show(); //Show first tab content
			
			//On Click Event
			$j("ul#sidebar-most-shared-content-tabs li").click(function() {
			
			$j("ul#sidebar-most-shared-content-tabs li").removeClass("active"); //Remove any "active" class
			$j(this).addClass("active"); //Add "active" class to selected tab
			$j(".tab-content").hide(); //Hide all tab content
			Cufon.refresh();
			
			var activeTab = $j(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
			$j(activeTab).fadeIn(); //Fade in the active ID content
			return false;
			});
			
			// CJN Cycler
			$j('#CJN-items').multipleElementsCycle({	
			elementContainer: '#CJN-items-list',
			nextElement: 'a.cjn-up',
			prevElement: 'a.cjn-down',
			speed: 400,
			showCount: 3,
			overrideStart:0,
			vertical: true,
			indexup : 1,
			indexdown : '',
			counterHolder: 'span.item-counter'
			});

	
			//Viewpoints Cycler
			$j('#homepage-viewpoints').multipleElementsCycle({	
			elementContainer: '#homepage-viewpoints-list',
			nextElement: 'a.viewpoints-up',
			prevElement: 'a.viewpoints-down',
			speed: 400,
			showCount: 3,
			overrideStart:0,
			vertical: true,
			indexup : 1,
			indexdown : '',
			counterHolder: 'span.item-counter2'
			});
			
			// DATE PICKER
			Date.firstDayOfWeek = 0;
			Date.format = 'mm/dd/yyyy';
			$j('.search-date-start, .search-date-end').datePicker({startDate:'01/01/1990'});
			
			// HOMEPAGE FORUM CATEGORY CSS EDITS
			$j("#homepage-interactive-community :nth-child(8)").addClass("forum-topic-bottom-row");
			$j("#homepage-interactive-community :nth-child(9)").addClass("forum-topic-bottom-row");

			/*///////////////// HOMEPAGE LATEST UPDATES BLOCK /////////////*/
			$j(".HP-latest-updates-tab-content").hide(); //Hide all content
			$j("ul#homepage-latest-update-tabs li:first").addClass("active-update").show(); //Activate first tab
			$j(".HP-latest-updates-tab-content:first").show(); //Show first tab content
			
			//On Click Event
			$j("ul#homepage-latest-update-tabs li").click(function() {
			
			$j("ul#homepage-latest-update-tabs li").removeClass("active-update"); //Remove any "active" class
			$j(this).addClass("active-update"); //Add "active" class to selected tab
			$j(".HP-latest-updates-tab-content").hide(); //Hide all tab content
			Cufon.refresh();
			
			var activeTab = $j(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
			$j(activeTab).fadeIn(); //Fade in the active ID content
			return false;
			});
			
 			/*//////////////// HOMEPAGE LATEST NEWS BLOCK /////////////////*/
			$j(".hp-news-tab-content").hide(); //Hide all content
			$j("ul#hp-latest-news-tab li:first").addClass("active").show(); //Activate first tab
			$j(".hp-news-tab-content:first").show(); //Show first tab content
			
			//On Click Event
			$j("ul#hp-latest-news-tab li").click(function() {
			
			$j("ul#hp-latest-news-tab li").removeClass("active"); //Remove any "active" class
			$j(this).addClass("active"); //Add "active" class to selected tab
			$j(".hp-news-tab-content").hide(); //Hide all tab content
			Cufon.refresh();
			
			var activeTab = $j(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
			$j(activeTab).fadeIn(); //Fade in the active ID content
			return false;
			});
			
			$j('#all-topics-list').listnav();
			
			$j("#sidebar-most-shared-content-tabs li:last-child").css({"border-right":"0"});
			$j("#homepage-ICJ-thumbs div:last-child").css({"margin-right":"0"});
			$j("#trending-searches ul li:last-child").css({"margin-right":"0"});
			// Last Child CSS fixes
			
			// START MENU
			$j('ul.sf-menu li ul li a').hover(function() {
				$j(this).css({'color':'#ccc', 'border':'0'});
			 },function() {
				$j(this).css({'color':'#fff', 'border':'0'});
			});
		        // END MENU
		        
			

			
            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(){
	//function font resize
	  $j('a.sm, div.sm').click(function(){
          $j('#bodyContent-wide, #bodyContent').stop().animate({fontSize: '12px'}, 300 );
	  });
	            
	   $j('a.med, div.med').click(function(){
          $j('#bodyContent-wide, #bodyContent').stop().animate({fontSize: '15px'}, 300 );
	   });
	            
	   $j('a.large, div.large').click(function(){
           $j('#bodyContent-wide, #bodyContent').stop().animate({fontSize: '20px'}, 300 );	  
 });

});

$j(function(){
    $j.fn.formLabels() //optional: {excludeElts: 'elts to exclude'} see the source for more options
    engine.structure.init();
    plugins.pageTools.init("#contentHere"); //change #contentHere for the selector of block with the main page content
    plugins.externalLinks(); //When specified, browser will open external links in new tab (or window)
	$j(".fading-list").fadingSiblings(); // add the fading-list class to any container that should have the fading siblings effect
});


//hide font size homepage
$j(function(){
var URL = window.location;
    if(URL == 'http://www.thecrimereport.org/'){
       $j('#font-size-tools').hide();
    }
});


$j(function(){
	//show rundom entries	
	var $li = $j("div#sidebar-topic .fading-list li").hide();
			var len = $li.length;
			var loop = 20;
			var randomnumber;
			var itmsLen;

			for(i = 0; i < loop; i++){
				itmsLen = $j("div#sidebar-topic .fading-list li").not(":hidden").length;
				randomnumber = Math.floor(Math.random()*len);
				
				if ($j($li.eq(randomnumber).is(":hidden")) && itmsLen < 10) {
					$li.eq(randomnumber).show();					
				} 
				  
		   }
});


//fake url
$j(function(){
	var parent = $j('div.blog_entry');
	var name = $j('b.author');

	$j('b.author').each(function(){
		var txt = $j(this).text();
		 parent = $j(this).parent().parent();
		
		
		switch(txt){
			case 'By Robin L. Barton':			
			$j('a.url', parent).attr('href', '/viewpoints/robin-barton');
			break;
			
			case 'By Mansfield Frazier':
			$j('a.url', parent).attr('href', '/viewpoints/mansfield-frazier');
			break;

			case 'By Erik Roskes':
			$j('a.url', parent).attr('href', '/viewpoints/erik-roskes');
			break;

			case 'By Ted Gest':
			$j('a.url', parent).attr('href', '/viewpoints/ted-gest');
			break;

			case 'By William D. Burrell':
			$j('a.url', parent).attr('href', '/viewpoints/william-burrell');
			break;		

			case 'By Mai Fernandez':
			$j('a.url', parent).attr('href', '/viewpoints/mai-fernandez');
			break;			
		};
});



$j('#printPage').click(function(){
      $j('#bodyContent').jqprint({
        	debug: false,
		importCSS: false, 
		printContainer: false,
		operaSupport: false

      });
});




//add url to send to friend page
var value = $j('span#hidden').text();
$j('textarea#share-message').val(value);

})//jQuery end




