/**
 * Initialize
 */ 
$(document).ready(function(){
    PCG.init();
    
/******************************************************/
});

/**
 * PCG NameSpace
 */
 
var pcgurl;
 
var PCG = window.PCG || 
{
    init: function() 
    {        
	this.aesthetics_init();
        this.cycle_init();
        this.menu_init();
	this.modals_init();
    },
	aesthetics_init: function (id) {
		 if ($('.breadcrumbs').length) { $('.breadcrumbs').corner('bottom 4px');};
	},
    cycle_init: function (id) {
		function pagerFactory(idx, slide) {
			var s = idx == 6  ? '<br />' : '';
			return '<span class="navbanner"><a href="#">'+$(".img" + idx).attr("title")+ s +'</a></span>';
		}
		$('#msgbanner').cycle({
				fx:'turnDown',
				speed:900,
                                startingSlide: 2,
				timeout:12000,
				random:0,
				pager:'#productlist',
				pagerAnchorBuilder:pagerFactory}
		);  
	},
	
	menu_init: function()
	{
		$("#menucontent ul").removeClass("nj");
		$("#menucontent ul li").hover(
			function () {
				$(this).addClass("hovering");
				$(this).find(".dropdown_menu").show();
			},
			function () {
				$(this).find(".dropdown_menu").hide();
				$(this).removeClass("hovering");
			}
		);
		$(".rel").hover(
		    function () {
				$('#menucontent ul li a.main').addClass("hovering");
			},
			function () {
				$('#menucontent ul li a.main').removeClass("hovering");
			}
		);
	},
	modals_init: function()
	{
		$('.contactformlink').click(function(e) 
		{
			e.preventDefault();
			var maskHeight = $(document).height();
			var maskWidth = $(window).width();
			$('.mask').css({'width':maskWidth,'height':maskHeight});
			$('.mask').css('filter', 'alpha(opacity=60)'); 
			$('.mask').fadeIn(300); 
			var winH = $(window).height();
			var winW = $(window).width();
			$('.contactform').css('top',  (winH/2-$('.contactform').height()/2) + $('html').scrollTop());
			$('.contactform').css('left', (winW/2-$('.contactform').width()/2));
			$('.contactform').fadeIn(300); 
	
		});

                $('.randyinterviewlink').click(function(e)
		{
			e.preventDefault();
			var maskHeight = $(document).height();
			var maskWidth = $(window).width();
			$('.mask').css({'width':maskWidth,'height':maskHeight});
			$('.mask').css('filter', 'alpha(opacity=60)');
			$('.mask').fadeIn(300);
			var winH = $(window).height();
			var winW = $(window).width();
			$('.randyinterview').css('top',  (winH/2-$('.randyinterview').height()/2) + $('html').scrollTop());
			$('.randyinterview').css('left', (winW/2-$('.randyinterview').width()/2));
			$('.randyinterview').fadeIn(300);

		});

                $('.nyseclosinglink').click(function(e)
		{
			e.preventDefault();
			var maskHeight = $(document).height();
			var maskWidth = $(window).width();
			$('.mask').css({'width':maskWidth,'height':maskHeight});
			$('.mask').css('filter', 'alpha(opacity=60)');
			$('.mask').fadeIn(300);
			var winH = $(window).height();
			var winW = $(window).width();
			$('.nyseclosing').css('top',  (winH/2-$('.nyseclosing').height()/2) + $('html').scrollTop());
			$('.nyseclosing').css('left', (winW/2-$('.nyseclosing').width()/2));
			$('.nyseclosing').fadeIn(300);

		});

		
		$('.contactform .close').click(function (e) 
		{
			if( jQuery.browser.msie ) 
			{
				window.location.reload();
			}
			else
			{
				e.preventDefault();
			}
			
			$('.mask').hide();
			$('.contactform').hide();
		});	

                $('.randyinterview .close').click(function (e)
		{
			if( jQuery.browser.msie )
			{
				window.location.reload();
			}
			else
			{
				e.preventDefault();
			}

			$('.mask').hide();
			$('.randyinterview').hide();
		});

                 $('.nyseclosing .close').click(function (e)
		{
			if( jQuery.browser.msie )
			{
				window.location.reload();
			}
			else
			{
				e.preventDefault();
			}

			$('.mask').hide();
			$('.nyseclosing').hide();
		});
		
		if ($('.nyseclosingvideo').length) {
			if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPad/i))) {
   				$('.nyseclosingvideo').html("<video controls width=\"500\" height=\"280\" ><source src=\"/wp-content/themes/pcgweb3/videos/pcg_nyse_closing.mp4\" poster=\"/wp-content/themes/pcgweb3/videos/start_frame.jpg\" type=\"video/mp4\"></video>");
			}
		}

		$(window).bind("resize", resizeWindow);
		
		function resizeWindow(e) 
		{
			var newWindowHeight = $(window).height();
			var newWindowWidth = $(window).width();
			$('.mask').css({'width':newWindowWidth,'height':newWindowHeight + $('html').scrollTop()});
			$('.window').css({'top':newWindowHeight/2-$('.window').height()/2 + $('html').scrollTop(),'left':(newWindowWidth/2-$('.window').width()/2)});
		};
	}
};
