var iframe = 0;
var timer;
var interval;
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
var pageTracker;
var _kd = document;
var _kdlh = _kd.location.href;
var _ki,_kq,_kv;
var _kwtlForm;
var _kretURL;
var _kwtlOnSubmit;
var _koid;
var typeof_func = false;
var swf_id;

function load_external()
{
	$.ajaxSetup({
		cache: true
	});
	
	// Misc Functions
	$.getScript('/_script/full/functions.js?08290808');
	
	// FAQ
	if ($('.list').length > 0) {
    	$.getScript('/_script/plugins/list.js');
    }

	// Text-Preview
	if ($('.text-preview').length > 0) {
    	$.getScript('/_script/plugins/text-preview.js', function() {
			$('.text-preview').text_preview({
				more: 'Show Full Article...',
				less: 'Hide Full Article...'
			});
		});
    }
	
	// Salesforce
	$.getScript('/_script/sf.js', function(){
		interval = setInterval("if (typeof __sfga == 'function') { __sfga(); clearInterval(interval); }",500);
	});
	
	// Google Analytics
	$.getScript(gaJsHost + 'google-analytics.com/ga.js', function(){
		pageTracker = _gat._getTracker('UA-5228704-1');
		pageTracker._setDomainName('none');
		pageTracker._setAllowLinker(true);
		pageTracker._trackPageview();
		pageTracker._setVar('Variation: ' + 'original');
	});
}

$(document).ready(function()
{
	// Tabs
	$('.tab').parent().hover(function(){
        $(this).children('div').fadeTo('fast', 0.8);
    }, function(){
        $(this).children('div').fadeTo('fast', 0.5);
    });
    
    var tabs = $('.tabs');
    
    tab_length = tabs.length;
    
    for (i = 0; i < tab_length; i++) {
    
        var tab_child = $(tabs[i]).children('ul').children().not('.clear');
        var tab_div = $(tabs[i]).children('.tabbed').children('div');
        
        $(tab_child[0]).addClass('sel');
        $(tab_div[0]).siblings().hide();
        $(tab_div[0]).siblings().andSelf().css({
            background: '#F6F6F6'
        });
        
        tab_child_length = tab_child.length;
        for (n = 0; n < tab_child_length; n++) {
        
            var rand = "Tab_" + i + "-" + n;
            
            $(tab_child[n]).attr('name', rand);
            
            $(tab_child[n]).click(function(){
                $(this).siblings('.sel').removeClass('sel');
                $(this).addClass('sel');
                
                var this_tab = $('#' + $(this).attr('name'));
                
                $('#' + $(this).attr('name')).siblings(':visible').hide();
				$(this_tab).show();

				return false;
                
            });
            
            $(tab_div[n]).attr('id', rand);
        }
        
    }
	
	// Hide specific elements
    $('.js_hide').hide();
	$('.js_unhide').show();
     
  	// Add Corners in IE
	if ($.browser.msie) {
		$('.heading:not(.nocorner),.top').corner({
	        tl: {radius: 5},
	        tr: {radius: 5},
	        bl: {radius: 0},
	        br: {radius: 0}
	    });

	    $('.content:not(.both,.top,.nocorner)').corner({
	        tl: {radius: 0},
	        tr: {radius: 0},
	        bl: {radius: 5},
	        br: {radius: 5}
	    });

	    $('.both').corner({
	        tl: {radius: 5},
	        tr: {radius: 5},
	        bl: {radius: 5},
	        br: {radius: 5}
	    });
	}
    
    // Clear Input boxes on click
    $('input:not(.datepick):not(.initval):not(:radio):not(:checkbox)')
		.one('focus', function(){
	        $(this).val('');
	    });

	
	// Change consultation URL
    if ($('#consult').length > 0) {
        $('#consult').attr('target', 'consult-iframe');
        $('#consult-retURL').val('http://www.slimband.ca/_ajax/consultation.php');
    }
	
	// Change Questionnaire Iframe
	$('#questionnaire').attr('target','questionnaire_iframe');

	// Lazy Load External Scripts
	load_external();
	
	// Fancy Box
	$('a[rel*=fancybox]').fancybox({
		callbackOnClose: function()
		{
			$('#fancy_div').html('');
		}
	});
});

function consultIframe() {}
function qIframe() {}
function fIframe() {}
