/*
	-- Common javascript functions --
	
	-- Author: 		e950
	-- URL:			http://www.e950.lv/
	-- Modified: 	04.11.2008
*/

$(document).ready(function() {
	
	var base_url = $("#base_url").text();
	
	if(! $.browser.opera) {	
		$('h1').sifr({
			path: base_url+'js2/frontend/sifr/',
			font: 'myriad',
			textAlign: 'left',
			height:33,
			offsetTop:3
		});
		
		$('.dissep h4').sifr({
			path: base_url+'js2/frontend/sifr/',
			font: 'myriad',
			textAlign: 'left',
			height:33,
			offsetTop:7
		});
	}
	
	$("#client_username").focus();
	
	$(".product #market_holder a").hover(function(){
		
		$(".product li[id^=p]").hide();
		
		var children = $(".product_holder .product li:has(a[id="+$(this).attr('id')+"]) span").text();
		children = children.split(';');
		
		for(var i = 0; i < (children.length - 1); i++) {
			$(".product #p"+children[i]).show();
		}
		
	}, function() {
		//nothing
	});
	
	$("#update_category").submit(function() {
		if(!$("#category_title").val()) {
			$("label[for=category_title]").css({color: '#830025', fontWeight: 'bold'});
			return false;
		}
	});
	
	$("#update_category #category_title").focus();
	
	$("#check_all").click(function(){
		if($("#check_all:checked").attr('id')) {
			$("form:has(#check_all) input[type=checkbox]:not(#checkbox)").attr('checked', 'checked');
		} else {
			$("form:has(#check_all) input[type=checkbox]:not(#checkbox)").attr('checked', '');
		}
		
	});
	
	$("#add_file_form").submit(function(){
		$("label[for=file_title], label[for=file_file]").css({color: '#5F6863', fontWeight: 'normal'});
		
		if(!$("#file_title").val()) {
			$("label[for=file_title]").css({color: '#830025', fontWeight: 'bold'});
			return false;
		}
		if(!$("#file_file").val()) {
			$("label[for=file_file]").css({color: '#830025', fontWeight: 'bold'});
			return false;
		} else {
			if($("#existing_files li:contains("+$("#file_file").val()+")").text() != "") {
				$("#file_ex_error").text('File with this filename ('+$("#file_file").val()+') already exists!').slideDown('fast');
				return false;
			}
		}
	});
	
	$("#update_user, #edit_account_form").submit(function(){
		var check = new Array('client_name', 'client_company', 'client_email', 'client_password');
		var i;
		var error = false;
		
		for(i = 0; i < check.length; i++) {
			if(! $("#"+check[i]).val()) {
				$("label[for="+check[i]+"]").css({color: '#830025', fontWeight: 'bold'});
				error = true;
			} else {
				$("label[for="+check[i]+"]").css({color: '#5F6863', fontWeight: 'normal'});
			}
		}
		
		if(error == true) {
			return false;
		}
	});
	
	$(".slideshow").cycle({speed:  500});

});