/* Altius */
/* Author: Gene Sivorot */

var Altius = window.Altius || {};

Altius.Main = (function($) {
	
	var base = Altius.settings.baseHref || '';
	
	var sifrStyles = function(options, additionalStyles) {
		var items = [];
		options = options || {};
		
		var defaults = {
			'font-size': '24px',
			color: '#ffffff',
			'text-transform': 'uppercase'
		};
		var settings = $.extend({}, defaults, options);
		
		// create css
		var css = '.sIFR-root {';
		for (prop in settings) {
			css += prop + ':' + String(settings[prop]) + ';'
		}
		css += '}';
		
		items.push(css);
		
		if (additionalStyles && typeof additionalStyles == 'object') {
			for (prop in additionalStyles) {
				items.push(prop + ' {' + String(additionalStyles[prop])+ '}');
			}
		}
		return items;
	}
	
	var setupCycle = function() {
		var elCycle = $('#home-featured ul');
		
		if (!elCycle.length) {
			return;
		}
		
		elCycle
			.after('\
				<div id="pager"> \
					<span id="toggle"><a id="toggle-cycle" href="#">&nbsp;</a></span> \
					<ul id="pager-items" class="pagination"></ul> \
				</div> \
			')
			.cycle({
				timeout: 5000,
				pager: '#pager-items',
				pagerAnchorBuilder: function(idx, slide) { 
			        return '<li><a href="#">' + (idx + 1) + '</a></li>'; 
			    } 
			});
		
		$('#toggle-cycle').click(function() {
			var toggle = $(this);
			
			if (toggle.hasClass('paused')) {
				toggle.removeClass('paused');
				elCycle.cycle('resume', true);
			} else {
				elCycle.cycle('pause');
				toggle.addClass('paused');
			}
			
			return false;
		});
	}
	
	var setupFilters = function() {
		$('#Form_FilterForm, #CategorySearchForm')
			.find(':submit')
				.hide()
				.end()
			.find('select')
				.change(function() {
					$(this).parents('form').submit();
				});
	}
	
	return {
		init: function() {
			setupCycle();	
			setupFilters();	
		},
		
		sifr: function() {
			
			sIFR.replace(kos, {
				selector: '#box-list .title-one',
				css: sifrStyles({
					'font-size':'12px', 
					color:'#707070',
					leading:-5,
					cursor:'pointer'
				}, {
					'a':'color:#707070; text-decoration:none;',
					'a:hover':'color:#707070;'
				}),
				wmode: 'transparent',
				ratios: [8, 1.41, 9, 1.33, 10, 1.35, 15, 1.31, 19, 1.28, 20, 1.27, 26, 1.26, 29, 1.24, 30, 1.25, 35, 1.24, 39, 1.23, 40, 1.24, 50, 1.23, 54, 1.22, 55, 1.23, 81, 1.22, 84, 1.21, 86, 1.22, 89, 1.21, 90, 1.22, 94, 1.21, 95, 1.22, 1.21],
				tuneHeight:-5
			});
			
			sIFR.replace(kos, {
				selector: '#box-list .title-two',
				css: sifrStyles({
					'font-size':'16px', 
					color:'#707070',
					leading:-8
				}, {
					'a':'color:#707070; text-decoration:none;',
					'a:hover':'color:#707070;'
				}),
				wmode: 'transparent'
			});
			
			sIFR.replace(kos, {
				selector: '#postWraper .postBody h2',
				css: sifrStyles({
					'font-size':'18px', 
					color:'#ffffff',
					leading:-8
				}),
				wmode: 'transparent'
			});
			
			sIFR.replace(kos, {
				selector: '#blog-list .itemHeading .title',
				css: sifrStyles({
					'font-size':'18px', 
					color:'#ffffff',
					leading:-8,
					cursor:'pointer'
				} , {
					'a':'color:#ffffff; text-decoration:none;',
					'a:hover':'color:#ffffff;'
				}),
				wmode: 'transparent'
			});
			
			sIFR.replace(kos, {
				selector: '#home-blog .itemHeading .title',
				css: sifrStyles({
					'font-size':'18px', 
					color:'#707070',
					leading:-8,
					cursor:'pointer'
				} , {
					'a':'color:#707070; text-decoration:none;',
					'a:hover':'color:#707070;'
				}),
				wmode: 'transparent',
				tuneHeight:-10
			});
			
			sIFR.replace(kos, {
				selector: '#box-list .owner',
				css: sifrStyles({
					'font-size':'18px', 
					color:'#ffffff',
					leading:-10
				}),
				wmode: 'transparent',
				tuneHeight:-12
			});
			
			sIFR.replace(kos, {
				selector: '#sidebar-testimonial .testimonial-person',
				css: sifrStyles({
					'font-size':'18px', 
					color:'#8E908F',
					leading:-10
				}),
				wmode: 'transparent',
				tuneHeight:-10
			});
			
			sIFR.replace(kos, {
				selector: '#sidebar-testimonial .testimonial-title, #sidebar-testimonial .testimonial-company',
				css: sifrStyles({
					'font-size':'11px', 
					color:'#8E908F',
					leading:-18
				}),
				wmode: 'transparent',
				tuneHeight:-6
			});
			
			sIFR.replace(kos, {
				selector: '.line-one-small',
				css: sifrStyles({
					'font-size':'32px', 
					color:'#ffffff',
					leading:-10
				}),
				wmode: 'transparent',
				tuneHeight:-12
			});
			
			sIFR.replace(kos, {
				selector: '.line-two-small',
				css: sifrStyles({
					'font-size':'16px', 
					color:'#ffffff',
					leading:-10
				}),
				wmode: 'transparent',
				tuneHeight:-5
			});
			
			sIFR.replace(kos, {
				selector: '.content-section .htmlcontent h3',
				css: sifrStyles({
					'font-size':'20px', 
					color:'#ffffff',
					leading:-10
				}),
				wmode: 'transparent',
				tuneHeight:-10
			});
			
			
			sIFR.replace(kos, {
				selector: '.header-one-brown',
				css: sifrStyles({
					'font-size':'30px', 
					color:'#707070',
					leading:-10
				}),
				wmode: 'transparent',
				tuneHeight:-12
			});
			
			sIFR.replace(kos, {
				selector: '.header-two-brown',
				css: sifrStyles({
					'font-size':'44px', 
					color:'#707070',
					leading:-14
				}),
				wmode: 'transparent',
				tuneHeight:-17
			});
			
			sIFR.replace(kos, {
				selector: '#subheader-content h2',
				css: sifrStyles(),
				wmode: 'transparent',
				tuneHeight: -12
			});
			
			sIFR.replace(kos, {
				selector: '#home-portfolio .portfolioBody .title',
				css: sifrStyles({
					'font-size':'18px',
					color:'#8E908F',
					leading:'-6'
				} , {
					'a':'color:#8E908F; text-decoration:none;',
					'a:hover':'color:#8E908F;'
				}),
				wmode: 'transparent',
				tuneHeight: -10
			});
			
			sIFR.replace(kos, {
				selector: '#home-sub-header h3',
				css: sifrStyles({
					'font-size':'30px',
					color:'#CECFCB',
					leading:'-10'
				}),
				wmode: 'transparent',
				tuneHeight: -12
			});
			
			sIFR.replace(kos, {
				selector: '.header-one-left',
				css: sifrStyles({
					'font-size':'30px',
					leading:'-10'
				}, {
					a: 'color:#ffffff;',
					'a:hover': 'color:#ffffff;'
				}),
				wmode: 'transparent',
				tuneHeight:-12
			});
			
			sIFR.replace(kos, {
				selector: '.header-two-left',
				css: sifrStyles({
					'font-size':'44px',
					leading:'-14'
				}, {
					a: 'color:#ffffff;',
					'a:hover': 'color:#ffffff;'
				}),
				wmode: 'transparent',
				ratios: [8, 1.41, 9, 1.33, 10, 1.35, 15, 1.31, 19, 1.28, 20, 1.27, 26, 1.26, 29, 1.24, 30, 1.25, 35, 1.24, 39, 1.23, 40, 1.24, 50, 1.23, 54, 1.22, 55, 1.23, 81, 1.22, 84, 1.21, 86, 1.22, 89, 1.21, 90, 1.22, 94, 1.21, 95, 1.22, 1.21],
				tuneHeight:-17
			});
			
			sIFR.replace(kos, {
				selector: 'div.itemHeading p.category a.sifr',
				css: sifrStyles({
					'font-size':'18px'
				}),
				wmode: 'transparent'
			});
		}
	}
	
})(jQuery);

// Init Sifr Immediately
var base = Altius.settings.baseHref || '';
var kos = { src: base + 'themes/altius/fonts/kos.swf' };
sIFR.activate(kos);
Altius.Main.sifr();
// Init on Document Ready
jQuery(document).ready(Altius.Main.init);



$(document).ready(function() {
	
	// filter dropdown on portfolio page
	$("#Form_FilterForm select").change(function() {
		$("#Form_FilterForm").submit();
	});
	
	// filter dropdowns on blog page
	$("#filter li.tab-category a").click(function() {
		$("#filter").removeClass("default-date");
		$("#filter").addClass("default-category");
		return false;
	});
	$("#filter li.tab-date a").click(function() {
		$("#filter").removeClass("default-category");
		$("#filter").addClass("default-date");
		return false;
	});
	$("#CategorySearchForm select").change(function() {
		$("#CategorySearchForm").submit();
	});
	$("#ArchiveSearchForm select").change(function() {
		$("#ArchiveSearchForm").submit();
	});
	
});

