/**
 * @author LPHMedia
 */

	//main menu script
	//global menu vars
	var _timeout = 750;
	var _subnav = '';
	var _current ='';
	var _galheight;
	var _galwidth;
	
	function removeTemp(el){
		
		//ie6 fix?
		if(jQuery.browser.msie){
			$('#'+el).stop().animate({backgroundPosition: '(0px 0px)'}, 1 );
			$('#submenu_'+el).stop().fadeOut('fast');
		}else{
			$('#'+el).stop().animate({backgroundPosition: '(0px 0px)'}, 1 );
			$('#submenu_'+el).stop().fadeOut('fast');
		}
		
		_current = '';
	}
	
	
	
	$(document).ready(function(){
		
		
		
			 
		if ($('.photos_portrait')[0]) {

			var tmp = $('.photos_portrait').attr('id'); 
			
			var settings = tmp.split('_');
			
			_galheight = 400;
			_galwidth = 420;
			
			/*
			if(settings[0]!="" && settings[1]!=""){
			
				_galheight = settings[0];
				_galwidth = settings[1];
			
			}
			*/
			
			$('.photos_portrait').css("visibility","hidden");
			
 
			 $('.photos_portrait').galleryView({
				panel_width:  _galwidth,
				panel_height:  _galheight,
				frame_width: 80,
				frame_height : 84,
				pause_on_hover: true,
				nav_theme: 'light',
				pointer_size: 0
			});
			
			$('.gallery').css("margin-left","auto");
			$('.gallery').css("margin-right","auto");
		}
		
		if ($('.photos_landscape')[0]) {
			 
			 _galheight = 400;
			 _galwidth = 600;
			
			
			/*
			if(settings[0]!="" && settings[1]!=""){
			
				_galheight = settings[0];
				_galwidth = settings[1];
			
			}
			*/
			 
			 $('.photos_landscape').css("visibility","hidden");
			 
			 $('.photos_landscape').galleryView({
				panel_width: _galwidth,
				panel_height: _galheight,
				frame_width: 60,
				frame_height : 40,
				pause_on_hover: true,
				nav_theme: 'light',
				pointer_size: 0
			});
			
			$('.gallery').css("margin-left","auto");
			$('.gallery').css("margin-right","auto");
		}
		
		$("a.enlarge").fancybox();
		
		$('table.fancylayout:not(.nolayout), .tabcontent table:not(.nolayout)').each(function(){
			
			var url = 'http://'+window.location.hostname+'/themes/gcd/images/';
			var img = $('.menuheading').text().toLowerCase().replace(" ", "");
			
			/*var switchImg = img;
				switch(switchImg) {
				case 'journalism':
					img = "media";
				break;
				case 'accountancy':
					img = "accountancy";
				break;
				case 'business':
					img = "business";
				break;
				case 'law':
					img = "law";
				break;
				case 'computing':
					img = "computing";
				break;
				case 'media':
					img = "media";
				break;
				case 'design':
					img = "design";
				break;
				case 'music':
					img = "music";
				break;
				case 'shortcourses':
					img = "shortcourses";
				break;
				default: 
					img = "default";
				}*/
			//img = "default";
			
			//alert(img);
			
			if(img==""){
				img = "default";
			}
			
			if(img.indexOf("news")>-1 || img.indexOf("contactus")>-1 || img.indexOf("international")>-1 || (img.indexOf("courses")>-1 && img!= "shortcourses") || img.indexOf("currentstudents")>-1 || img.indexOf("accomodation")>-1 || img.indexOf("conferencecentre")>-1 || img.indexOf("limerickcampus")>-1 || img.indexOf("corkcampus")>-1 || img.indexOf("accommodation")>-1 ){
				img = "default";
			}
			
			if(img.indexOf("futurestudents")>-1){
				img = "default";
			}
			
			if(img.indexOf('journalism')>-1){
				img = "media";
			}
			
			if(img.indexOf("music")>-1){
				img = "music";
			}
			/* Biliana 02.02.2011 - fancylayout table styles */
			
			$(this).css({
				'background':'url('+url+img+'_bg.png) no-repeat',
				'border':'0',
				'margin-top':'0px'
			});
			
			
			
			/*
			$(this).find('tr').find('td').not(':last').css(
				{
					"border-right": "1px solid #cccccc",
					"border-bottom": "1px solid #cccccc",
					"padding": "5px"
				}
			);
			*/
			$(this).find('tr').not(':first').find('td').css(
				"background","#fff"
			);
			
			$(this).find('tr').not(':even').find('td').css(
				"background","#eff0ef"
				
			);
			/*
			$(this).find('tr').find('td:last').css(
				{
					"border-right": "0px solid #cccccc",
					"border-bottom": "1px solid #cccccc",
					"padding": "5px"
				}
			);
			
			$(this).find('tr:first').find('td:first').css(
				{
					"background": "url("+url+"top_left_corner.png) top left no-repeat",
					"padding": "5px",
					"border-right": "1px solid #cccccc",
					"border-bottom": "1px solid #cccccc"
				}
			);
			
			
			if($(this).find('tr:first').find('td').size()>1){
				$(this).find('tr:first').find('td:last').css(
				{
					"background": "url("+url+"top_right_corner.png) top right no-repeat",
					"padding": "5px",
					"border-bottom": "1px solid #cccccc"
				}
				);
				
			}else{
			
				$(this).find('tr:first').find('td').css("border-right","0");
				$(this).css("-moz-border-radius-topright","8px");
				$(this).css("-webkit-border-top-right-radius","8px");
				$(this).css("border-top-right-radius","8px");
				
			}
			*/
			
			$(this).find('tr:first').find('td').css(
				"color","#ffffff"
			);
			$(this).find('tr:first').find('td').css(
				"font-weight","bold"
			);
			$(this).find('tr:first').find('td').css(
				"text-transform","uppercase"
			);
			$(this).find('tr:first').find('td').find('a').css(
				"text-decoration","none"
			);
			$(this).find('tr:first').find('td').find('a').css(
				"color","#ffffff"
			);
			
			
			//add last  row to table
			// - max cells
			/*var _i = 0;
			$(this).find('tr').each(function(){
				len = $(this).find('td').size();
				if(len>_i)
				{
					_i=len;
				}
			});
			
			lastrow = '<tr><td style="background: url('+url+'bottom_left_corner.png) bottom left no-repeat; line-height: 5px;">&nbsp;</td>';
			for(i=0;i<_i-2;i++){
				lastrow += '<td></td>';
			}
			lastrow += '<td style="background: url('+url+'bottom_right_corner.png) bottom right no-repeat; line-height: 5px;">&nbsp;</td></tr>';
			
			$(this).last().append(lastrow);
			*/
		});
		
		if($('.leftmenu_header').length > 0){
		
		var opacity = 9;
		var tmp = $('.leftmenu_header').attr('id');
		
		$('.leftmenu_header').css({"border-bottom":"1px solid #ffffff"});
		
		var bgcolor = "#DE1934";
		if(tmp.indexOf('media')>-1){var bgcolor = "#2AAA4D";}		
		if(tmp.indexOf('design')>-1){var bgcolor = "#9B0461";}		
		if(tmp.indexOf('law')>-1){var bgcolor = "#8F53A4";}		
		if(tmp.indexOf('business')>-1){var bgcolor = "#086CA8";}		
		if(tmp.indexOf('accountancy')>-1){var bgcolor = "#083DA4";}		
		if(tmp.indexOf('computing')>-1){var bgcolor = "#F1602B";}		
		if(tmp.indexOf('music')>-1){var bgcolor = "#CDA11C";}		
		if(tmp.indexOf('short')>-1){var bgcolor = "#821C32";}		
	

		$('#menucolumn').find('.leftmenuitem').each(function(i){
			if($(this).parent().find('.leftmenuitem2nd').length>0){
				
				if($(this).parent().attr('data')=='current'){
					$(this).parent().find('.leftmenuitem2nd').each(function (i){
						$(this).css({"display":"block"});						
					});
				}
				/*
				$(this).css({
					"border-bottom": "1px solid #ffffff",
					"color": "#ffffff",
					"font-weight": "bold",
					"background": bgcolor,
					"filter":"alpha(opacity="+opacity+"0)",
					"-moz-opacity":"0."+opacity,
					"-khtml-opacity":"0."+opacity,
					"opacity": "0."+opacity,
					"-ms-filter":"progid:DXImageTransform.Microsoft.Alpha(Opacity="+opacity+"0)"
				});
				*/
				
				$(this).css({
					"border-bottom": "1px solid #ffffff",
					"color": "#ffffff",
					"font-weight": "bold",
					"background": bgcolor
				});
				
				if ($(this).parent().find('.leftmenuitem2nd').length > 0) {
					$(this).css({
						"background": "url('/themes/gcd/images/menuindicator.gif') no-repeat bottom right " + bgcolor						
					});
				}
				
				$(this).parent().find('.leftmenuitem2nd').each(function (i){
					$(this).hover(
						function(){
							$(this).css({"border-left": "4px solid "+ bgcolor});
						},
						function(){
							$(this).css({"border-left": "0px"});
						}
					)
					
				});
				
				if($(this).parent().attr('data')=='section'){
					$(this).parent().find('.leftmenuitem2nd').each(function (i){
						$(this).css({"display":"block"});
						
						if($(this).attr('data')=='current'){
							$(this).css({"border-left": "4px solid "+ bgcolor, "background": "#EFEFEF","margin-left": "0px","padding-left": "6px"});
							$(this).hover(
								function(){
									$(this).css({"border-left": "4px solid "+ bgcolor});
								},
								function(){
									$(this).css({"border-left": "4px solid "+ bgcolor});
								}
							)
						}
										
					});
				}
				
				opacity = opacity - 1;
			}
		});
		
		}
		
		$('.leftmenuitem').mouseover(function(){
			
			/*
			
			$('.leftmenuitem2nd').each(function(i){
				if($(this).hasClass('active')){
					$(this).hide();
				}
			});
			
			*/
			//if($(this).parent().find(':first-child').is(':hidden')==false){
			$(this).parent().find('.leftmenuitem2nd').slideDown();
			//}
					
		});
		
		
		
		$(".button").hover(function(){
                
				$("#"+$(this).attr('id')+" img")
                .animate({top:"-10px"}, 200).animate({top:"-4px"}, 200) // first jump
                .animate({top:"-7px"}, 100).animate({top:"-4px"}, 100) // second jump
                .animate({top:"-6px"}, 100).animate({top:"-4px"}, 100); // the last jump
        });
		
		
		$('.frontnewsheadline:first').css({'padding-top' : '0'});
		
		//ff fix
		$('#home').css({backgroundPosition: '0px 0px'});

		$(".menuitem").hover(function(){
		      
			  el = $(this).attr('id');			  
			 if(_current != el){ $('.submenus').stop(true,true).hide();}
			 clearTimeout(_subnav);
			  
			 $(".menuitem").stop().animate({backgroundPosition: '(0px 0px)'}, 1 );
			 $(this).stop().animate({backgroundPosition: '(0px -26px)'}, 200 );
			  
			  if (_current != el) {
			   	//set height
				$('#submenu_' + el).slideDown();				
			  }
			  
			  //for dynmic sized dropdowns - unused
			  //setheight('#submenu_' + el);
			  _current = el;
			  
		    },
			function() {
			
			  _subnav =  window.setTimeout(function(){
				removeTemp(el);
			  },_timeout);
			  
			  
			  
		});
		
		$('.submenus').hover(
			function(){
				
				clearTimeout(_subnav);
				
				$(this).show();
				el = $(this).attr('id').split('_');
				$('#'+el[1]+'_menuitem').stop().animate({backgroundPosition: '(0px -26px)'}, 1 );
			},
			function(){
				
				_subnav =  window.setTimeout(function(){
				removeTemp(el[1]);
			  	},_timeout);
				
			}
		);
		
	});
	

