﻿jQuery.fn.extend({
    scrollTo: function(speed, easing) {
        return this.each(function() {
            var targetOffset = $(this).offset().top;
            $('html,body').animate({
                scrollTop: targetOffset
            }, speed, easing);
        });
    },
	limitTextArea: function(maxlength, message) {
		function recalculate(objT) {
			var mobjT = $(objT)
			timeoutID = window.setTimeout(function() { truncateText(mobjT) }, 100);
		}
		function truncateText(mobjT) {
			var maxlength = mobjT.attr('limit');
			var toChange = mobjT.next();
			if (mobjT.val().length > maxlength) {
				mobjT.val(mobjT.val().substring(0, maxlength));
}
			toChange.html((maxlength - mobjT.val().length) + ' ' + message);
		}
		return this.each(function() {
		    $(this).attr('limit', maxlength);
			$(this).after('<p class="remaining">' + maxlength + ' ' + message + '</span>');
			$(this).bind('keyup cut paste', function() {
				recalculate($(this));
			});
			recalculate(this);
		});
	}
    
});

function placeFooter() {
	var mainC;
	if($('#mainSwf').length > 0) {
		mainC = $('#mainSwf');
	}
	else {
		mainC = $('.wrapper');
	}
    var diff = ($(window).height() - 54) - mainC.innerHeight();
    if (diff > 0) { $('.footer').css('margin-top', diff +'px') }
    else { $('.footer').css('margin-top', '0px') }
}


$(document).ready(function() {

    $(".idContent div").hide();
    $(".idContent div:first").show()
    $(".idTabs a:first").addClass("aktif");

    $(".idTabs a").click(function () {
        var deger = $(this).attr("id");
        $(".idTabs a").removeClass("aktif");
        $(this).addClass("aktif");
        
        $(".idContent div").hide();
        $(".idContent div#tab"+deger).show();
        
    });

    
    /* accordion */
    
    $('.slideheader a:first').addClass('activeslider');
    $('.slidecontent:first').addClass('opencontent').css('display','block');
    $('.slideheader a').live('click', function() {

        if (!$(this).hasClass('activeslider')) {
            $('.opencontent').slideUp()
            $('.opencontent').removeClass('opencontent');
            $('.activeslider').removeClass('activeslider');
            $(this).addClass('activeslider');
            $('.slidecontent').eq($('.slideheader a').index(this)).slideDown().addClass('opencontent');
        }
        else {
            $(this).removeClass('activeslider');
            $('.opencontent').slideUp()
            $('.opencontent').removeClass('opencontent');
        }
        
        //setTimeout(function() {
        //    $(".activeslider").scrollTo();
        //},700)
        
        return false;
    });
    
    /* footer */
	$(window).bind('load resize', placeFooter);
    placeFooter();
    
    /* table */
    $('.tableStyle tr td:first-child').addClass("firstTd");
    $('.tableStyle tr td:last-child').addClass("lastTd");
    $('.tableStyle tr:last-child td').addClass("lastTr");
    
    /* form */
    $(".inputArea input").focus(function() {
		$(this).parents(".inputArea").addClass("inputActive");
	})
	$(".inputArea input").blur(function() {
		$(this).parents(".inputArea").removeClass("inputActive");
	})
    $(".textArea textarea").focus(function() {
		$(this).parents(".textArea").addClass("textActive");
	})
	$(".textArea textarea").blur(function() {
		$(this).parents(".textArea").removeClass("textActive");
	})
    /* modal link */
    $(".beniHaberdarEtModal").colorbox({
        iframe:true, innerWidth:550, innerHeight:240
    });
    $(".modalLink").colorbox({
        iframe:true, innerWidth:550, innerHeight:400
    });
    $(".reklamFilmiModal").colorbox({
        iframe:true, innerWidth:370, innerHeight:250
    });
    $(".modalİmage").colorbox({
        iframe:true, innerWidth:390, innerHeight:560
    });
    $(".modalİmage2").colorbox({
        iframe:true, innerWidth:690, innerHeight:470
    });    

    
});

function onlyNumber(e) {
    var keyCode = ($.browser.mozilla) ? e.which : event.keyCode;
    if ((keyCode < 48 || keyCode > 57) && keyCode != 8 && keyCode != 0) {
        return false;
    }
}

function onlyEmail(e) {
    var InvalidChars = " !#/*{[()]},;%^><\\?+:='`|şŞĞğÜüÇçİıÖö";

    kCode = InvalidChars.charAt(5);

    var keyCode = ($.browser.mozilla) ? e.which : event.keyCode;

    if (keyCode > 127) {
        return false;
    }
    for (i = 0; i <= InvalidChars.length - 1; i++) {
        if (keyCode == InvalidChars.charCodeAt(i)) {
            return false;
        }
    }
    return true;
} 

function onlyLetter(e) {
        var InvalidChars = "!#/*{[()]},;%^><\\?+:='`|&-_";

        var keyCode = ($.browser.mozilla) ? e.which : event.keyCode;

        if (keyCode > 47 && keyCode < 58) {
            return false;
        }
        for (i = 0; i <= InvalidChars.length - 1; i++) {
            if (keyCode == InvalidChars.charCodeAt(i)) {
                return false;
            }
        }
}


function mailTo(m, e, t) {
    if (!e) {
        e = 'paritem.com';
    }
    if (!t) {
        t = m + String.fromCharCode(64) + e;
    }
    document.write('<a href="mailto:' + m + String.fromCharCode(64) + e + '">' + t + '</a>');
}


